lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1201479 - in /lucene/dev/branches/branch_3x/solr: CHANGES.txt core/src/java/org/apache/solr/schema/TrieField.java example/solr/conf/schema.xml
Date Sun, 13 Nov 2011 19:11:53 GMT
Author: erick
Date: Sun Nov 13 19:11:52 2011
New Revision: 1201479

URL: http://svn.apache.org/viewvc?rev=1201479&view=rev
Log:
Fixes for SOLR-2881, making Trie fields respect sortMissingFirst/Last

Modified:
    lucene/dev/branches/branch_3x/solr/CHANGES.txt
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/TrieField.java
    lucene/dev/branches/branch_3x/solr/example/solr/conf/schema.xml

Modified: lucene/dev/branches/branch_3x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/CHANGES.txt?rev=1201479&r1=1201478&r2=1201479&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/solr/CHANGES.txt Sun Nov 13 19:11:52 2011
@@ -62,6 +62,9 @@ New Features
 
 * SOLR-1926: Add hl.q parameter. (koji)
 
+* SOLR-2881: Numeric types now support sortMissingFirst/Last. This includes Trie and date
types
+  (Ryan McKinley, Mike McCandless, Erick Erickson)
+
 Optimizations
 ----------------------
 

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/TrieField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/TrieField.java?rev=1201479&r1=1201478&r2=1201479&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/TrieField.java
(original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/TrieField.java
Sun Nov 13 19:11:52 2011
@@ -60,6 +60,8 @@ public class TrieField extends FieldType
   protected int precisionStepArg = TrieField.DEFAULT_PRECISION_STEP;  // the one passed in
or defaulted
   protected int precisionStep;     // normalized
   protected TrieTypes type;
+  protected Object missingValue;
+
 
   /**
    * Used for handling date types following the same semantics as DateField
@@ -125,16 +127,48 @@ public class TrieField extends FieldType
   public SortField getSortField(SchemaField field, boolean top) {
     field.checkSortability();
 
+    Object missingValue = null;
+    boolean sortMissingLast  = field.sortMissingLast();
+    boolean sortMissingFirst = field.sortMissingFirst();
+
     switch (type) {
       case INTEGER:
-        return new SortField(field.getName(), FieldCache.NUMERIC_UTILS_INT_PARSER, top);
+        if( sortMissingLast ) {
+          missingValue = top ? Integer.MIN_VALUE : Integer.MAX_VALUE;
+        }
+        else if( sortMissingFirst ) {
+          missingValue = top ? Integer.MAX_VALUE : Integer.MIN_VALUE;
+        }
+        return new SortField( field.getName(), FieldCache.NUMERIC_UTILS_INT_PARSER, top).setMissingValue(missingValue);
+
       case FLOAT:
-        return new SortField(field.getName(), FieldCache.NUMERIC_UTILS_FLOAT_PARSER, top);
+        if( sortMissingLast ) {
+          missingValue = top ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;
+        }
+        else if( sortMissingFirst ) {
+          missingValue = top ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
+        }
+        return new SortField( field.getName(), FieldCache.NUMERIC_UTILS_FLOAT_PARSER, top).setMissingValue(missingValue);
+
       case DATE: // fallthrough
       case LONG:
-        return new SortField(field.getName(), FieldCache.NUMERIC_UTILS_LONG_PARSER, top);
+        if( sortMissingLast ) {
+          missingValue = top ? Long.MIN_VALUE : Long.MAX_VALUE;
+        }
+        else if( sortMissingFirst ) {
+          missingValue = top ? Long.MAX_VALUE : Long.MIN_VALUE;
+        }
+        return new SortField( field.getName(), FieldCache.NUMERIC_UTILS_LONG_PARSER, top).setMissingValue(missingValue);
+
       case DOUBLE:
-        return new SortField(field.getName(), FieldCache.NUMERIC_UTILS_DOUBLE_PARSER, top);
+        if( sortMissingLast ) {
+          missingValue = top ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
+        }
+        else if( sortMissingFirst ) {
+          missingValue = top ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
+        }
+        return new SortField( field.getName(), FieldCache.NUMERIC_UTILS_DOUBLE_PARSER, top).setMissingValue(missingValue);
+
       default:
         throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie
field: " + field.name);
     }
@@ -441,10 +475,6 @@ class TrieDateFieldSource extends LongFi
     super(field, parser);
   }
 
-  public TrieDateFieldSource(String field) {
-    super(field);
-  }
-
   @Override
   public String description() {
     return "date(" + field + ')';

Modified: lucene/dev/branches/branch_3x/solr/example/solr/conf/schema.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/example/solr/conf/schema.xml?rev=1201479&r1=1201478&r2=1201479&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/example/solr/conf/schema.xml (original)
+++ lucene/dev/branches/branch_3x/solr/example/solr/conf/schema.xml Sun Nov 13 19:11:52 2011
@@ -75,8 +75,10 @@
     <fieldtype name="binary" class="solr.BinaryField"/>
 
     <!-- The optional sortMissingLast and sortMissingFirst attributes are
-         currently supported on types that are sorted internally as strings.
-	       This includes "string","boolean","sint","slong","sfloat","sdouble","pdate"
+         currently supported on types that are sorted internally as strings
+         and on numeric types.
+	       This includes "string","boolean", and, as of 3.5 (and 4.x),
+	       int, float, long, date, double, including the "Trie" variants.
        - If sortMissingLast="true", then a sort on this field will cause documents
          without the field to come after documents with the field,
          regardless of the requested sort order (asc or desc).
@@ -157,8 +159,8 @@
 
     <!--
       Note:
-      These should only be used for compatibility with existing indexes (created with older
Solr versions)
-      or if "sortMissingFirst" or "sortMissingLast" functionality is needed. Use Trie based
fields instead.
+      These should only be used for compatibility with existing indexes (created with older
Solr versions).
+      Use Trie based fields instead. As of Solr 3.5 and 4.x, Trie based fields support sortMissingFirst/Last
 
       Numeric field types that manipulate the value into
       a string value that isn't human-readable in its internal form,
@@ -581,7 +583,7 @@
    <dynamicField name="*_tf" type="tfloat"  indexed="true"  stored="true"/>
    <dynamicField name="*_td" type="tdouble" indexed="true"  stored="true"/>
    <dynamicField name="*_tdt" type="tdate"  indexed="true"  stored="true"/>
-
+   
    <dynamicField name="*_pi"  type="pint"    indexed="true"  stored="true"/>
 
    <dynamicField name="ignored_*" type="ignored" multiValued="true"/>



Mime
View raw message