You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/03/17 20:34:37 UTC

svn commit: r1578529 - in /lucene/dev/branches/lucene_solr_4_7: ./ lucene/ lucene/demo/ lucene/demo/src/java/org/apache/lucene/demo/facet/ lucene/demo/src/test/org/apache/lucene/demo/facet/ lucene/facet/ lucene/facet/src/java/org/apache/lucene/facet/ l...

Author: mikemccand
Date: Mon Mar 17 19:34:37 2014
New Revision: 1578529

URL: http://svn.apache.org/r1578529
Log:
LUCENE-5522: backport to 4.7.x

Modified:
    lucene/dev/branches/lucene_solr_4_7/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/demo/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/java/org/apache/lucene/demo/facet/AssociationsFacetsExample.java
    lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/test/org/apache/lucene/demo/facet/TestAssociationsFacetsExample.java
    lucene/dev/branches/lucene_solr_4_7/lucene/facet/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
    lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetAssociations.java

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/CHANGES.txt?rev=1578529&r1=1578528&r2=1578529&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/CHANGES.txt Mon Mar 17 19:34:37 2014
@@ -29,6 +29,9 @@ Bug Fixes
 
 * LUCENE-5502: Fixed TermsFilter.equals that could return true for different
   filters. (Igor Motov via Adrien Grand)
+  
+* LUCENE-5522: FacetsConfig didn't add drill-down terms for association facet 
+  fields labels. (Shai Erera)
 
 * LUCENE-5520: ToChildBlockJoinQuery would hit
   ArrayIndexOutOfBoundsException if a parent document had no children

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/java/org/apache/lucene/demo/facet/AssociationsFacetsExample.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/java/org/apache/lucene/demo/facet/AssociationsFacetsExample.java?rev=1578529&r1=1578528&r2=1578529&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/java/org/apache/lucene/demo/facet/AssociationsFacetsExample.java (original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/java/org/apache/lucene/demo/facet/AssociationsFacetsExample.java Mon Mar 17 19:34:37 2014
@@ -23,6 +23,7 @@ import java.util.List;
 
 import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
 import org.apache.lucene.document.Document;
+import org.apache.lucene.facet.DrillDownQuery;
 import org.apache.lucene.facet.FacetResult;
 import org.apache.lucene.facet.Facets;
 import org.apache.lucene.facet.FacetsCollector;
@@ -116,12 +117,43 @@ public class AssociationsFacetsExample {
     return results;
   }
   
+  /** User drills down on 'tags/solr'. */
+  private FacetResult drillDown() throws IOException {
+    DirectoryReader indexReader = DirectoryReader.open(indexDir);
+    IndexSearcher searcher = new IndexSearcher(indexReader);
+    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
+
+    // Passing no baseQuery means we drill down on all
+    // documents ("browse only"):
+    DrillDownQuery q = new DrillDownQuery(config);
+
+    // Now user drills down on Publish Date/2010:
+    q.add("tags", "solr");
+    FacetsCollector fc = new FacetsCollector();
+    FacetsCollector.search(searcher, q, 10, fc);
+
+    // Retrieve results
+    Facets facets = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc);
+    FacetResult result = facets.getTopChildren(10, "genre");
+
+    indexReader.close();
+    taxoReader.close();
+    
+    return result;
+  }
+  
   /** Runs summing association example. */
   public List<FacetResult> runSumAssociations() throws IOException {
     index();
     return sumAssociations();
   }
   
+  /** Runs the drill-down example. */
+  public FacetResult runDrillDown() throws IOException {
+    index();
+    return drillDown();
+  }
+
   /** Runs the sum int/float associations examples and prints the results. */
   public static void main(String[] args) throws Exception {
     System.out.println("Sum associations example:");

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/test/org/apache/lucene/demo/facet/TestAssociationsFacetsExample.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/test/org/apache/lucene/demo/facet/TestAssociationsFacetsExample.java?rev=1578529&r1=1578528&r2=1578529&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/test/org/apache/lucene/demo/facet/TestAssociationsFacetsExample.java (original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/test/org/apache/lucene/demo/facet/TestAssociationsFacetsExample.java Mon Mar 17 19:34:37 2014
@@ -34,4 +34,11 @@ public class TestAssociationsFacetsExamp
     assertEquals("dim=tags path=[] value=-1 childCount=2\n  lucene (4)\n  solr (2)\n", res.get(0).toString());
     assertEquals("dim=genre path=[] value=-1.0 childCount=2\n  computing (1.62)\n  software (0.34)\n", res.get(1).toString());
   }  
+
+  @Test
+  public void testDrillDown() throws Exception {
+    FacetResult result = new AssociationsFacetsExample().runDrillDown();
+    assertEquals("dim=genre path=[] value=-1.0 childCount=2\n  computing (0.75)\n  software (0.34)\n", result.toString());
+  }
+  
 }

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java?rev=1578529&r1=1578528&r2=1578529&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java (original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java Mon Mar 17 19:34:37 2014
@@ -389,6 +389,12 @@ public class FacetsConfig {
         }
         System.arraycopy(field.assoc.bytes, field.assoc.offset, bytes, upto, field.assoc.length);
         upto += field.assoc.length;
+        
+        // Drill down:
+        FacetLabel cp = new FacetLabel(field.dim, field.path);
+        for (int i = 1; i <= cp.length; i++) {
+          doc.add(new StringField(indexFieldName, pathToString(cp.components, i), Field.Store.NO));
+        }
       }
       doc.add(new BinaryDocValuesField(indexFieldName, new BytesRef(bytes, 0, upto)));
     }

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetAssociations.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetAssociations.java?rev=1578529&r1=1578528&r2=1578529&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetAssociations.java (original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetAssociations.java Mon Mar 17 19:34:37 2014
@@ -19,6 +19,7 @@ package org.apache.lucene.facet.taxonomy
 
 
 import org.apache.lucene.document.Document;
+import org.apache.lucene.facet.DrillDownQuery;
 import org.apache.lucene.facet.FacetTestCase;
 import org.apache.lucene.facet.Facets;
 import org.apache.lucene.facet.FacetsCollector;
@@ -223,4 +224,19 @@ public class TestTaxonomyFacetAssociatio
     }
     IOUtils.close(writer, taxoWriter, dir, taxoDir);
   }
+  
+  public void testIntSumAssociationDrillDown() throws Exception {
+    FacetsCollector fc = new FacetsCollector();
+    
+    IndexSearcher searcher = newSearcher(reader);
+    DrillDownQuery q = new DrillDownQuery(config);
+    q.add("int", "b");
+    searcher.search(q, fc);
+
+    Facets facets = new TaxonomyFacetSumIntAssociations("$facets.int", taxoReader, config, fc);
+    assertEquals("dim=int path=[] value=-1 childCount=2\n  b (150)\n  a (100)\n", facets.getTopChildren(10, "int").toString());
+    assertEquals("Wrong count for category 'a'!", 100, facets.getSpecificValue("int", "a").intValue());
+    assertEquals("Wrong count for category 'b'!", 150, facets.getSpecificValue("int", "b").intValue());
+  }
+
 }