001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.core.lucene;
018:
019: import org.apache.lucene.document.Field;
020: import org.compass.core.converter.ResourcePropertyConverter;
021: import org.compass.core.engine.RepeatableReader;
022: import org.compass.core.mapping.ResourcePropertyMapping;
023: import org.compass.core.spi.InternalProperty;
024:
025: /**
026: * @author kimchy
027: */
028: public class LuceneProperty implements InternalProperty {
029:
030: private static final long serialVersionUID = 3690475809949104182L;
031:
032: private Field field;
033:
034: private RepeatableReader reader;
035:
036: private transient ResourcePropertyMapping propertyMapping;
037:
038: public LuceneProperty(Field field) {
039: this .field = field;
040: }
041:
042: public LuceneProperty(Field field, RepeatableReader reader) {
043: this .field = field;
044: this .reader = reader;
045: }
046:
047: public void setPropertyMapping(
048: ResourcePropertyMapping propertyMapping) {
049: this .propertyMapping = propertyMapping;
050: }
051:
052: public ResourcePropertyMapping getPropertyMapping() {
053: return propertyMapping;
054: }
055:
056: public RepeatableReader getRepeatableReader() {
057: return this .reader;
058: }
059:
060: public Field getField() {
061: return this .field;
062: }
063:
064: public String getName() {
065: return field.name();
066: }
067:
068: public Object getObjectValue() {
069: String value = getStringValue();
070: if (propertyMapping == null) {
071: return value;
072: }
073: ResourcePropertyConverter converter = (ResourcePropertyConverter) propertyMapping
074: .getConverter();
075: if (converter == null) {
076: return null;
077: }
078: return converter.fromString(value, propertyMapping);
079: }
080:
081: public String getStringValue() {
082: return field.stringValue();
083: }
084:
085: public byte[] getBinaryValue() {
086: return field.binaryValue();
087: }
088:
089: public float getBoost() {
090: return field.getBoost();
091: }
092:
093: public void setBoost(float boost) {
094: field.setBoost(boost);
095: }
096:
097: public boolean isIndexed() {
098: return field.isIndexed();
099: }
100:
101: public boolean isStored() {
102: return field.isStored();
103: }
104:
105: public boolean isCompressed() {
106: return field.isCompressed();
107: }
108:
109: public boolean isBinary() {
110: return field.isBinary();
111: }
112:
113: public boolean isTokenized() {
114: return field.isTokenized();
115: }
116:
117: public boolean isTermVectorStored() {
118: return field.isTermVectorStored();
119: }
120:
121: /**
122: * Not exported to the users since it is always false when loading the Field
123: * from Lucene.
124: */
125: public boolean isStoreOffsetWithTermVector() {
126: return field.isStoreOffsetWithTermVector();
127: }
128:
129: /**
130: * Not exported to the users since it is always false when loading the Field
131: * from Lucene.
132: */
133: public boolean isStorePositionWithTermVector() {
134: return field.isStorePositionWithTermVector();
135: }
136:
137: public boolean isOmitNorms() {
138: return field.getOmitNorms();
139: }
140:
141: public void setOmitNorms(boolean omitNorms) {
142: field.setOmitNorms(omitNorms);
143: }
144:
145: public String toString() {
146: return "[" + field + "]";
147: }
148: }
|