lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1578530 - 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...
Date Mon, 17 Mar 2014 19:38:53 GMT
Author: mikemccand
Date: Mon Mar 17 19:38:53 2014
New Revision: 1578530

URL: http://svn.apache.org/r1578530
Log:
LUCENE-5525: 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/SimpleFacetsExample.java
    lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/test/org/apache/lucene/demo/facet/TestSimpleFacetsExample.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/MultiFacets.java
    lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.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=1578530&r1=1578529&r2=1578530&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:38:53 2014
@@ -39,6 +39,10 @@ Bug Fixes
 
 * LUCENE-5532: AutomatonQuery.hashCode was not thread-safe. (Robert Muir)
 
+* LUCENE-5525: Implement MultiFacets.getAllDims, so you can do sparse
+  facets through DrillSideways, for example.  (Jose Peleteiro, Mike
+  McCandless)
+
 * LUCENE-5481: IndexWriter.forceMerge used to run a merge even if there was a
   single segment in the index. (Adrien Grand, Mike McCandless)
 

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/java/org/apache/lucene/demo/facet/SimpleFacetsExample.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/java/org/apache/lucene/demo/facet/SimpleFacetsExample.java?rev=1578530&r1=1578529&r2=1578530&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/java/org/apache/lucene/demo/facet/SimpleFacetsExample.java
(original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/java/org/apache/lucene/demo/facet/SimpleFacetsExample.java
Mon Mar 17 19:38:53 2014
@@ -24,6 +24,8 @@ 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.DrillSideways.DrillSidewaysResult;
+import org.apache.lucene.facet.DrillSideways;
 import org.apache.lucene.facet.FacetField;
 import org.apache.lucene.facet.FacetResult;
 import org.apache.lucene.facet.Facets;
@@ -117,7 +119,8 @@ public class SimpleFacetsExample {
     return results;
   }
   
-  /** User drills down on 'Publish Date/2010'. */
+  /** User drills down on 'Publish Date/2010', and we
+   *  return facets for 'Author' */
   private FacetResult drillDown() throws IOException {
     DirectoryReader indexReader = DirectoryReader.open(indexDir);
     IndexSearcher searcher = new IndexSearcher(indexReader);
@@ -142,6 +145,33 @@ public class SimpleFacetsExample {
     return result;
   }
 
+  /** User drills down on 'Publish Date/2010', and we
+   *  return facets for both 'Publish Date' and 'Author',
+   *  using DrillSideways. */
+  private List<FacetResult> drillSideways() 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("Publish Date", "2010");
+
+    DrillSideways ds = new DrillSideways(searcher, config, taxoReader);
+    DrillSidewaysResult result = ds.search(q, 10);
+
+    // Retrieve results
+    List<FacetResult> facets = result.facets.getAllDims(10);
+
+    indexReader.close();
+    taxoReader.close();
+    
+    return facets;
+  }
+
   /** Runs the search example. */
   public List<FacetResult> runSearch() throws IOException {
     index();
@@ -154,6 +184,12 @@ public class SimpleFacetsExample {
     return drillDown();
   }
 
+  /** Runs the drill-sideways example. */
+  public List<FacetResult> runDrillSideways() throws IOException {
+    index();
+    return drillSideways();
+  }
+
   /** Runs the search and drill-down examples and prints the results. */
   public static void main(String[] args) throws Exception {
     System.out.println("Facet counting example:");
@@ -162,11 +198,17 @@ public class SimpleFacetsExample {
     List<FacetResult> results = example.runSearch();
     System.out.println("Author: " + results.get(0));
     System.out.println("Publish Date: " + results.get(1));
-
     System.out.println("\n");
     System.out.println("Facet drill-down example (Publish Date/2010):");
     System.out.println("---------------------------------------------");
     System.out.println("Author: " + example.runDrillDown());
+
+    System.out.println("\n");
+    System.out.println("Facet drill-sideways example (Publish Date/2010):");
+    System.out.println("---------------------------------------------");
+    for(FacetResult result : example.runDrillSideways()) {
+      System.out.println(result);
+    }
   }
   
 }

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/test/org/apache/lucene/demo/facet/TestSimpleFacetsExample.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/test/org/apache/lucene/demo/facet/TestSimpleFacetsExample.java?rev=1578530&r1=1578529&r2=1578530&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/test/org/apache/lucene/demo/facet/TestSimpleFacetsExample.java
(original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/demo/src/test/org/apache/lucene/demo/facet/TestSimpleFacetsExample.java
Mon Mar 17 19:38:53 2014
@@ -20,7 +20,6 @@ package org.apache.lucene.demo.facet;
 import java.util.List;
 
 import org.apache.lucene.facet.FacetResult;
-import org.apache.lucene.facet.taxonomy.FacetLabel;
 import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
 import org.apache.lucene.util.LuceneTestCase;
 import org.junit.Test;
@@ -41,4 +40,11 @@ public class TestSimpleFacetsExample ext
     FacetResult result = new SimpleFacetsExample().runDrillDown();
     assertEquals("dim=Author path=[] value=2 childCount=2\n  Bob (1)\n  Lisa (1)\n", result.toString());
   }
+
+  @Test
+  public void testDrillSideways() throws Exception {
+    List<FacetResult> result = new SimpleFacetsExample().runDrillSideways();
+    assertEquals("dim=Publish Date path=[] value=5 childCount=3\n  2010 (2)\n  2012 (2)\n
 1999 (1)\n", result.get(0).toString());
+    assertEquals("dim=Author path=[] value=2 childCount=2\n  Bob (1)\n  Lisa (1)\n", result.get(1).toString());
+  }
 }

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/java/org/apache/lucene/facet/MultiFacets.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/java/org/apache/lucene/facet/MultiFacets.java?rev=1578530&r1=1578529&r2=1578530&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/java/org/apache/lucene/facet/MultiFacets.java
(original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/java/org/apache/lucene/facet/MultiFacets.java
Mon Mar 17 19:38:53 2014
@@ -18,6 +18,7 @@ package org.apache.lucene.facet;
  */
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -65,7 +66,25 @@ public class MultiFacets extends Facets 
 
   @Override
   public List<FacetResult> getAllDims(int topN) throws IOException {
-    // TODO
-    throw new UnsupportedOperationException();
+
+    List<FacetResult> results = new ArrayList<FacetResult>();
+
+    // First add the specific dim's facets:
+    for(Map.Entry<String,Facets> ent : dimToFacets.entrySet()) {
+      results.add(ent.getValue().getTopChildren(topN, ent.getKey()));
+    }
+
+    if (defaultFacets != null) {
+
+      // Then add all default facets as long as we didn't
+      // already add that dim:
+      for(FacetResult result : defaultFacets.getAllDims(topN)) {
+        if (dimToFacets.containsKey(result.dim) == false) {
+          results.add(result);
+        }
+      }
+    }
+
+    return results;
   }
 }

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java?rev=1578530&r1=1578529&r2=1578530&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
(original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
Mon Mar 17 19:38:53 2014
@@ -148,7 +148,7 @@ public class TestDrillSideways extends F
     // published once:
     assertEquals("dim=Author path=[] value=5 childCount=4\n  Lisa (2)\n  Bob (1)\n  Susan
(1)\n  Frank (1)\n", r.facets.getTopChildren(10, "Author").toString());
 
-    // Another simple case: drill-down on on single fields
+    // Another simple case: drill-down on single fields
     // but OR of two values
     ddq = new DrillDownQuery(config);
     ddq.add("Author", "Lisa");
@@ -163,6 +163,12 @@ public class TestDrillSideways extends F
     // published once:
     assertEquals("dim=Author path=[] value=5 childCount=4\n  Lisa (2)\n  Bob (1)\n  Susan
(1)\n  Frank (1)\n", r.facets.getTopChildren(10, "Author").toString());
 
+    assertTrue(r.facets instanceof MultiFacets);
+    List<FacetResult> allResults = r.facets.getAllDims(10);
+    assertEquals(2, allResults.size());
+    assertEquals("dim=Author path=[] value=5 childCount=4\n  Lisa (2)\n  Bob (1)\n  Susan
(1)\n  Frank (1)\n", allResults.get(0).toString());
+    assertEquals("dim=Publish Date path=[] value=3 childCount=2\n  2010 (2)\n  2012 (1)\n",
allResults.get(1).toString());
+
     // More interesting case: drill-down on two fields
     ddq = new DrillDownQuery(config);
     ddq.add("Author", "Lisa");



Mime
View raw message