lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hoss...@apache.org
Subject svn commit: r1387825 - in /lucene/dev/branches/branch_4x: ./ dev-tools/ lucene/ lucene/analysis/ lucene/analysis/icu/src/java/org/apache/lucene/collation/ lucene/backwards/ lucene/benchmark/ lucene/codecs/ lucene/core/ lucene/demo/ lucene/facet/ lucene...
Date Thu, 20 Sep 2012 00:21:29 GMT
Author: hossman
Date: Thu Sep 20 00:21:27 2012
New Revision: 1387825

URL: http://svn.apache.org/viewvc?rev=1387825&view=rev
Log:
SOLR-3783: Fixed Pivot Faceting to work with facet.missing=true (merge r1387824)

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/dev-tools/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/BUILD.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/CHANGES.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/JRE_VERSION_MIGRATION.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/LICENSE.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/MIGRATE.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/README.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/analysis/   (props changed)
    lucene/dev/branches/branch_4x/lucene/analysis/icu/src/java/org/apache/lucene/collation/ICUCollationKeyFilterFactory.java
  (props changed)
    lucene/dev/branches/branch_4x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_4x/lucene/benchmark/   (props changed)
    lucene/dev/branches/branch_4x/lucene/build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/codecs/   (props changed)
    lucene/dev/branches/branch_4x/lucene/common-build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/demo/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/   (props changed)
    lucene/dev/branches/branch_4x/lucene/grouping/   (props changed)
    lucene/dev/branches/branch_4x/lucene/highlighter/   (props changed)
    lucene/dev/branches/branch_4x/lucene/ivy-settings.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/join/   (props changed)
    lucene/dev/branches/branch_4x/lucene/licenses/   (props changed)
    lucene/dev/branches/branch_4x/lucene/memory/   (props changed)
    lucene/dev/branches/branch_4x/lucene/misc/   (props changed)
    lucene/dev/branches/branch_4x/lucene/module-build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/queries/   (props changed)
    lucene/dev/branches/branch_4x/lucene/queryparser/   (props changed)
    lucene/dev/branches/branch_4x/lucene/sandbox/   (props changed)
    lucene/dev/branches/branch_4x/lucene/site/   (props changed)
    lucene/dev/branches/branch_4x/lucene/spatial/   (props changed)
    lucene/dev/branches/branch_4x/lucene/suggest/   (props changed)
    lucene/dev/branches/branch_4x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/lucene/tools/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/LICENSE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/README.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/build.xml   (props changed)
    lucene/dev/branches/branch_4x/solr/cloud-dev/   (props changed)
    lucene/dev/branches/branch_4x/solr/common-build.xml   (props changed)
    lucene/dev/branches/branch_4x/solr/contrib/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java
    lucene/dev/branches/branch_4x/solr/dev-tools/   (props changed)
    lucene/dev/branches/branch_4x/solr/example/   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpclient-LICENSE-ASL.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpclient-NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpcore-LICENSE-ASL.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpcore-NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpmime-LICENSE-ASL.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpmime-NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/scripts/   (props changed)
    lucene/dev/branches/branch_4x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
    lucene/dev/branches/branch_4x/solr/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/solr/testlogging.properties   (props changed)
    lucene/dev/branches/branch_4x/solr/webapp/   (props changed)

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1387825&r1=1387824&r2=1387825&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Thu Sep 20 00:21:27 2012
@@ -249,6 +249,8 @@ Bug Fixes
   fixes some bugs related to xinclude and fieldTypes.
   (Amit Nithian, hossman)
 
+* SOLR-3783: Fixed Pivot Faceting to work with facet.missing=true (hossman)
+
 Other Changes
 ----------------------
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java?rev=1387825&r1=1387824&r2=1387825&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java
Thu Sep 20 00:21:27 2012
@@ -32,6 +32,7 @@ import org.apache.solr.request.SolrQuery
 import org.apache.solr.schema.FieldType;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.index.Term;
 
 import java.io.IOException;
