lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1201715 [2/2] - in /lucene/dev/branches/lucene2621: ./ dev-tools/idea/lucene/contrib/ lucene/ lucene/contrib/sandbox/src/test/org/apache/lucene/sandbox/queries/regex/ lucene/src/java/org/apache/lucene/document/ lucene/src/java/org/apache/l...
Date Mon, 14 Nov 2011 14:15:22 GMT
Modified: lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java?rev=1201715&r1=1201714&r2=1201715&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java
(original)
+++ lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java
Mon Nov 14 14:15:19 2011
@@ -17,6 +17,7 @@
 package org.apache.solr.handler.dataimport;
 
 import org.apache.solr.common.SolrException;
+
 import static org.apache.solr.handler.dataimport.DataImportHandlerException.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,21 +43,25 @@ public class EntityProcessorBase extends
 
   protected Iterator<Map<String, Object>> rowIterator;
 
-  protected List<Transformer> transformers;
-
-  protected String query;
-
-  protected String onError = ABORT;
+  protected String query;  
+  
+  protected String onError = ABORT;  
+  
+  protected DIHCacheSupport cacheSupport = null;
 
 
   @Override
   public void init(Context context) {
-    rowIterator = null;
     this.context = context;
     if (isFirstInit) {
       firstInit(context);
     }
-    query = null;
+    if(cacheSupport!=null) {
+      rowIterator = null;
+      query = null;
+      cacheSupport.initNewParent(context);
+    }   
+    
   }
 
   /**first time init call. do one-time operations here
@@ -65,29 +70,20 @@ public class EntityProcessorBase extends
     entityName = context.getEntityAttribute("name");
     String s = context.getEntityAttribute(ON_ERROR);
     if (s != null) onError = s;
+    initCache(context);
     isFirstInit = false;
   }
 
+    protected void initCache(Context context) {
+        String cacheImplName = context
+            .getResolvedEntityAttribute(DIHCacheSupport.CACHE_IMPL);
 
-  protected Map<String, Object> getNext() {
-    try {
-      if (rowIterator == null)
-        return null;
-      if (rowIterator.hasNext())
-        return rowIterator.next();
-      query = null;
-      rowIterator = null;
-      return null;
-    } catch (Exception e) {
-      SolrException.log(log, "getNext() failed for query '" + query + "'", e);
-      query = null;
-      rowIterator = null;
-      wrapAndThrow(DataImportHandlerException.WARN, e);
-      return null;
+        if (cacheImplName != null ) {
+          cacheSupport = new DIHCacheSupport(context, cacheImplName);
+        }
     }
-  }
 
-  @Override
+    @Override
   public Map<String, Object> nextModifiedRowKey() {
     return null;
   }
@@ -113,165 +109,40 @@ public class EntityProcessorBase extends
   public Map<String, Object> nextRow() {
     return null;// do not do anything
   }
-
-
-  @Override
-  public void destroy() {
-    /*no op*/
-  }
-
-  /**
-   * Only used by cache implementations
-   */
-  protected String cachePk;
-
-  /**
-   * Only used by cache implementations
-   */
-  protected String cacheVariableName;
-
-  /**
-   * Only used by cache implementations
-   */
-  protected Map<String, List<Map<String, Object>>> simpleCache;
-
-  /**
-   * Only used by cache implementations
-   */
-  protected Map<String, Map<Object, List<Map<String, Object>>>> cacheWithWhereClause;
-
-  protected List<Map<String, Object>> dataSourceRowCache;
-
-  /**
-   * Only used by cache implementations
-   */
-  protected void cacheInit() {
-    if (simpleCache != null || cacheWithWhereClause != null)
-      return;
-    String where = context.getEntityAttribute("where");
-
-    String cacheKey = context.getEntityAttribute(CACHE_KEY);
-    String lookupKey = context.getEntityAttribute(CACHE_LOOKUP);
-    if(cacheKey != null && lookupKey == null){
-      throw new DataImportHandlerException(DataImportHandlerException.SEVERE,
-              "'cacheKey' is specified for the entity "+ entityName+" but 'cacheLookup' is
missing" );
-
-    }
-    if (where == null && cacheKey == null) {
-      simpleCache = new HashMap<String, List<Map<String, Object>>>();
-    } else {
-      if (where != null) {
-        String[] splits = where.split("=");
-        cachePk = splits[0];
-        cacheVariableName = splits[1].trim();
-      } else {
-        cachePk = cacheKey;
-        cacheVariableName = lookupKey;
-      }
-      cacheWithWhereClause = new HashMap<String, Map<Object, List<Map<String,
Object>>>>();
-    }
-  }
-
-  /**
-   * If the where clause is present the cache is sql Vs Map of key Vs List of Rows. Only
used by cache implementations.
-   *
-   * @param query the query string for which cached data is to be returned
-   *
-   * @return the cached row corresponding to the given query after all variables have been
resolved
-   */
-  protected Map<String, Object> getIdCacheData(String query) {
-    Map<Object, List<Map<String, Object>>> rowIdVsRows = cacheWithWhereClause
-            .get(query);
-    List<Map<String, Object>> rows = null;
-    Object key = context.resolve(cacheVariableName);
-    if (key == null) {
-      throw new DataImportHandlerException(DataImportHandlerException.WARN,
-              "The cache lookup value : " + cacheVariableName + " is resolved to be null
in the entity :" +
-                      context.getEntityAttribute("name"));
-
-    }
-    if (rowIdVsRows != null) {
-      rows = rowIdVsRows.get(key);
-      if (rows == null)
+  
+  protected Map<String, Object> getNext() {
+    if(cacheSupport==null) {
+      try {
+        if (rowIterator == null)
+          return null;
+        if (rowIterator.hasNext())
+          return rowIterator.next();
+        query = null;
+        rowIterator = null;
         return null;
-      dataSourceRowCache = new ArrayList<Map<String, Object>>(rows);
-      return getFromRowCacheTransformed();
-    } else {
-      rows = getAllNonCachedRows();
-      if (rows.isEmpty()) {
+      } catch (Exception e) {
+        SolrException.log(log, "getNext() failed for query '" + query + "'", e);
+        query = null;
+        rowIterator = null;
+        wrapAndThrow(DataImportHandlerException.WARN, e);
         return null;
-      } else {
-        rowIdVsRows = new HashMap<Object, List<Map<String, Object>>>();
-        for (Map<String, Object> row : rows) {
-          Object k = row.get(cachePk);
-          if (k == null) {
-            throw new DataImportHandlerException(DataImportHandlerException.WARN,
-                    "No value available for the cache key : " + cachePk + " in the entity
: " +
-                            context.getEntityAttribute("name"));
-          }
-          if (!k.getClass().equals(key.getClass())) {
-            throw new DataImportHandlerException(DataImportHandlerException.WARN,
-                    "The key in the cache type : " + k.getClass().getName() +
-                            "is not same as the lookup value type " + key.getClass().getName()
+ " in the entity " +
-                            context.getEntityAttribute("name"));
-          }
-          if (rowIdVsRows.get(k) == null)
-            rowIdVsRows.put(k, new ArrayList<Map<String, Object>>());
-          rowIdVsRows.get(k).add(row);
-        }
-        cacheWithWhereClause.put(query, rowIdVsRows);
-        if (!rowIdVsRows.containsKey(key))
-          return null;
-        dataSourceRowCache = new ArrayList<Map<String, Object>>(rowIdVsRows.get(key));
-        if (dataSourceRowCache.isEmpty()) {
-          dataSourceRowCache = null;
-          return null;
-        }
-        return getFromRowCacheTransformed();
       }
-    }
+    } else  {
+      return cacheSupport.getCacheData(context, query, rowIterator);
+    }      
   }
 
-  /**
-   * <p> Get all the rows from the the datasource for the given query. Only used by
cache implementations. </p> This
-   * <b>must</b> be implemented by sub-classes which intend to provide a cached
implementation
-   *
-   * @return the list of all rows fetched from the datasource.
-   */
-  protected List<Map<String, Object>> getAllNonCachedRows() {
-    return Collections.EMPTY_LIST;
-  }
 
-  /**
-   * If where clause is not present the cache is a Map of query vs List of Rows. Only used
by cache implementations.
-   *
-   * @param query string for which cached row is to be returned
-   *
-   * @return the cached row corresponding to the given query
-   */
-  protected Map<String, Object> getSimpleCacheData(String query) {
-    List<Map<String, Object>> rows = simpleCache.get(query);
-    if (rows != null) {
-      dataSourceRowCache = new ArrayList<Map<String, Object>>(rows);
-      return getFromRowCacheTransformed();
-    } else {
-      rows = getAllNonCachedRows();
-      if (rows.isEmpty()) {
-        return null;
-      } else {
-        dataSourceRowCache = new ArrayList<Map<String, Object>>(rows);
-        simpleCache.put(query, rows);
-        return getFromRowCacheTransformed();
-      }
-    }
+  @Override
+  public void destroy() {
+  	query = null;
+  	if(cacheSupport!=null){
+  	  cacheSupport.destroyAll();
+  	}
+  	cacheSupport = null;
   }
 
-  protected Map<String, Object> getFromRowCacheTransformed() {
-    Map<String, Object> r = dataSourceRowCache.remove(0);
-    if (dataSourceRowCache.isEmpty())
-      dataSourceRowCache = null;
-    return r;
-  }
+  
 
   public static final String TRANSFORMER = "transformer";
 
@@ -287,8 +158,4 @@ public class EntityProcessorBase extends
 
   public static final String SKIP_DOC = "$skipDoc";
 
-  public static final String CACHE_KEY = "cacheKey";
-  
-  public static final String CACHE_LOOKUP = "cacheLookup";
-
 }

Modified: lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SolrWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SolrWriter.java?rev=1201715&r1=1201714&r2=1201715&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SolrWriter.java
(original)
+++ lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SolrWriter.java
Mon Nov 14 14:15:19 2011
@@ -37,7 +37,7 @@ import java.util.Set;
  *
  * @since solr 1.3
  */
-public class SolrWriter implements DIHWriter {
+public class SolrWriter extends DIHWriterBase implements DIHWriter {
   private static final Logger log = LoggerFactory.getLogger(SolrWriter.class);
 
   static final String LAST_INDEX_KEY = "last_index_time";
@@ -159,5 +159,5 @@ public class SolrWriter implements DIHWr
 	@Override
 	public void init(Context context) {
 		/* NO-OP */		
-	}
+	}	
 }

Modified: lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ThreadedContext.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ThreadedContext.java?rev=1201715&r1=1201714&r2=1201715&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ThreadedContext.java
(original)
+++ lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ThreadedContext.java
Mon Nov 14 14:15:19 2011
@@ -24,17 +24,19 @@ package org.apache.solr.handler.dataimpo
  */
 public class ThreadedContext extends ContextImpl{
   private DocBuilder.EntityRunner entityRunner;
+  private VariableResolverImpl resolver;
   private boolean limitedContext = false;
 
-  public ThreadedContext(DocBuilder.EntityRunner entityRunner, DocBuilder docBuilder) {
+  public ThreadedContext(DocBuilder.EntityRunner entityRunner, DocBuilder docBuilder, VariableResolverImpl
resolver) {
     super(entityRunner.entity,
-            null,//to be fetched realtime
+    				resolver,
             null,
             null,
             docBuilder.session,
             null,
             docBuilder);
     this.entityRunner = entityRunner;
+    this.resolver = resolver;
   }
 
   @Override
@@ -45,7 +47,7 @@ public class ThreadedContext extends Con
 
   @Override
   public Context getParentContext() {
-    ThreadedContext ctx = new ThreadedContext(entityRunner.parent, docBuilder);
+  	ThreadedContext ctx = new ThreadedContext(entityRunner.parent, docBuilder, resolver);
     ctx.limitedContext =  true;
     return ctx;
   }

Modified: lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-schema.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-schema.xml?rev=1201715&r1=1201714&r2=1201715&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-schema.xml
(original)
+++ lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-schema.xml
Mon Nov 14 14:15:19 2011
@@ -274,14 +274,15 @@
         EXAMPLE:  name="*_i" will match any field ending in _i (like myid_i, z_i)
         Longer patterns will be matched first.  if equal size patterns
         both match, the first appearing in the schema will be used.  -->
-   <dynamicField name="*_i"  type="sint"    indexed="true"  stored="true"/>
-   <dynamicField name="*_s"  type="string"  indexed="true"  stored="true"/>
-   <dynamicField name="*_l"  type="slong"   indexed="true"  stored="true"/>
-   <dynamicField name="*_t"  type="text"    indexed="true"  stored="true"/>
-   <dynamicField name="*_b"  type="boolean" indexed="true"  stored="true"/>
-   <dynamicField name="*_f"  type="sfloat"  indexed="true"  stored="true"/>
-   <dynamicField name="*_d"  type="sdouble" indexed="true"  stored="true"/>
-   <dynamicField name="*_dt" type="date"    indexed="true"  stored="true"/>
+   <dynamicField name="*_i"       type="sint"    indexed="true"  stored="true"/>
+   <dynamicField name="*_s"       type="string"  indexed="true"  stored="true"/>
+   <dynamicField name="*_mult_s"  type="string"  indexed="true"  stored="true"   multiValued="true"/>
+   <dynamicField name="*_l"       type="slong"   indexed="true"  stored="true"/>
+   <dynamicField name="*_t"       type="text"    indexed="true"  stored="true"/>
+   <dynamicField name="*_b"       type="boolean" indexed="true"  stored="true"/>
+   <dynamicField name="*_f"       type="sfloat"  indexed="true"  stored="true"/>
+   <dynamicField name="*_d"       type="sdouble" indexed="true"  stored="true"/>
+   <dynamicField name="*_dt"      type="date"    indexed="true"  stored="true"/>
 
    <dynamicField name="random*" type="random" />
 

Modified: lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestCachedSqlEntityProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestCachedSqlEntityProcessor.java?rev=1201715&r1=1201714&r2=1201715&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestCachedSqlEntityProcessor.java
(original)
+++ lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestCachedSqlEntityProcessor.java
Mon Nov 14 14:15:19 2011
@@ -190,7 +190,7 @@ public class TestCachedSqlEntityProcesso
     fields.add(createMap("column", "desc"));
     String q = "select * from x";
     Map<String, String> entityAttrs = createMap(
-            "query", q, EntityProcessorBase.CACHE_KEY,"id", EntityProcessorBase.CACHE_LOOKUP
,"x.id");
+        "query", q, DIHCacheSupport.CACHE_PRIMARY_KEY,"id", DIHCacheSupport.CACHE_FOREIGN_KEY
,"x.id");
     MockDataSource ds = new MockDataSource();
     VariableResolverImpl vr = new VariableResolverImpl();
     Map xNamespace = createMap("id", 0);

Modified: lucene/dev/branches/lucene2621/solr/core/src/test-files/solr/conf/schema-numeric.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/solr/core/src/test-files/solr/conf/schema-numeric.xml?rev=1201715&r1=1201714&r2=1201715&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/solr/core/src/test-files/solr/conf/schema-numeric.xml (original)
+++ lucene/dev/branches/lucene2621/solr/core/src/test-files/solr/conf/schema-numeric.xml Mon
Nov 14 14:15:19 2011
@@ -35,36 +35,42 @@
     <fieldType name="int"          class="solr.TrieIntField"    precisionStep="0" sortMissingLast="false"
omitNorms="true" positionIncrementGap="0"/>
     <fieldType name="float"        class="solr.TrieFloatField"  precisionStep="0" sortMissingLast="false"
omitNorms="true" positionIncrementGap="0"/>
     <fieldType name="long"         class="solr.TrieLongField"   precisionStep="0" sortMissingLast="false"
omitNorms="true" positionIncrementGap="0"/>
-    <fieldType name="double"       class="solr.TrieDoubleField" precisionStep="0" sortMissingLast="false"
omitNorms="true" positionIncrementGap="0"/>  
+    <fieldType name="date"         class="solr.TrieDateField"   precisionStep="0" sortMissingLast="false"
omitNorms="true" positionIncrementGap="0"/>
+    <fieldType name="double"       class="solr.TrieDoubleField" precisionStep="0" sortMissingLast="false"
omitNorms="true" positionIncrementGap="0"/>
 
     <fieldType name="int_last"     class="solr.TrieIntField"    precisionStep="0" sortMissingLast="true"
omitNorms="true" positionIncrementGap="0"/>
     <fieldType name="float_last"   class="solr.TrieFloatField"  precisionStep="0" sortMissingLast="true"
omitNorms="true" positionIncrementGap="0"/>
     <fieldType name="long_last"    class="solr.TrieLongField"   precisionStep="0" sortMissingLast="true"
omitNorms="true" positionIncrementGap="0"/>
-    <fieldType name="double_last"  class="solr.TrieDoubleField" precisionStep="0" sortMissingLast="true"
omitNorms="true" positionIncrementGap="0"/>  
+    <fieldType name="date_last"    class="solr.TrieDateField"   precisionStep="0" sortMissingLast="true"
omitNorms="true" positionIncrementGap="0"/>
+    <fieldType name="double_last"  class="solr.TrieDoubleField" precisionStep="0" sortMissingLast="true"
omitNorms="true" positionIncrementGap="0"/>
 
     <fieldType name="int_first"    class="solr.TrieIntField"    precisionStep="0" sortMissingFirst="true"
omitNorms="true" positionIncrementGap="0"/>
     <fieldType name="float_first"  class="solr.TrieFloatField"  precisionStep="0" sortMissingFirst="true"
omitNorms="true" positionIncrementGap="0"/>
     <fieldType name="long_first"   class="solr.TrieLongField"   precisionStep="0" sortMissingFirst="true"
omitNorms="true" positionIncrementGap="0"/>
-    <fieldType name="double_first" class="solr.TrieDoubleField" precisionStep="0" sortMissingFirst="true"
omitNorms="true" positionIncrementGap="0"/>  
+    <fieldType name="date_first"   class="solr.TrieDateField"   precisionStep="0" sortMissingFirst="true"
omitNorms="true" positionIncrementGap="0"/>
+    <fieldType name="double_first" class="solr.TrieDoubleField" precisionStep="0" sortMissingFirst="true"
omitNorms="true" positionIncrementGap="0"/>
 
   </types>
-  
+
   <fields>
     <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/>
-    
+
     <field name="int"          type="int"          indexed="true" stored="true" multiValued="false"/>
     <field name="float"        type="float"        indexed="true" stored="true" multiValued="false"/>
     <field name="long"         type="long"         indexed="true" stored="true" multiValued="false"/>
+    <field name="date"         type="date"         indexed="true" stored="true" multiValued="false"/>
     <field name="double"       type="double"       indexed="true" stored="true" multiValued="false"/>
-   
+
     <field name="int_last"     type="int_last"     indexed="true" stored="true" multiValued="false"/>
     <field name="float_last"   type="float_last"   indexed="true" stored="true" multiValued="false"/>
     <field name="long_last"    type="long_last"    indexed="true" stored="true" multiValued="false"/>
+    <field name="date_last"    type="date_last"    indexed="true" stored="true" multiValued="false"/>
     <field name="double_last"  type="double_last"  indexed="true" stored="true" multiValued="false"/>
-   
+
     <field name="int_first"    type="int_first"    indexed="true" stored="true" multiValued="false"/>
     <field name="float_first"  type="float_first"  indexed="true" stored="true" multiValued="false"/>
     <field name="long_first"   type="long_first"   indexed="true" stored="true" multiValued="false"/>
+    <field name="date_first"   type="date_first"   indexed="true" stored="true" multiValued="false"/>
     <field name="double_first" type="double_first" indexed="true" stored="true" multiValued="false"/>
    
   </fields>

Modified: lucene/dev/branches/lucene2621/solr/core/src/test/org/apache/solr/schema/NumericFieldsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/solr/core/src/test/org/apache/solr/schema/NumericFieldsTest.java?rev=1201715&r1=1201714&r2=1201715&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/solr/core/src/test/org/apache/solr/schema/NumericFieldsTest.java
(original)
+++ lucene/dev/branches/lucene2621/solr/core/src/test/org/apache/solr/schema/NumericFieldsTest.java
Mon Nov 14 14:15:19 2011
@@ -26,107 +26,133 @@ import org.junit.Test;
 public class NumericFieldsTest extends SolrTestCaseJ4 {
   @BeforeClass
   public static void beforeClass() throws Exception {
-    initCore("solrconfig-master.xml","schema-numeric.xml");
-  }    
-  
-  static String[] types = new String[] { "int", "long", "float", "double" };
-  
-  public static SolrInputDocument getDoc( String id, Integer number )
-  {
+    initCore("solrconfig-master.xml", "schema-numeric.xml");
+  }
+
+  static String[] types = new String[]{"int", "long", "float", "double", "date"};
+
+  public static SolrInputDocument getDoc(String id, Integer number, String date) {
     SolrInputDocument doc = new SolrInputDocument();
-    doc.addField( "id", id );
-    for( String t : types ) {
-      doc.addField( t, number );
-      doc.addField( t+"_last", number );
-      doc.addField( t+"_first", number );
+    doc.addField("id", id);
+    for (String t : types) {
+      if ("date".equals(t)) {
+        doc.addField(t, date);
+        doc.addField(t + "_last", date);
+        doc.addField(t + "_first", date);
+      } else {
+        doc.addField(t, number);
+        doc.addField(t + "_last", number);
+        doc.addField(t + "_first", number);
+      }
     }
     return doc;
   }
 
   @Test
-  public void testSortMissingFirstLast() 
-  {
+  public void testSortMissingFirstLast() {
     clearIndex();
-    
-    assertU(adoc("id", "M1" ));
-    assertU(adoc( getDoc( "+4",  4 ) ));
-    assertU(adoc( getDoc( "+5",  5 ) ));
-    assertU(adoc( getDoc( "-3", -3 ) ));
-    assertU(adoc("id", "M2" ));
-    assertU(commit());
 
+    assertU(adoc("id", "M1"));
+    assertU(adoc(getDoc("+4", 4, "2011-04-04T00:00:00Z")));
+    assertU(adoc(getDoc("+5", 5, "2011-05-05T00:00:00Z")));
+    assertU(adoc(getDoc("-3", -3, "2011-01-01T00:00:00Z")));
+    assertU(adoc("id", "M2"));
+    assertU(commit());
     // 'normal' sorting.  Missing Values are 0
     String suffix = "";
-    for( String t : types ) {
-      assertQ( "Sorting Asc: "+t+suffix,
-          req("fl", "id", "q", "*:*", "sort", (t+suffix)+" asc" ),
-              "//*[@numFound='5']",
-              "//result/doc[1]/str[@name='id'][.='-3']",
-              "//result/doc[2]/str[@name='id'][.='M1']",
-              "//result/doc[3]/str[@name='id'][.='M2']",
-              "//result/doc[4]/str[@name='id'][.='+4']",
-              "//result/doc[5]/str[@name='id'][.='+5']"
-      );
-      
-      assertQ( "Sorting Desc: "+t+suffix,
-          req("fl", "id", "q", "*:*", "sort", (t+suffix)+" desc" ),
-              "//*[@numFound='5']",
-              "//result/doc[1]/str[@name='id'][.='+5']",
-              "//result/doc[2]/str[@name='id'][.='+4']",
-              "//result/doc[3]/str[@name='id'][.='M1']",
-              "//result/doc[4]/str[@name='id'][.='M2']",
-              "//result/doc[5]/str[@name='id'][.='-3']"
-      );
+    for (String t : types) {
+      if ("date".equals(t)) {
+        assertQ("Sorting Asc: " + t + suffix,
+            req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc"),
+            "//*[@numFound='5']",
+            "//result/doc[1]/str[@name='id'][.='M1']",
+            "//result/doc[2]/str[@name='id'][.='M2']",
+            "//result/doc[3]/str[@name='id'][.='-3']",
+            "//result/doc[4]/str[@name='id'][.='+4']",
+            "//result/doc[5]/str[@name='id'][.='+5']"
+        );
+
+        assertQ("Sorting Desc: " + t + suffix,
+            req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc"),
+            "//*[@numFound='5']",
+            "//result/doc[1]/str[@name='id'][.='+5']",
+            "//result/doc[2]/str[@name='id'][.='+4']",
+            "//result/doc[3]/str[@name='id'][.='-3']",
+            "//result/doc[4]/str[@name='id'][.='M1']",
+            "//result/doc[5]/str[@name='id'][.='M2']"
+        );
+      } else {
+        assertQ("Sorting Asc: " + t + suffix,
+            req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc"),
+            "//*[@numFound='5']",
+            "//result/doc[1]/str[@name='id'][.='-3']",
+            "//result/doc[2]/str[@name='id'][.='M1']",
+            "//result/doc[3]/str[@name='id'][.='M2']",
+            "//result/doc[4]/str[@name='id'][.='+4']",
+            "//result/doc[5]/str[@name='id'][.='+5']"
+        );
+
+        assertQ("Sorting Desc: " + t + suffix,
+            req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc"),
+            "//*[@numFound='5']",
+            "//result/doc[1]/str[@name='id'][.='+5']",
+            "//result/doc[2]/str[@name='id'][.='+4']",
+            "//result/doc[3]/str[@name='id'][.='M1']",
+            "//result/doc[4]/str[@name='id'][.='M2']",
+            "//result/doc[5]/str[@name='id'][.='-3']"
+        );
+
+      }
     }
-    
-    
-    // sortMissingLast = true 
+
+
+    // sortMissingLast = true
     suffix = "_last";
-    for( String t : types ) {
-      assertQ( "Sorting Asc: "+t+suffix,
-          req("fl", "id", "q", "*:*", "sort", (t+suffix)+" asc" ),
-              "//*[@numFound='5']",
-              "//result/doc[1]/str[@name='id'][.='-3']",
-              "//result/doc[2]/str[@name='id'][.='+4']",
-              "//result/doc[3]/str[@name='id'][.='+5']",
-              "//result/doc[4]/str[@name='id'][.='M1']",
-              "//result/doc[5]/str[@name='id'][.='M2']"
+    for (String t : types) {
+      assertQ("Sorting Asc: " + t + suffix,
+          req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc"),
+          "//*[@numFound='5']",
+          "//result/doc[1]/str[@name='id'][.='-3']",
+          "//result/doc[2]/str[@name='id'][.='+4']",
+          "//result/doc[3]/str[@name='id'][.='+5']",
+          "//result/doc[4]/str[@name='id'][.='M1']",
+          "//result/doc[5]/str[@name='id'][.='M2']"
       );
-      
+
       // This does not match
-      assertQ( "Sorting Desc: "+t+suffix,
-          req("fl", "id", "q", "*:*", "sort", (t+suffix)+" desc", "indent", "on" ),
-              "//*[@numFound='5']",
-              "//result/doc[1]/str[@name='id'][.='+5']",
-              "//result/doc[2]/str[@name='id'][.='+4']",
-              "//result/doc[3]/str[@name='id'][.='-3']",
-              "//result/doc[4]/str[@name='id'][.='M1']",
-              "//result/doc[5]/str[@name='id'][.='M2']"
+      assertQ("Sorting Desc: " + t + suffix,
+          req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc", "indent", "on"),
+          "//*[@numFound='5']",
+          "//result/doc[1]/str[@name='id'][.='+5']",
+          "//result/doc[2]/str[@name='id'][.='+4']",
+          "//result/doc[3]/str[@name='id'][.='-3']",
+          "//result/doc[4]/str[@name='id'][.='M1']",
+          "//result/doc[5]/str[@name='id'][.='M2']"
       );
     }
 
-    // sortMissingFirst = true 
+    // sortMissingFirst = true
     suffix = "_first";
-    for( String t : types ) {
-      assertQ( "Sorting Asc: "+t+suffix,
-          req("fl", "id", "q", "*:*", "sort", (t+suffix)+" asc", "indent", "on" ),
-              "//*[@numFound='5']",
-              "//result/doc[1]/str[@name='id'][.='M1']",
-              "//result/doc[2]/str[@name='id'][.='M2']",
-              "//result/doc[3]/str[@name='id'][.='-3']",
-              "//result/doc[4]/str[@name='id'][.='+4']",
-              "//result/doc[5]/str[@name='id'][.='+5']"
+    for (String t : types) {
+      assertQ("Sorting Asc: " + t + suffix,
+          req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc", "indent", "on"),
+          "//*[@numFound='5']",
+          "//result/doc[1]/str[@name='id'][.='M1']",
+          "//result/doc[2]/str[@name='id'][.='M2']",
+          "//result/doc[3]/str[@name='id'][.='-3']",
+          "//result/doc[4]/str[@name='id'][.='+4']",
+          "//result/doc[5]/str[@name='id'][.='+5']"
       );
-      
+
       // This does not match
-      assertQ( "Sorting Desc: "+t+suffix,
-          req("fl", "id", "q", "*:*", "sort", (t+suffix)+" desc", "indent", "on" ),
-              "//*[@numFound='5']",
-              "//result/doc[1]/str[@name='id'][.='M1']",
-              "//result/doc[2]/str[@name='id'][.='M2']",
-              "//result/doc[3]/str[@name='id'][.='+5']",
-              "//result/doc[4]/str[@name='id'][.='+4']",
-              "//result/doc[5]/str[@name='id'][.='-3']"
+      assertQ("Sorting Desc: " + t + suffix,
+          req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc", "indent", "on"),
+          "//*[@numFound='5']",
+          "//result/doc[1]/str[@name='id'][.='M1']",
+          "//result/doc[2]/str[@name='id'][.='M2']",
+          "//result/doc[3]/str[@name='id'][.='+5']",
+          "//result/doc[4]/str[@name='id'][.='+4']",
+          "//result/doc[5]/str[@name='id'][.='-3']"
       );
     }
   }

Modified: lucene/dev/branches/lucene2621/solr/example/solr/conf/schema.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/solr/example/solr/conf/schema.xml?rev=1201715&r1=1201714&r2=1201715&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/solr/example/solr/conf/schema.xml (original)
+++ lucene/dev/branches/lucene2621/solr/example/solr/conf/schema.xml Mon Nov 14 14:15:19 2011
@@ -74,8 +74,11 @@
     <!--Binary data type. The data should be sent/retrieved in as Base64 encoded Strings
-->
     <fieldtype name="binary" class="solr.BinaryField"/>
 
-    <!--  sortMissingLast and sortMissingFirst attributes are optional attributes
-          that control how fields are sorted when values are missing.
+    <!-- sortMissingLast and sortMissingFirst attributes are optional attributes are
+         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).
@@ -141,7 +144,8 @@
     <!--
       Note:
       These should only be used for compatibility with existing indexes (created with lucene
or older Solr versions).
-
+      Use Trie based fields instead. As of Solr 3.5 and 4.x, Trie based fields support sortMissingFirst/Last
+      
       Plain numeric field types that store and index the text
       value verbatim (and hence don't correctly support range queries, since the
       lexicographic ordering isn't equal to the numeric ordering)



Mime
View raw message