Return-Path: X-Original-To: apmail-lucene-commits-archive@www.apache.org Delivered-To: apmail-lucene-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4AD691061A for ; Mon, 17 Mar 2014 19:39:16 +0000 (UTC) Received: (qmail 9734 invoked by uid 500); 17 Mar 2014 19:39:16 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 9727 invoked by uid 99); 17 Mar 2014 19:39:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Mar 2014 19:39:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Mar 2014 19:39:14 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1D5E323888E4; Mon, 17 Mar 2014 19:38:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@lucene.apache.org From: mikemccand@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140317193854.1D5E323888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 facets = result.facets.getAllDims(10); + + indexReader.close(); + taxoReader.close(); + + return facets; + } + /** Runs the search example. */ public List runSearch() throws IOException { index(); @@ -154,6 +184,12 @@ public class SimpleFacetsExample { return drillDown(); } + /** Runs the drill-sideways example. */ + public List 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 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 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 getAllDims(int topN) throws IOException { - // TODO - throw new UnsupportedOperationException(); + + List results = new ArrayList(); + + // First add the specific dim's facets: + for(Map.Entry 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 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");