@@ -103,22 +104,38 @@ public class PivotFacetHelper
     for (Map.Entry<String, Integer> kv : superFacets) {
       // Only sub-facet if parent facet has positive count - still may not be any values
for the sub-field though
       if (kv.getValue() >= minMatch ) {
-        // don't reuse the same BytesRef  each time since we will be constructing Term
-        // objects that will most likely be cached.
-        BytesRef termval = new BytesRef();
-        ftype.readableToIndexed(kv.getKey(), termval);
-        
+
+        // may be null when using facet.missing
+        final String fieldValue = kv.getKey(); 
+
+        // don't reuse the same BytesRef each time since we will be 
+        // constructing Term objects used in TermQueries that may be cached.
+        BytesRef termval = null;
+
         SimpleOrderedMap<Object> pivot = new SimpleOrderedMap<Object>();
         pivot.add( "field", field );
-        pivot.add( "value", ftype.toObject(sfield, termval) );
+        if (null == fieldValue) {
+          pivot.add( "value", null );
+        } else {
+          termval = new BytesRef();
+          ftype.readableToIndexed(fieldValue, termval);
+          pivot.add( "value", ftype.toObject(sfield, termval) );
+        }
         pivot.add( "count", kv.getValue() );
         
         if( subField == null ) {
           values.add( pivot );
         }
         else {
-          Query query = new TermQuery(new Term(field, termval));
-          DocSet subset = searcher.getDocSet(query, docs);
+          DocSet subset = null;
+          if ( null == termval ) {
+            DocSet hasVal = searcher.getDocSet
+              (new TermRangeQuery(field, null, null, false, false));
+            subset = docs.andNot(hasVal);
+          } else {
+            Query query = new TermQuery(new Term(field, termval));
+            subset = searcher.getDocSet(query, docs);
+          }
           SimpleFacets sf = getFacetImplementation(rb.req, subset, rb.req.getParams());
           
           NamedList<Integer> nl = sf.getTermCounts(subField);
@@ -134,6 +151,7 @@ public class PivotFacetHelper
     fnames.push( nextField );
     return values;
   }
+
 // TODO: This is code from various patches to support distributed search.
 //  Some parts may be helpful for whoever implements distributed search.
 //

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java?rev=1387825&r1=1387824&r2=1387825&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
(original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
Thu Sep 20 00:21:27 2012
@@ -939,8 +939,15 @@ abstract public class SolrExampleTests e
   }
 
   @Test
-  public void testPivotFacet() throws Exception
-  {    
+  public void testPivotFacets() throws Exception {
+    doPivotFacetTest(false);
+  }
+    
+  public void testPivotFacetsMissing() throws Exception {
+    doPivotFacetTest(true);
+  }
+    
+  private void doPivotFacetTest(boolean missing) throws Exception {
     SolrServer server = getSolrServer();
     
     // Empty the database...
@@ -961,13 +968,14 @@ abstract public class SolrExampleTests e
     docs.add( makeTestDoc( "id", id++, "features", "bbb",  "cat", "b", "inStock", true )
);
     docs.add( makeTestDoc( "id", id++, "features", "bbb",  "cat", "b", "inStock", false )
);
     docs.add( makeTestDoc( "id", id++, "features", "bbb",  "cat", "b", "inStock", true )
);
-    docs.add( makeTestDoc( "id", id++ ) ); // something not matching
+    docs.add( makeTestDoc( "id", id++,  "cat", "b" ) ); // something not matching all fields
     server.add( docs );
     server.commit();
     
     SolrQuery query = new SolrQuery( "*:*" );
     query.addFacetPivotField("features,cat", "cat,features", "features,cat,inStock" );
     query.setFacetMinCount( 0 );
+    query.setFacetMissing( missing );
     query.setRows( 0 );
     
     QueryResponse rsp = server.query( query );
@@ -991,10 +999,12 @@ abstract public class SolrExampleTests e
     //  features=aaa (5)
     //    cat=a (3)
     //    cat=b (2)
-    
-    List<PivotField> pivot = pivots.getVal( 0 );
+    //  features missing (1)
+    //    cat=b (1)
+
     assertEquals( "features,cat", pivots.getName( 0 ) );
-    assertEquals( 2, pivot.size() );
+    List<PivotField> pivot = pivots.getVal( 0 );
+    assertEquals( missing ? 3 : 2, pivot.size() );
     
     PivotField ff = pivot.get( 0 );
     assertEquals( "features", ff.getField() );
@@ -1007,27 +1017,72 @@ abstract public class SolrExampleTests e
     assertEquals(   4, counts.get(0).getCount() );
     assertEquals( "a", counts.get(1).getValue() );
     assertEquals(   2, counts.get(1).getCount() );
-    
 
-    //  PIVOT: cat,features
-    //  cat=b (6)
-    //    features=bbb (4)
-    //    features=aaa (2)
-    //  cat=a (5)
-    //    features=aaa (3)
-    //    features=bbb (2)
-    
     ff = pivot.get( 1 );
     assertEquals( "features", ff.getField() );
     assertEquals( "aaa", ff.getValue() );
     assertEquals( 5, ff.getCount() );
     counts = ff.getPivot();
     assertEquals( 2, counts.size() );
+    assertEquals( "cat", counts.get(0).getField() );
     assertEquals( "a", counts.get(0).getValue() );
     assertEquals(   3, counts.get(0).getCount() );
     assertEquals( "b", counts.get(1).getValue() );
     assertEquals(   2, counts.get(1).getCount() );
-    
+
+    if (missing) {
+      ff = pivot.get( 2 );
+      assertEquals( "features", ff.getField() );
+      assertEquals( null, ff.getValue() );
+      assertEquals( 1, ff.getCount() );
+      counts = ff.getPivot();
+      assertEquals( 1, counts.size() );
+      assertEquals( "cat", counts.get(0).getField() );
+      assertEquals( "b", counts.get(0).getValue() );
+      assertEquals( 1, counts.get(0).getCount() );
+    }
+
+    //  PIVOT: cat,features
+    //  cat=b (7)
+    //    features=bbb (4)
+    //    features=aaa (2)
+    //    features missing (1)
+    //  cat=a (5)
+    //    features=aaa (3)
+    //    features=bbb (2)
+
+    assertEquals( "cat,features", pivots.getName( 1 ) );
+    pivot = pivots.getVal( 1 );
+    assertEquals( 2, pivot.size() );
+
+    ff = pivot.get( 0 );
+    assertEquals( "cat", ff.getField() );
+    assertEquals( "b", ff.getValue() );
+    assertEquals( 7, ff.getCount() );
+    counts = ff.getPivot();
+    assertEquals( missing ? 3 : 2, counts.size() );
+    assertEquals( "features", counts.get(0).getField() );
+    assertEquals( "bbb", counts.get(0).getValue() );
+    assertEquals( 4, counts.get(0).getCount() );
+    assertEquals( "aaa", counts.get(1).getValue() );
+    assertEquals( 2, counts.get(1).getCount() );
+    if ( missing ) {
+      assertEquals( null, counts.get(2).getValue() );
+      assertEquals( 1, counts.get(2).getCount() );
+    }
+
+    ff = pivot.get( 1 );
+    assertEquals( "cat", ff.getField() );
+    assertEquals( "a", ff.getValue() );
+    assertEquals( 5, ff.getCount() );
+    counts = ff.getPivot();
+    assertEquals( 2, counts.size() );
+    assertEquals( "features", counts.get(0).getField() );
+    assertEquals( "aaa", counts.get(0).getValue() );
+    assertEquals( 3, counts.get(0).getCount() );
+    assertEquals( "bbb", counts.get(1).getValue() );
+    assertEquals( 2, counts.get(1).getCount() );
+
     // Three deep:
     //  PIVOT: features,cat,inStock
     //  features=bbb (6)
@@ -1044,10 +1099,13 @@ abstract public class SolrExampleTests e
     //    cat=b (2)
     //      inStock=false (1)
     //      inStock=true (1)
-    
-    pivot = pivots.getVal( 2 );
+    //  features missing (1)
+    //    cat=b (1)
+    //      inStock missing (1)
+
     assertEquals( "features,cat,inStock", pivots.getName( 2 ) );
-    assertEquals( 2, pivot.size() );
+    pivot = pivots.getVal( 2 );
+    assertEquals( missing ? 3 : 2, pivot.size() );
     PivotField p = pivot.get( 1 ).getPivot().get(0);     // get(1) should be features=AAAA,
then get(0) should be cat=a
     assertEquals( "cat", p.getField() );
     assertEquals( "a", p.getValue() );
@@ -1057,6 +1115,25 @@ abstract public class SolrExampleTests e
     assertEquals( "inStock",    counts.get(0).getField() );
     assertEquals( Boolean.TRUE, counts.get(0).getValue() );
     assertEquals(  2,           counts.get(0).getCount() );
+
+    if (missing) {
+      p = pivot.get( 2 );
+      assertEquals( "features", p.getField() );
+      assertEquals( null, p.getValue() );
+      assertEquals( 1, p.getCount() );
+      assertEquals( 1, p.getPivot().size() );
+      p = p.getPivot().get(0);
+      assertEquals( "cat", p.getField() );
+      assertEquals( "b", p.getValue() );
+      assertEquals( 1, p.getCount() );
+      assertEquals( 1, p.getPivot().size() );
+      p = p.getPivot().get(0);
+      assertEquals( "inStock", p.getField() );
+      assertEquals( null, p.getValue() );
+      assertEquals( 1, p.getCount() );
+      assertEquals( null, p.getPivot() );
+    }
+
   }
   
   public static SolrInputDocument makeTestDoc( Object ... kvp )



Mime
View raw message