You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by gs...@apache.org on 2008/02/20 04:36:56 UTC
svn commit: r629334 - in /lucene/solr/trunk: ./
src/java/org/apache/solr/schema/ src/java/org/apache/solr/search/function/
Author: gsingers
Date: Tue Feb 19 19:36:49 2008
New Revision: 629334
URL: http://svn.apache.org/viewvc?rev=629334&view=rev
Log:
SOLR-324: fixed support for longs/doubles, still need to add short and byte, per next Lucene update from trunk.
Added:
lucene/solr/trunk/src/java/org/apache/solr/search/function/DoubleFieldSource.java (with props)
lucene/solr/trunk/src/java/org/apache/solr/search/function/LongFieldSource.java (with props)
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/src/java/org/apache/solr/schema/DoubleField.java
lucene/solr/trunk/src/java/org/apache/solr/schema/LongField.java
lucene/solr/trunk/src/java/org/apache/solr/search/function/DocValues.java
lucene/solr/trunk/src/java/org/apache/solr/search/function/FieldCacheSource.java
Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=629334&r1=629333&r2=629334&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Tue Feb 19 19:36:49 2008
@@ -255,6 +255,8 @@
17. SOLR-481: Handle UnknownHostException in _info.jsp (gsingers)
+18. SOLR-324: Add proper support for Long and Doubles in sorting, etc. (gsingers)
+
Other Changes
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the
build scripts to make two jars: apache-solr-1.3.jar and
Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/DoubleField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/DoubleField.java?rev=629334&r1=629333&r2=629334&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/DoubleField.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/DoubleField.java Tue Feb 19 19:36:49 2008
@@ -17,32 +17,32 @@
package org.apache.solr.schema;
-import org.apache.lucene.search.SortField;
-import org.apache.solr.search.function.ValueSource;
-import org.apache.solr.search.function.FloatFieldSource;
import org.apache.lucene.document.Fieldable;
-import org.apache.solr.request.XMLWriter;
+import org.apache.lucene.search.SortField;
import org.apache.solr.request.TextResponseWriter;
+import org.apache.solr.request.XMLWriter;
+import org.apache.solr.search.function.DoubleFieldSource;
+import org.apache.solr.search.function.ValueSource;
-import java.util.Map;
import java.io.IOException;
+import java.util.Map;
+
/**
* @version $Id$
*/
public class DoubleField extends FieldType {
- protected void init(IndexSchema schema, Map<String,String> args) {
+ protected void init(IndexSchema schema, Map<String, String> args) {
restrictProps(SORT_MISSING_FIRST | SORT_MISSING_LAST);
}
/////////////////////////////////////////////////////////////
- // TODO: ACK.. there is currently no SortField.DOUBLE!
- public SortField getSortField(SchemaField field,boolean reverse) {
- return new SortField(field.name,SortField.FLOAT, reverse);
+ public SortField getSortField(SchemaField field, boolean reverse) {
+ return new SortField(field.name, SortField.DOUBLE, reverse);
}
public ValueSource getValueSource(SchemaField field) {
// fieldCache doesn't support double
- return new FloatFieldSource(field.name);
+ return new DoubleFieldSource(field.name);
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
@@ -52,10 +52,10 @@
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
writer.writeDouble(name, f.stringValue());
}
-
+
@Override
public Double toObject(Fieldable f) {
- return Double.valueOf( toExternal(f) );
+ return Double.valueOf(toExternal(f));
}
}
Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/LongField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/LongField.java?rev=629334&r1=629333&r2=629334&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/LongField.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/LongField.java Tue Feb 19 19:36:49 2008
@@ -17,15 +17,16 @@
package org.apache.solr.schema;
-import org.apache.lucene.search.SortField;
-import org.apache.solr.search.function.ValueSource;
-import org.apache.solr.search.function.IntFieldSource;
import org.apache.lucene.document.Fieldable;
-import org.apache.solr.request.XMLWriter;
+import org.apache.lucene.search.SortField;
import org.apache.solr.request.TextResponseWriter;
+import org.apache.solr.request.XMLWriter;
+import org.apache.solr.search.function.IntFieldSource;
+import org.apache.solr.search.function.ValueSource;
+import org.apache.solr.search.function.LongFieldSource;
-import java.util.Map;
import java.io.IOException;
+import java.util.Map;
/**
* @version $Id$
*/
@@ -35,15 +36,15 @@
}
/////////////////////////////////////////////////////////////
- // TODO: ACK.. there is no SortField.LONG!
+
public SortField getSortField(SchemaField field,boolean reverse) {
- // todo - log warning
- return new SortField(field.name,SortField.INT, reverse);
+
+ return new SortField(field.name,SortField.LONG, reverse);
}
public ValueSource getValueSource(SchemaField field) {
- // todo - log warning
- return new IntFieldSource(field.name);
+
+ return new LongFieldSource(field.name);
}
Modified: lucene/solr/trunk/src/java/org/apache/solr/search/function/DocValues.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/DocValues.java?rev=629334&r1=629333&r2=629334&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/DocValues.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/DocValues.java Tue Feb 19 19:36:49 2008
@@ -33,6 +33,9 @@
// - For caching, Query objects are often used as keys... you don't
// want the Query carrying around big objects
public abstract class DocValues {
+ public byte byteVal(int doc) { throw new UnsupportedOperationException(); }
+ public short shortVal(int doc) { throw new UnsupportedOperationException(); }
+
public float floatVal(int doc) { throw new UnsupportedOperationException(); }
public int intVal(int doc) { throw new UnsupportedOperationException(); }
public long longVal(int doc) { throw new UnsupportedOperationException(); }
Added: lucene/solr/trunk/src/java/org/apache/solr/search/function/DoubleFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/DoubleFieldSource.java?rev=629334&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/DoubleFieldSource.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/DoubleFieldSource.java Tue Feb 19 19:36:49 2008
@@ -0,0 +1,96 @@
+/**
+ * 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.
+ */
+
+package org.apache.solr.search.function;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.ExtendedFieldCache;
+
+import java.io.IOException;
+
+/**
+ * Obtains float field values from the {@link org.apache.lucene.search.FieldCache}
+ * using <code>getFloats()</code>
+ * and makes those values available as other numeric types, casting as needed.
+ *
+ * @version $Id:$
+ */
+
+public class DoubleFieldSource extends FieldCacheSource {
+ protected ExtendedFieldCache.DoubleParser parser;
+
+ public DoubleFieldSource(String field) {
+ this(field, null);
+ }
+
+ public DoubleFieldSource(String field, ExtendedFieldCache.DoubleParser parser) {
+ super(field);
+ this.parser = parser;
+ }
+
+ public String description() {
+ return "double(" + field + ')';
+ }
+
+ public DocValues getValues(IndexReader reader) throws IOException {
+ final double[] arr = (parser == null) ?
+ ((ExtendedFieldCache) cache).getDoubles(reader, field) :
+ ((ExtendedFieldCache) cache).getDoubles(reader, field, parser);
+ return new DocValues() {
+ public float floatVal(int doc) {
+ return (float) arr[doc];
+ }
+
+ public int intVal(int doc) {
+ return (int) arr[doc];
+ }
+
+ public long longVal(int doc) {
+ return (long) arr[doc];
+ }
+
+ public double doubleVal(int doc) {
+ return arr[doc];
+ }
+
+ public String strVal(int doc) {
+ return Double.toString(arr[doc]);
+ }
+
+ public String toString(int doc) {
+ return description() + '=' + floatVal(doc);
+ }
+ };
+ }
+
+ public boolean equals(Object o) {
+ if (o.getClass() != DoubleFieldSource.class) return false;
+ DoubleFieldSource other = (DoubleFieldSource) o;
+ return super.equals(other)
+ && this.parser == null ? other.parser == null :
+ this.parser.getClass() == other.parser.getClass();
+ }
+
+ public int hashCode() {
+ int h = parser == null ? Float.class.hashCode() : parser.getClass().hashCode();
+ h += super.hashCode();
+ return h;
+ }
+
+ ;
+
+}
\ No newline at end of file
Propchange: lucene/solr/trunk/src/java/org/apache/solr/search/function/DoubleFieldSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: lucene/solr/trunk/src/java/org/apache/solr/search/function/FieldCacheSource.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/FieldCacheSource.java?rev=629334&r1=629333&r2=629334&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/FieldCacheSource.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/FieldCacheSource.java Tue Feb 19 19:36:49 2008
@@ -18,6 +18,7 @@
package org.apache.solr.search.function;
import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.search.ExtendedFieldCache;
/**
* A base class for ValueSource implementations that retrieve values for
@@ -27,15 +28,22 @@
*/
public abstract class FieldCacheSource extends ValueSource {
protected String field;
- protected FieldCache cache = FieldCache.DEFAULT;
+ protected FieldCache cache = ExtendedFieldCache.EXT_DEFAULT;
public FieldCacheSource(String field) {
this.field=field;
}
+ /**
+ * If you are using longs or doubles, this needs to be a {@link org.apache.lucene.search.ExtendedFieldCache}.
+ *
+ * @param cache The {@link org.apache.lucene.search.FieldCache}
+ */
public void setFieldCache(FieldCache cache) {
this.cache = cache;
}
+
+
public FieldCache getFieldCache() {
return cache;
Added: lucene/solr/trunk/src/java/org/apache/solr/search/function/LongFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/LongFieldSource.java?rev=629334&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/LongFieldSource.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/LongFieldSource.java Tue Feb 19 19:36:49 2008
@@ -0,0 +1,97 @@
+/**
+ * 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.
+ */
+
+package org.apache.solr.search.function;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.ExtendedFieldCache;
+
+
+import java.io.IOException;
+
+/**
+ * Obtains float field values from the {@link org.apache.lucene.search.FieldCache}
+ * using <code>getFloats()</code>
+ * and makes those values available as other numeric types, casting as needed.
+ *
+ * @version $Id: FloatFieldSource.java 555343 2007-07-11 17:46:25Z hossman $
+ */
+
+public class LongFieldSource extends FieldCacheSource {
+ protected ExtendedFieldCache.LongParser parser;
+
+ public LongFieldSource(String field) {
+ this(field, null);
+ }
+
+ public LongFieldSource(String field, ExtendedFieldCache.LongParser parser) {
+ super(field);
+ this.parser = parser;
+ }
+
+ public String description() {
+ return "long(" + field + ')';
+ }
+
+ public DocValues getValues(IndexReader reader) throws IOException {
+ final long[] arr = (parser == null) ?
+ ((ExtendedFieldCache) cache).getLongs(reader, field) :
+ ((ExtendedFieldCache) cache).getLongs(reader, field, parser);
+ return new DocValues() {
+ public float floatVal(int doc) {
+ return (float) arr[doc];
+ }
+
+ public int intVal(int doc) {
+ return (int) arr[doc];
+ }
+
+ public long longVal(int doc) {
+ return (long) arr[doc];
+ }
+
+ public double doubleVal(int doc) {
+ return arr[doc];
+ }
+
+ public String strVal(int doc) {
+ return Double.toString(arr[doc]);
+ }
+
+ public String toString(int doc) {
+ return description() + '=' + floatVal(doc);
+ }
+ };
+ }
+
+ public boolean equals(Object o) {
+ if (o.getClass() != LongFieldSource.class) return false;
+ LongFieldSource other = (LongFieldSource) o;
+ return super.equals(other)
+ && this.parser == null ? other.parser == null :
+ this.parser.getClass() == other.parser.getClass();
+ }
+
+ public int hashCode() {
+ int h = parser == null ? Float.class.hashCode() : parser.getClass().hashCode();
+ h += super.hashCode();
+ return h;
+ }
+
+ ;
+
+}
\ No newline at end of file
Propchange: lucene/solr/trunk/src/java/org/apache/solr/search/function/LongFieldSource.java
------------------------------------------------------------------------------
svn:eol-style = native