Index: lucene/src/java/org/apache/lucene/document2/DateTools.java =================================================================== --- lucene/src/java/org/apache/lucene/document2/DateTools.java (revision 0) +++ lucene/src/java/org/apache/lucene/document2/DateTools.java (revision 0) @@ -0,0 +1,210 @@ +package org.apache.lucene.document2; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.lucene.search.NumericRangeQuery; // for javadocs +import org.apache.lucene.util.NumericUtils; // for javadocs + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +/** + * Provides support for converting dates to strings and vice-versa. + * The strings are structured so that lexicographic sorting orders + * them by date, which makes them suitable for use as field values + * and search terms. + * + *
This class also helps you to limit the resolution of your dates. Do not + * save dates with a finer resolution than you really need, as then + * RangeQuery and PrefixQuery will require more memory and become slower. + * + *
+ * Another approach is {@link NumericUtils}, which provides
+ * a sortable binary representation (prefix encoded) of numeric values, which
+ * date/time are.
+ * For indexing a {@link Date} or {@link Calendar}, just get the unix timestamp as
+ *
* Expert: change the value of this field. This can be used during indexing to
Index: lucene/src/java/org/apache/lucene/document2/NumericField.java
===================================================================
--- lucene/src/java/org/apache/lucene/document2/NumericField.java (revision 1145347)
+++ lucene/src/java/org/apache/lucene/document2/NumericField.java (working copy)
@@ -21,6 +21,7 @@
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.NumericTokenStream;
+import org.apache.lucene.document.NumericField.DataType;
import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.search.NumericRangeQuery; // javadocs
import org.apache.lucene.search.NumericRangeFilter; // javadocs
@@ -162,7 +163,7 @@
TYPE_STORED.freeze();
}
- public static enum DataType { INT, LONG, FLOAT, DOUBLE }
+ //public static enum DataType { INT, LONG, FLOAT, DOUBLE }
private DataType dataType;
private transient NumericTokenStream numericTS;
@@ -288,6 +289,7 @@
* instances. You can then use {@link #getNumericValue} to return the stored
* value.
*/
+ @Override
public String stringValue() {
return (fieldsData == null) ? null : fieldsData.toString();
}
@@ -296,7 +298,8 @@
* Returns the current numeric value as a subclass of {@link Number},
* long using {@link Date#getTime} or {@link Calendar#getTimeInMillis} and
+ * index this as a numeric value with {@link NumericField}
+ * and use {@link NumericRangeQuery} to query it.
+ */
+public class DateTools {
+
+ final static TimeZone GMT = TimeZone.getTimeZone("GMT");
+
+ private static final ThreadLocalyyyyMMddHHmmssSSS or shorter,
+ * depending on resolution; using GMT as timezone
+ */
+ public static String dateToString(Date date, Resolution resolution) {
+ return timeToString(date.getTime(), resolution);
+ }
+
+ /**
+ * Converts a millisecond time to a string suitable for indexing.
+ *
+ * @param time the date expressed as milliseconds since January 1, 1970, 00:00:00 GMT
+ * @param resolution the desired resolution, see
+ * {@link #round(long, DateTools.Resolution)}
+ * @return a string in format yyyyMMddHHmmssSSS or shorter,
+ * depending on resolution; using GMT as timezone
+ */
+ public static String timeToString(long time, Resolution resolution) {
+ final Date date = new Date(round(time, resolution));
+ return TL_FORMATS.get()[resolution.formatLen].format(date);
+ }
+
+ /**
+ * Converts a string produced by timeToString or
+ * dateToString back to a time, represented as the
+ * number of milliseconds since January 1, 1970, 00:00:00 GMT.
+ *
+ * @param dateString the date string to be converted
+ * @return the number of milliseconds since January 1, 1970, 00:00:00 GMT
+ * @throws ParseException if dateString is not in the
+ * expected format
+ */
+ public static long stringToTime(String dateString) throws ParseException {
+ return stringToDate(dateString).getTime();
+ }
+
+ /**
+ * Converts a string produced by timeToString or
+ * dateToString back to a time, represented as a
+ * Date object.
+ *
+ * @param dateString the date string to be converted
+ * @return the parsed time as a Date object
+ * @throws ParseException if dateString is not in the
+ * expected format
+ */
+ public static Date stringToDate(String dateString) throws ParseException {
+ try {
+ return TL_FORMATS.get()[dateString.length()].parse(dateString);
+ } catch (Exception e) {
+ throw new ParseException("Input is not a valid date string: " + dateString, 0);
+ }
+ }
+
+ /**
+ * Limit a date's resolution. For example, the date 2004-09-21 13:50:11
+ * will be changed to 2004-09-01 00:00:00 when using
+ * Resolution.MONTH.
+ *
+ * @param resolution The desired resolution of the date to be returned
+ * @return the date with all values more precise than resolution
+ * set to 0 or 1
+ */
+ public static Date round(Date date, Resolution resolution) {
+ return new Date(round(date.getTime(), resolution));
+ }
+
+ /**
+ * Limit a date's resolution. For example, the date 1095767411000
+ * (which represents 2004-09-21 13:50:11) will be changed to
+ * 1093989600000 (2004-09-01 00:00:00) when using
+ * Resolution.MONTH.
+ *
+ * @param resolution The desired resolution of the date to be returned
+ * @return the date with all values more precise than resolution
+ * set to 0 or 1, expressed as milliseconds since January 1, 1970, 00:00:00 GMT
+ */
+ @SuppressWarnings("fallthrough")
+ public static long round(long time, Resolution resolution) {
+ final Calendar calInstance = TL_CAL.get();
+ calInstance.setTimeInMillis(time);
+
+ switch (resolution) {
+ //NOTE: switch statement fall-through is deliberate
+ case YEAR:
+ calInstance.set(Calendar.MONTH, 0);
+ case MONTH:
+ calInstance.set(Calendar.DAY_OF_MONTH, 1);
+ case DAY:
+ calInstance.set(Calendar.HOUR_OF_DAY, 0);
+ case HOUR:
+ calInstance.set(Calendar.MINUTE, 0);
+ case MINUTE:
+ calInstance.set(Calendar.SECOND, 0);
+ case SECOND:
+ calInstance.set(Calendar.MILLISECOND, 0);
+ case MILLISECOND:
+ // don't cut off anything
+ break;
+ default:
+ throw new IllegalArgumentException("unknown resolution " + resolution);
+ }
+ return calInstance.getTimeInMillis();
+ }
+
+ /** Specifies the time granularity. */
+ public static enum Resolution {
+
+ YEAR(4), MONTH(6), DAY(8), HOUR(10), MINUTE(12), SECOND(14), MILLISECOND(17);
+
+ final int formatLen;
+ final SimpleDateFormat format;//should be cloned before use, since it's not threadsafe
+
+ Resolution(int formatLen) {
+ this.formatLen = formatLen;
+ // formatLen 10's place: 11111111
+ // formatLen 1's place: 12345678901234567
+ this.format = new SimpleDateFormat("yyyyMMddHHmmssSSS".substring(0,formatLen),Locale.US);
+ this.format.setTimeZone(GMT);
+ }
+
+ /** this method returns the name of the resolution
+ * in lowercase (for backwards compatibility) */
+ @Override
+ public String toString() {
+ return super.toString().toLowerCase(Locale.ENGLISH);
+ }
+
+ }
+
+}
Index: lucene/src/java/org/apache/lucene/document2/Document.java
===================================================================
--- lucene/src/java/org/apache/lucene/document2/Document.java (revision 1145347)
+++ lucene/src/java/org/apache/lucene/document2/Document.java (working copy)
@@ -158,7 +158,31 @@
}
return null;
}
+
+ public final IndexableField getField(String name) {
+ for (IndexableField field : fields) {
+ if (field.name().equals(name))
+ return field;
+ }
+ return null;
+ }
+
+ private final static IndexableField[] NO_FIELDS = new IndexableField[0];
+ public IndexableField[] getFields(String name) {
+ Listnull if not yet initialized.
*/
- public Number getNumericValue() {
+ @Override
+ public Number numericValue() {
return (Number) fieldsData;
}
@@ -310,10 +313,21 @@
*
* @since 3.2
*/
- public DataType getNumericDataType() {
+ @Override
+ public DataType numericDataType() {
return dataType;
}
-
+
+ public DataType numericType() {
+ return dataType;
+ }
+
+ @Override
+ public boolean numeric() {
+ return true;
+ }
+
+ @Override
public boolean isNumeric() {
return true;
}
Index: lucene/src/java/org/apache/lucene/document2/StringField.java
===================================================================
--- lucene/src/java/org/apache/lucene/document2/StringField.java (revision 1145347)
+++ lucene/src/java/org/apache/lucene/document2/StringField.java (working copy)
@@ -42,6 +42,7 @@
this(name, true, value);
}
+ @Override
public String stringValue() {
return (fieldsData == null) ? null : fieldsData.toString();
}
Index: solr/src/java/org/apache/solr/schema/BCDIntField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/BCDIntField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/BCDIntField.java (working copy)
@@ -21,6 +21,7 @@
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.ValueSource;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexableField;
import org.apache.solr.util.BCDUtils;
import org.apache.solr.response.TextResponseWriter;
@@ -51,12 +52,21 @@
}
@Override
+ public String toExternal(IndexableField f) {
+ return indexedToReadable(f.stringValue());
+ }
+
+ @Override
public String toExternal(Fieldable f) {
return indexedToReadable(f.stringValue());
}
// Note, this can't return type 'Integer' because BCDStrField and BCDLong extend it
@Override
+ public Object toObject(IndexableField f) {
+ return Integer.valueOf( toExternal(f) );
+ }
+ @Override
public Object toObject(Fieldable f) {
return Integer.valueOf( toExternal(f) );
}
Index: solr/src/java/org/apache/solr/schema/BCDLongField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/BCDLongField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/BCDLongField.java (working copy)
@@ -18,11 +18,16 @@
package org.apache.solr.schema;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexableField;
/**
*
*/
public class BCDLongField extends BCDIntField {
@Override
+ public Long toObject(IndexableField f) {
+ return Long.valueOf( toExternal(f) );
+ }
+ @Override
public Long toObject(Fieldable f) {
return Long.valueOf( toExternal(f) );
}
Index: solr/src/java/org/apache/solr/schema/BCDStrField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/BCDStrField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/BCDStrField.java (working copy)
@@ -18,6 +18,7 @@
package org.apache.solr.schema;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexableField;
/**
*
*/
@@ -27,6 +28,10 @@
* is not an integer, it will not survive the base10k conversion!
*/
@Override
+ public String toObject(IndexableField f) {
+ return toExternal(f);
+ }
+ @Override
public String toObject(Fieldable f) {
return toExternal(f);
}
Index: solr/src/java/org/apache/solr/schema/BinaryField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/BinaryField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/BinaryField.java (working copy)
@@ -20,8 +20,9 @@
import java.io.IOException;
import java.nio.ByteBuffer;
-import org.apache.lucene.document.Field;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.document2.Field;
+import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.SortField;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.common.util.Base64;
@@ -46,9 +47,19 @@
@Override
+ public String toExternal(IndexableField f) {
+ return toBase64String(toObject(f));
+ }
+ @Override
public String toExternal(Fieldable f) {
return toBase64String(toObject(f));
}
+
+ @Override
+ public ByteBuffer toObject(IndexableField f) {
+ BytesRef bytes = f.binaryValue(null);
+ return ByteBuffer.wrap(bytes.bytes, bytes.offset, bytes.length);
+ }
@Override
public ByteBuffer toObject(Fieldable f) {
@@ -57,7 +68,7 @@
}
@Override
- public Fieldable createField(SchemaField field, Object val, float boost) {
+ public IndexableField createField(SchemaField field, Object val, float boost) {
if (val == null) return null;
if (!field.stored()) {
log.trace("Ignoring unstored binary field: " + field);
@@ -81,7 +92,7 @@
len = buf.length;
}
- Field f = new Field(field.getName(), buf, offset, len);
+ Field f = new org.apache.lucene.document2.BinaryField(field.getName(), buf, offset, len);
f.setBoost(boost);
return f;
}
Index: solr/src/java/org/apache/solr/schema/BoolField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/BoolField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/BoolField.java (working copy)
@@ -18,6 +18,7 @@
package org.apache.solr.schema;
import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.SortField;
import org.apache.lucene.util.BytesRef;
@@ -114,11 +115,19 @@
}
@Override
+ public String toExternal(IndexableField f) {
+ return indexedToReadable(f.stringValue());
+ }
+ @Override
public String toExternal(Fieldable f) {
return indexedToReadable(f.stringValue());
}
@Override
+ public Boolean toObject(IndexableField f) {
+ return Boolean.valueOf( toExternal(f) );
+ }
+ @Override
public Boolean toObject(Fieldable f) {
return Boolean.valueOf( toExternal(f) );
}
Index: solr/src/java/org/apache/solr/schema/CollationField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/CollationField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/CollationField.java (working copy)
@@ -32,6 +32,7 @@
import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
import org.apache.lucene.collation.CollationKeyAnalyzer;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TermRangeQuery;
Index: solr/src/java/org/apache/solr/schema/DateField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/DateField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/DateField.java (working copy)
@@ -19,6 +19,7 @@
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TermRangeQuery;
@@ -182,7 +183,7 @@
}
}
- public Fieldable createField(SchemaField field, Object value, float boost) {
+ public IndexableField createField(SchemaField field, Object value, float boost) {
// Convert to a string before indexing
if(value instanceof Date) {
value = toInternal( (Date)value ) + Z;
@@ -207,6 +208,10 @@
}
@Override
+ public String toExternal(IndexableField f) {
+ return indexedToReadable(f.stringValue());
+ }
+ @Override
public String toExternal(Fieldable f) {
return indexedToReadable(f.stringValue());
}
@@ -224,6 +229,15 @@
throw new RuntimeException( ex );
}
}
+ @Override
+ public Date toObject(IndexableField f) {
+ try {
+ return parseDate( toExternal(f) );
+ }
+ catch( ParseException ex ) {
+ throw new RuntimeException( ex );
+ }
+ }
@Override
public SortField getSortField(SchemaField field,boolean reverse) {
Index: solr/src/java/org/apache/solr/schema/DoubleField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/DoubleField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/DoubleField.java (working copy)
@@ -18,6 +18,7 @@
package org.apache.solr.schema;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.lucene.search.cache.DoubleValuesCreator;
@@ -78,6 +79,10 @@
@Override
+ public Double toObject(IndexableField f) {
+ return Double.valueOf(toExternal(f));
+ }
+ @Override
public Double toObject(Fieldable f) {
return Double.valueOf(toExternal(f));
}
Index: solr/src/java/org/apache/solr/schema/ExternalFileField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/ExternalFileField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/ExternalFileField.java (working copy)
@@ -18,6 +18,7 @@
import org.apache.lucene.search.SortField;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexableField;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.FileFloatSource;
import org.apache.solr.search.QParser;
Index: solr/src/java/org/apache/solr/schema/FieldType.java
===================================================================
--- solr/src/java/org/apache/solr/schema/FieldType.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/FieldType.java (working copy)
@@ -21,8 +21,9 @@
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
-import org.apache.lucene.document.Field;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.document2.Field;
+import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Similarity;
@@ -90,7 +91,7 @@
}
/**
- * A "polyField" is a FieldType that can produce more than one Fieldable instance for a single value, via the {@link #createFields(org.apache.solr.schema.SchemaField, Object, float)} method. This is useful
+ * A "polyField" is a FieldType that can produce more than one IndexableField instance for a single value, via the {@link #createFields(org.apache.solr.schema.SchemaField, Object, float)} method. This is useful
* when hiding the implementation details of a field from the Solr end user. For instance, a spatial point may be represented by multiple different fields.
* @return true if the {@link #createFields(org.apache.solr.schema.SchemaField, Object, float)} method may return more than one field
*/
@@ -234,7 +235,7 @@
*
*
*/
- public Fieldable createField(SchemaField field, Object value, float boost) {
+ public IndexableField createField(SchemaField field, Object value, float boost) {
if (!field.indexed() && !field.stored()) {
if (log.isTraceEnabled())
log.trace("Ignoring unindexed/unstored field: " + field);
@@ -249,6 +250,47 @@
}
if (val==null) return null;
+ org.apache.lucene.document2.FieldType newType = new org.apache.lucene.document2.FieldType();
+ newType.setIndexed(field.indexed());
+ newType.setTokenized(field.isTokenized());
+ newType.setStored(field.stored());
+ newType.setOmitNorms(field.omitNorms());
+ newType.setOmitTermFreqAndPositions(field.omitTf());
+ newType.setStoreTermVectors(field.storeTermVector());
+ newType.setStoreTermVectorOffsets(field.storeTermOffsets());
+ newType.setStoreTermVectorPositions(field.storeTermPositions());
+
+ return createField(field.getName(), val, newType, boost);
+ }
+
+ protected Fieldable createField(String name, String val, org.apache.lucene.document.Field.Store storage, org.apache.lucene.document.Field.Index index,
+ org.apache.lucene.document.Field.TermVector vec, boolean omitNorms, boolean omitTFPos, float boost){
+ org.apache.lucene.document.Field f = new org.apache.lucene.document.Field(name,
+ val,
+ storage,
+ index,
+ vec);
+ f.setOmitNorms(omitNorms);
+ f.setOmitTermFreqAndPositions(omitTFPos);
+ f.setBoost(boost);
+ return f;
+ }
+
+ public Fieldable createField2(SchemaField field, Object value, float boost) {
+ if (!field.indexed() && !field.stored()) {
+ if (log.isTraceEnabled())
+ log.trace("Ignoring unindexed/unstored field: " + field);
+ return null;
+ }
+
+ String val;
+ try {
+ val = toInternal(value.toString());
+ } catch (RuntimeException e) {
+ throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Error while creating field '" + field + "' from value '" + value + "'", e, false);
+ }
+ if (val==null) return null;
+
return createField(field.getName(), val, getFieldStore(field, val),
getFieldIndex(field, val), getFieldTermVec(field, val), field.omitNorms(),
field.omitTf(), boost);
@@ -260,66 +302,55 @@
* Fields per SchemaField
* @param name The name of the field
* @param val The _internal_ value to index
- * @param storage {@link org.apache.lucene.document.Field.Store}
- * @param index {@link org.apache.lucene.document.Field.Index}
- * @param vec {@link org.apache.lucene.document.Field.TermVector}
- * @param omitNorms true if norms should be omitted
- * @param omitTFPos true if term freq and position should be omitted.
+ * @param type {@link org.apache.lucene.document2.FieldType}
* @param boost The boost value
- * @return the {@link org.apache.lucene.document.Fieldable}.
+ * @return the {@link org.apache.lucene.index.IndexableField}.
*/
- protected Fieldable createField(String name, String val, Field.Store storage, Field.Index index,
- Field.TermVector vec, boolean omitNorms, boolean omitTFPos, float boost){
- Field f = new Field(name,
- val,
- storage,
- index,
- vec);
- f.setOmitNorms(omitNorms);
- f.setOmitTermFreqAndPositions(omitTFPos);
+ protected IndexableField createField(String name, String val, org.apache.lucene.document2.FieldType type, float boost){
+ Field f = new Field(name, type, val);
f.setBoost(boost);
return f;
}
/**
- * Given a {@link org.apache.solr.schema.SchemaField}, create one or more {@link org.apache.lucene.document.Fieldable} instances
+ * Given a {@link org.apache.solr.schema.SchemaField}, create one or more {@link org.apache.lucene.index.IndexableField} instances
* @param field the {@link org.apache.solr.schema.SchemaField}
* @param value The value to add to the field
* @param boost The boost to apply
- * @return An array of {@link org.apache.lucene.document.Fieldable}
+ * @return An array of {@link org.apache.lucene.index.IndexableField}
*
* @see #createField(SchemaField, Object, float)
* @see #isPolyField()
*/
- public Fieldable[] createFields(SchemaField field, Object value, float boost) {
- Fieldable f = createField( field, value, boost);
- return f==null ? new Fieldable[]{} : new Fieldable[]{f};
+ public IndexableField[] createFields(SchemaField field, Object value, float boost) {
+ IndexableField f = createField( field, value, boost);
+ return f==null ? new IndexableField[]{} : new IndexableField[]{f};
}
/* Helpers for field construction */
- protected Field.TermVector getFieldTermVec(SchemaField field,
+ protected org.apache.lucene.document.Field.TermVector getFieldTermVec(SchemaField field,
String internalVal) {
- Field.TermVector ftv = Field.TermVector.NO;
+ org.apache.lucene.document.Field.TermVector ftv = org.apache.lucene.document.Field.TermVector.NO;
if (field.storeTermPositions() && field.storeTermOffsets())
- ftv = Field.TermVector.WITH_POSITIONS_OFFSETS;
+ ftv = org.apache.lucene.document.Field.TermVector.WITH_POSITIONS_OFFSETS;
else if (field.storeTermPositions())
- ftv = Field.TermVector.WITH_POSITIONS;
+ ftv = org.apache.lucene.document.Field.TermVector.WITH_POSITIONS;
else if (field.storeTermOffsets())
- ftv = Field.TermVector.WITH_OFFSETS;
+ ftv = org.apache.lucene.document.Field.TermVector.WITH_OFFSETS;
else if (field.storeTermVector())
- ftv = Field.TermVector.YES;
+ ftv = org.apache.lucene.document.Field.TermVector.YES;
return ftv;
}
- protected Field.Store getFieldStore(SchemaField field,
+ protected org.apache.lucene.document.Field.Store getFieldStore(SchemaField field,
String internalVal) {
- return field.stored() ? Field.Store.YES : Field.Store.NO;
+ return field.stored() ? org.apache.lucene.document.Field.Store.YES : org.apache.lucene.document.Field.Store.NO;
}
- protected Field.Index getFieldIndex(SchemaField field,
+ protected org.apache.lucene.document.Field.Index getFieldIndex(SchemaField field,
String internalVal) {
- return field.indexed() ? (isTokenized() ? Field.Index.ANALYZED :
- Field.Index.NOT_ANALYZED) : Field.Index.NO;
+ return field.indexed() ? (isTokenized() ? org.apache.lucene.document.Field.Index.ANALYZED :
+ org.apache.lucene.document.Field.Index.NOT_ANALYZED) : org.apache.lucene.document.Field.Index.NO;
}
-
+
/**
* Convert an external value (from XML update command or from query string)
* into the internal format for both storing and indexing (which can be modified by any analyzers).
@@ -338,10 +369,13 @@
*/
public String toExternal(Fieldable f) {
// currently used in writing XML of the search result (but perhaps
- // a more efficient toXML(Fieldable f, Writer w) should be used
+ // a more efficient toXML(IndexableField f, Writer w) should be used
// in the future.
return f.stringValue();
}
+ public String toExternal(IndexableField f) {
+ return f.stringValue();
+ }
/**
* Convert the stored-field format to an external object.
@@ -351,11 +385,14 @@
public Object toObject(Fieldable f) {
return toExternal(f); // by default use the string
}
+ public Object toObject(IndexableField f) {
+ return toExternal(f); // by default use the string
+ }
public Object toObject(SchemaField sf, BytesRef term) {
final CharsRef ref = new CharsRef(term.length);
indexedToReadable(term, ref);
- final Fieldable f = createField(sf, ref.toString(), 1.0f);
+ final IndexableField f = createField(sf, ref.toString(), 1.0f);
return toObject(f);
}
@@ -374,6 +411,10 @@
public String storedToReadable(Fieldable f) {
return toExternal(f);
}
+ /** Given the stored field, return the human readable representation */
+ public String storedToReadable(IndexableField f) {
+ return toExternal(f);
+ }
/** Given the stored field, return the indexed form */
public String storedToIndexed(Fieldable f) {
@@ -382,6 +423,10 @@
// that the indexed form is the same as the stored field form.
return f.stringValue();
}
+ /** Given the stored field, return the indexed form */
+ public String storedToIndexed(IndexableField f) {
+ return f.stringValue();
+ }
/** Given the readable value, return the term value that will match it. */
public String readableToIndexed(String val) {
Index: solr/src/java/org/apache/solr/schema/FloatField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/FloatField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/FloatField.java (working copy)
@@ -24,6 +24,7 @@
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.FloatFieldSource;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexableField;
import org.apache.solr.response.TextResponseWriter;
import java.util.Map;
@@ -75,6 +76,10 @@
}
@Override
+ public Float toObject(IndexableField f) {
+ return Float.valueOf( toExternal(f) );
+ }
+ @Override
public Float toObject(Fieldable f) {
return Float.valueOf( toExternal(f) );
}
Index: solr/src/java/org/apache/solr/schema/GeoHashField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/GeoHashField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/GeoHashField.java (working copy)
@@ -18,6 +18,7 @@
package org.apache.solr.schema;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SortField;
import org.apache.lucene.spatial.geohash.GeoHashUtils;
@@ -75,7 +76,7 @@
@Override
- public String toExternal(Fieldable f) {
+ public String toExternal(IndexableField f) {
double[] latLon = GeoHashUtils.decode(f.stringValue());
return latLon[0] + "," + latLon[1];
}
Index: solr/src/java/org/apache/solr/schema/IndexSchema.java
===================================================================
--- solr/src/java/org/apache/solr/schema/IndexSchema.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/IndexSchema.java (working copy)
@@ -20,6 +20,7 @@
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.DefaultSimilarity;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Similarity;
@@ -260,8 +261,11 @@
* @return null if this schema has no unique key field
* @see #printableUniqueKey
*/
+ public IndexableField getUniqueKeyField(org.apache.lucene.document2.Document doc) {
+ return doc.getField(uniqueKeyFieldName); // this should return null if name is null
+ }
public Fieldable getUniqueKeyField(org.apache.lucene.document.Document doc) {
- return doc.getFieldable(uniqueKeyFieldName); // this should return null if name is null
+ return doc.getField(uniqueKeyFieldName); // this should return null if name is null
}
/**
@@ -270,9 +274,13 @@
* @return null if this schema has no unique key field
*/
public String printableUniqueKey(org.apache.lucene.document.Document doc) {
- Fieldable f = doc.getFieldable(uniqueKeyFieldName);
- return f==null ? null : uniqueKeyFieldType.toExternal(f);
- }
+ Fieldable f = doc.getFieldable(uniqueKeyFieldName);
+ return f==null ? null : uniqueKeyFieldType.toExternal(f);
+ }
+ public String printableUniqueKey(org.apache.lucene.document2.Document doc) {
+ IndexableField f = doc.getField(uniqueKeyFieldName);
+ return f==null ? null : uniqueKeyFieldType.toExternal(f);
+ }
private SchemaField getIndexedField(String fname) {
SchemaField f = getFields().get(fname);
Index: solr/src/java/org/apache/solr/schema/IntField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/IntField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/IntField.java (working copy)
@@ -24,6 +24,7 @@
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.IntFieldSource;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexableField;
import org.apache.solr.response.TextResponseWriter;
import java.util.Map;
@@ -75,6 +76,10 @@
}
@Override
+ public Integer toObject(IndexableField f) {
+ return Integer.valueOf( toExternal(f) );
+ }
+ @Override
public Integer toObject(Fieldable f) {
return Integer.valueOf( toExternal(f) );
}
Index: solr/src/java/org/apache/solr/schema/LatLonType.java
===================================================================
--- solr/src/java/org/apache/solr/schema/LatLonType.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/LatLonType.java (working copy)
@@ -16,8 +16,9 @@
* limitations under the License.
*/
-import org.apache.lucene.document.Field;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.document2.FieldType;
+import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.search.*;
@@ -54,10 +55,10 @@
}
@Override
- public Fieldable[] createFields(SchemaField field, Object value, float boost) {
+ public IndexableField[] createFields(SchemaField field, Object value, float boost) {
String externalVal = value.toString();
//we could have tileDiff + 3 fields (two for the lat/lon, one for storage)
- Fieldable[] f = new Fieldable[(field.indexed() ? 2 : 0) + (field.stored() ? 1 : 0)];
+ IndexableField[] f = new IndexableField[(field.indexed() ? 2 : 0) + (field.stored() ? 1 : 0)];
if (field.indexed()) {
int i = 0;
double[] latLon = new double[0];
@@ -75,9 +76,10 @@
}
if (field.stored()) {
- f[f.length - 1] = createField(field.getName(), externalVal,
- getFieldStore(field, externalVal), Field.Index.NO, Field.TermVector.NO,
- false, false, boost);
+ FieldType customType = new FieldType();
+ customType.setStored(true);
+
+ f[f.length - 1] = createField(field.getName(), externalVal, customType, boost);
}
return f;
}
@@ -281,7 +283,7 @@
//It never makes sense to create a single field, so make it impossible to happen
@Override
- public Fieldable createField(SchemaField field, Object value, float boost) {
+ public IndexableField createField(SchemaField field, Object value, float boost) {
throw new UnsupportedOperationException("LatLonType uses multiple fields. field=" + field.getName());
}
Index: solr/src/java/org/apache/solr/schema/LongField.java
===================================================================
--- solr/src/java/org/apache/solr/schema/LongField.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/LongField.java (working copy)
@@ -18,6 +18,7 @@
package org.apache.solr.schema;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.lucene.search.cache.LongValuesCreator;
@@ -77,6 +78,10 @@
}
@Override
+ public Long toObject(IndexableField f) {
+ return Long.valueOf( toExternal(f) );
+ }
+ @Override
public Long toObject(Fieldable f) {
return Long.valueOf( toExternal(f) );
}
Index: solr/src/java/org/apache/solr/schema/PointType.java
===================================================================
--- solr/src/java/org/apache/solr/schema/PointType.java (revision 1145347)
+++ solr/src/java/org/apache/solr/schema/PointType.java (working copy)
@@ -19,6 +19,7 @@
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
@@ -68,7 +69,7 @@
}
@Override
- public Fieldable[] createFields(SchemaField field, Object value, float boost) {
+ public IndexableField[] createFields(SchemaField field, Object value, float boost) {
String externalVal = value.toString();
String[] point = new String[0];
try {
@@ -78,7 +79,7 @@
}
// TODO: this doesn't currently support polyFields as sub-field types
- Fieldable[] f = new Fieldable[ (field.indexed() ? dimension : 0) + (field.stored() ? 1 : 0) ];
+ IndexableField[] f = new IndexableField[ (field.indexed() ? dimension : 0) + (field.stored() ? 1 : 0) ];
if (field.indexed()) {
for (int i=0; i