You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2013/01/18 19:31:23 UTC

svn commit: r1435287 [18/41] - in /lucene/dev/branches/LUCENE-2878: ./ dev-tools/ dev-tools/eclipse/ dev-tools/idea/.idea/libraries/ dev-tools/idea/lucene/analysis/icu/ dev-tools/maven/ dev-tools/maven/lucene/benchmark/ dev-tools/maven/solr/ dev-tools/...

Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestFacetsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestFacetsCollector.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestFacetsCollector.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestFacetsCollector.java Fri Jan 18 18:30:54 2013
@@ -1,13 +1,13 @@
 package org.apache.lucene.facet.search;
 
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.lucene.analysis.core.KeywordAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field.Store;
 import org.apache.lucene.document.StringField;
-import org.apache.lucene.facet.index.CategoryDocumentBuilder;
+import org.apache.lucene.facet.index.FacetFields;
 import org.apache.lucene.facet.search.params.FacetSearchParams;
 import org.apache.lucene.facet.search.params.ScoreFacetRequest;
 import org.apache.lucene.facet.search.results.FacetResult;
@@ -55,20 +55,18 @@ public class TestFacetsCollector extends
     IndexWriter iw = new IndexWriter(indexDir, new IndexWriterConfig(
         TEST_VERSION_CURRENT, new KeywordAnalyzer()));
 
-    CategoryDocumentBuilder cdb = new CategoryDocumentBuilder(taxonomyWriter);
-    Iterable<CategoryPath> cats = Arrays.asList(new CategoryPath("a"));
+    FacetFields facetFields = new FacetFields(taxonomyWriter);
     for(int i = atLeast(2000); i > 0; --i) {
       Document doc = new Document();
       doc.add(new StringField("f", "v", Store.NO));
-      cdb.setCategoryPaths(cats);
-      iw.addDocument(cdb.build(doc));
+      facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a")));
+      iw.addDocument(doc);
     }
     
     taxonomyWriter.close();
     iw.close();
     
-    FacetSearchParams sParams = new FacetSearchParams();
-    sParams.addFacetRequest(new ScoreFacetRequest(new CategoryPath("a"), 10));
+    FacetSearchParams sParams = new FacetSearchParams(new ScoreFacetRequest(new CategoryPath("a"), 10));
     
     DirectoryReader r = DirectoryReader.open(indexDir);
     DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);

Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java Fri Jan 18 18:30:54 2013
@@ -1,16 +1,26 @@
 package org.apache.lucene.facet.search;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.analysis.MockTokenizer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.TextField;
 import org.apache.lucene.facet.FacetTestUtils;
+import org.apache.lucene.facet.index.FacetFields;
 import org.apache.lucene.facet.index.params.CategoryListParams;
 import org.apache.lucene.facet.index.params.FacetIndexingParams;
 import org.apache.lucene.facet.index.params.PerDimensionIndexingParams;
 import org.apache.lucene.facet.search.params.CountFacetRequest;
+import org.apache.lucene.facet.search.params.FacetRequest;
+import org.apache.lucene.facet.search.params.FacetRequest.ResultMode;
 import org.apache.lucene.facet.search.params.FacetSearchParams;
 import org.apache.lucene.facet.search.results.FacetResult;
 import org.apache.lucene.facet.search.results.FacetResultNode;
@@ -19,23 +29,19 @@ import org.apache.lucene.facet.taxonomy.
 import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
 import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
 import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
-import org.apache.lucene.index.DocsEnum;
+import org.apache.lucene.index.AtomicReader;
+import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriterConfig.OpenMode;
-import org.apache.lucene.index.MultiFields;
 import org.apache.lucene.index.RandomIndexWriter;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.MultiCollector;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TopScoreDocCollector;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util._TestUtil;
 import org.junit.Test;
 
 /*
@@ -57,6 +63,18 @@ import org.junit.Test;
 
 public class TestMultipleCategoryLists extends LuceneTestCase {
 
+  private static final CategoryPath[] CATEGORIES = new CategoryPath[] {
+    new CategoryPath("Author", "Mark Twain"),
+    new CategoryPath("Author", "Stephen King"),
+    new CategoryPath("Author", "Kurt Vonnegut"),
+    new CategoryPath("Band", "Rock & Pop", "The Beatles"),
+    new CategoryPath("Band", "Punk", "The Ramones"),
+    new CategoryPath("Band", "Rock & Pop", "U2"),
+    new CategoryPath("Band", "Rock & Pop", "REM"),
+    new CategoryPath("Band", "Rock & Pop", "Dave Matthews Band"),
+    new CategoryPath("Composer", "Bach"),
+  };
+  
   @Test
   public void testDefault() throws Exception {
     Directory[][] dirs = getDirs();
@@ -66,10 +84,7 @@ public class TestMultipleCategoryLists e
     // create and open a taxonomy writer
     TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE);
 
-    /**
-     * Configure with no custom counting lists
-     */
-    PerDimensionIndexingParams iParams = new PerDimensionIndexingParams();
+    PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(Collections.<CategoryPath, CategoryListParams>emptyMap());
 
     seedIndex(iw, tw, iParams);
 
@@ -82,19 +97,14 @@ public class TestMultipleCategoryLists e
     // prepare searcher to search against
     IndexSearcher searcher = newSearcher(ir);
 
-    FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
-        searcher);
+    FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
 
     // Obtain facets results and hand-test them
     assertCorrectResults(facetsCollector);
 
-    DocsEnum td = _TestUtil.docs(random(), ir, "$facets", new BytesRef("$fulltree$"), MultiFields.getLiveDocs(ir), null, 0);
-    assertTrue(td.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
+    assertOrdinalsExist("$facets", ir);
 
-    tr.close();
-    ir.close();
-    iw.close();
-    tw.close();
+    IOUtils.close(tr, ir, iw, tw);
     IOUtils.close(dirs[0]);
   }
 
@@ -105,12 +115,10 @@ public class TestMultipleCategoryLists e
     RandomIndexWriter iw = new RandomIndexWriter(random(), dirs[0][0], newIndexWriterConfig(
         TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
     // create and open a taxonomy writer
-    TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1],
-        OpenMode.CREATE);
+    TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE);
 
-    PerDimensionIndexingParams iParams = new PerDimensionIndexingParams();
-    iParams.addCategoryListParams(new CategoryPath("Author"),
-        new CategoryListParams(new Term("$author", "Authors")));
+    PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(
+        Collections.singletonMap(new CategoryPath("Author"), new CategoryListParams("$author")));
     seedIndex(iw, tw, iParams);
 
     IndexReader ir = iw.getReader();
@@ -122,19 +130,15 @@ public class TestMultipleCategoryLists e
     // prepare searcher to search against
     IndexSearcher searcher = newSearcher(ir);
 
-    FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
-        searcher);
+    FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
 
     // Obtain facets results and hand-test them
     assertCorrectResults(facetsCollector);
 
-    assertPostingListExists("$facets", "$fulltree$", ir);
-    assertPostingListExists("$author", "Authors", ir);
+    assertOrdinalsExist("$facets", ir);
+    assertOrdinalsExist("$author", ir);
 
-    tr.close();
-    ir.close();
-    iw.close();
-    tw.close();
+    IOUtils.close(tr, ir, iw, tw);
     IOUtils.close(dirs[0]);
   }
 
@@ -145,14 +149,12 @@ public class TestMultipleCategoryLists e
     RandomIndexWriter iw = new RandomIndexWriter(random(), dirs[0][0], newIndexWriterConfig(
         TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
     // create and open a taxonomy writer
-    TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1],
-        OpenMode.CREATE);
+    TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE);
 
-    PerDimensionIndexingParams iParams = new PerDimensionIndexingParams();
-    iParams.addCategoryListParams(new CategoryPath("Band"),
-        new CategoryListParams(new Term("$music", "Bands")));
-    iParams.addCategoryListParams(new CategoryPath("Composer"),
-        new CategoryListParams(new Term("$music", "Composers")));
+    Map<CategoryPath,CategoryListParams> paramsMap = new HashMap<CategoryPath,CategoryListParams>();
+    paramsMap.put(new CategoryPath("Band"), new CategoryListParams("$music"));
+    paramsMap.put(new CategoryPath("Composer"), new CategoryListParams("$music"));
+    PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap);
     seedIndex(iw, tw, iParams);
 
     IndexReader ir = iw.getReader();
@@ -164,26 +166,27 @@ public class TestMultipleCategoryLists e
     // prepare searcher to search against
     IndexSearcher searcher = newSearcher(ir);
 
-    FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
-        searcher);
+    FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
 
     // Obtain facets results and hand-test them
     assertCorrectResults(facetsCollector);
 
-    assertPostingListExists("$facets", "$fulltree$", ir);
-    assertPostingListExists("$music", "Bands", ir);
-    assertPostingListExists("$music", "Composers", ir);
-
-    tr.close();
-    ir.close();
-    iw.close();
-    tw.close();
+    assertOrdinalsExist("$facets", ir);
+    assertOrdinalsExist("$music", ir);
+    assertOrdinalsExist("$music", ir);
+
+    IOUtils.close(tr, ir, iw, tw);
     IOUtils.close(dirs[0]);
   }
 
-  private void assertPostingListExists(String field, String text, IndexReader ir) throws IOException {
-    DocsEnum de = _TestUtil.docs(random(), ir, field, new BytesRef(text), null, null, 0);
-    assertTrue(de.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
+  private void assertOrdinalsExist(String field, IndexReader ir) throws IOException {
+    for (AtomicReaderContext context : ir.leaves()) {
+      AtomicReader r = context.reader();
+      if (r.docValues(field) != null) {
+        return; // not all segments must have this DocValues
+      }
+    }
+    fail("no ordinals found for " + field);
   }
 
   @Test
@@ -195,11 +198,10 @@ public class TestMultipleCategoryLists e
     // create and open a taxonomy writer
     TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE);
 
-    PerDimensionIndexingParams iParams = new PerDimensionIndexingParams();
-    iParams.addCategoryListParams(new CategoryPath("Band"),
-        new CategoryListParams(new Term("$bands", "Bands")));
-    iParams.addCategoryListParams(new CategoryPath("Composer"),
-        new CategoryListParams(new Term("$composers", "Composers")));
+    Map<CategoryPath,CategoryListParams> paramsMap = new HashMap<CategoryPath,CategoryListParams>();
+    paramsMap.put(new CategoryPath("Band"), new CategoryListParams("$bands"));
+    paramsMap.put(new CategoryPath("Composer"), new CategoryListParams("$composers"));
+    PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap);
     seedIndex(iw, tw, iParams);
 
     IndexReader ir = iw.getReader();
@@ -211,18 +213,15 @@ public class TestMultipleCategoryLists e
     // prepare searcher to search against
     IndexSearcher searcher = newSearcher(ir);
 
-    FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
-        searcher);
+    FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
 
     // Obtain facets results and hand-test them
     assertCorrectResults(facetsCollector);
-    assertPostingListExists("$facets", "$fulltree$", ir);
-    assertPostingListExists("$bands", "Bands", ir);
-    assertPostingListExists("$composers", "Composers", ir);
-    tr.close();
-    ir.close();
-    iw.close();
-    tw.close();
+    assertOrdinalsExist("$facets", ir);
+    assertOrdinalsExist("$bands", ir);
+    assertOrdinalsExist("$composers", ir);
+
+    IOUtils.close(tr, ir, iw, tw);
     IOUtils.close(dirs[0]);
   }
 
@@ -233,16 +232,13 @@ public class TestMultipleCategoryLists e
     RandomIndexWriter iw = new RandomIndexWriter(random(), dirs[0][0], newIndexWriterConfig(
         TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
     // create and open a taxonomy writer
-    TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1],
-        OpenMode.CREATE);
+    TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE);
 
-    PerDimensionIndexingParams iParams = new PerDimensionIndexingParams();
-    iParams.addCategoryListParams(new CategoryPath("Band"),
-        new CategoryListParams(new Term("$music", "music")));
-    iParams.addCategoryListParams(new CategoryPath("Composer"),
-        new CategoryListParams(new Term("$music", "music")));
-    iParams.addCategoryListParams(new CategoryPath("Author"),
-        new CategoryListParams(new Term("$literature", "Authors")));
+    Map<CategoryPath,CategoryListParams> paramsMap = new HashMap<CategoryPath,CategoryListParams>();
+    paramsMap.put(new CategoryPath("Band"), new CategoryListParams("$music"));
+    paramsMap.put(new CategoryPath("Composer"), new CategoryListParams("$music"));
+    paramsMap.put(new CategoryPath("Author"), new CategoryListParams("$literature"));
+    PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap);
 
     seedIndex(iw, tw, iParams);
 
@@ -255,18 +251,14 @@ public class TestMultipleCategoryLists e
     // prepare searcher to search against
     IndexSearcher searcher = newSearcher(ir);
 
-    FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
-        searcher);
+    FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
 
     // Obtain facets results and hand-test them
     assertCorrectResults(facetsCollector);
-    assertPostingListExists("$music", "music", ir);
-    assertPostingListExists("$literature", "Authors", ir);
+    assertOrdinalsExist("$music", ir);
+    assertOrdinalsExist("$literature", ir);
 
-    tr.close();
-    ir.close();
-    iw.close();
-    tw.close();
+    IOUtils.close(tr, ir, iw, tw);
     IOUtils.close(dirs[0]);
   }
 
@@ -274,14 +266,12 @@ public class TestMultipleCategoryLists e
     return FacetTestUtils.createIndexTaxonomyDirs(1);
   }
 
-  private void assertCorrectResults(FacetsCollector facetsCollector)
-  throws IOException {
+  private void assertCorrectResults(FacetsCollector facetsCollector) throws IOException {
     List<FacetResult> res = facetsCollector.getFacetResults();
 
     FacetResult results = res.get(0);
     FacetResultNode resNode = results.getFacetResultNode();
-    Iterable<? extends FacetResultNode> subResults = resNode
-    .getSubResults();
+    Iterable<? extends FacetResultNode> subResults = resNode.getSubResults();
     Iterator<? extends FacetResultNode> subIter = subResults.iterator();
 
     checkResult(resNode, "Band", 5.0);
@@ -324,27 +314,24 @@ public class TestMultipleCategoryLists e
     checkResult(subIter.next(), "Band/Rock & Pop/The Beatles", 1.0);
   }
 
-  private FacetsCollector performSearch(FacetIndexingParams iParams,
-                                        TaxonomyReader tr, IndexReader ir,
-                                        IndexSearcher searcher) throws IOException {
+  private FacetsCollector performSearch(FacetIndexingParams iParams, TaxonomyReader tr, IndexReader ir, 
+      IndexSearcher searcher) throws IOException {
     // step 1: collect matching documents into a collector
     Query q = new MatchAllDocsQuery();
-    TopScoreDocCollector topDocsCollector = TopScoreDocCollector.create(10,
-        true);
+    TopScoreDocCollector topDocsCollector = TopScoreDocCollector.create(10, true);
 
-    // Faceted search parameters indicate which facets are we interested in
-    FacetSearchParams facetSearchParams = new FacetSearchParams(iParams);
-
-    facetSearchParams.addFacetRequest(new CountFacetRequest(
-        new CategoryPath("Band"), 10));
-    CountFacetRequest bandDepth = new CountFacetRequest(new CategoryPath(
-    "Band"), 10);
+    List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
+    facetRequests.add(new CountFacetRequest(new CategoryPath("Band"), 10));
+    CountFacetRequest bandDepth = new CountFacetRequest(new CategoryPath("Band"), 10);
     bandDepth.setDepth(2);
-    facetSearchParams.addFacetRequest(bandDepth);
-    facetSearchParams.addFacetRequest(new CountFacetRequest(
-        new CategoryPath("Author"), 10));
-    facetSearchParams.addFacetRequest(new CountFacetRequest(
-        new CategoryPath("Band", "Rock & Pop"), 10));
+    // makes it easier to check the results in the test.
+    bandDepth.setResultMode(ResultMode.GLOBAL_FLAT);
+    facetRequests.add(bandDepth);
+    facetRequests.add(new CountFacetRequest(new CategoryPath("Author"), 10));
+    facetRequests.add(new CountFacetRequest(new CategoryPath("Band", "Rock & Pop"), 10));
+
+    // Faceted search parameters indicate which facets are we interested in
+    FacetSearchParams facetSearchParams = new FacetSearchParams(facetRequests, iParams);
 
     // perform documents search and facets accumulation
     FacetsCollector facetsCollector = new FacetsCollector(facetSearchParams, ir, tr);
@@ -352,27 +339,19 @@ public class TestMultipleCategoryLists e
     return facetsCollector;
   }
 
-  private void seedIndex(RandomIndexWriter iw, TaxonomyWriter tw,
-                          FacetIndexingParams iParams) throws IOException {
-    FacetTestUtils.add(iParams, iw, tw, "Author", "Mark Twain");
-    FacetTestUtils.add(iParams, iw, tw, "Author", "Stephen King");
-    FacetTestUtils.add(iParams, iw, tw, "Author", "Kurt Vonnegut");
-    FacetTestUtils.add(iParams, iw, tw, "Band", "Rock & Pop",
-    "The Beatles");
-    FacetTestUtils.add(iParams, iw, tw, "Band", "Punk", "The Ramones");
-    FacetTestUtils.add(iParams, iw, tw, "Band", "Rock & Pop", "U2");
-    FacetTestUtils.add(iParams, iw, tw, "Band", "Rock & Pop", "REM");
-    FacetTestUtils.add(iParams, iw, tw, "Band", "Rock & Pop",
-    "Dave Matthews Band");
-    FacetTestUtils.add(iParams, iw, tw, "Composer", "Bach");
+  private void seedIndex(RandomIndexWriter iw, TaxonomyWriter tw, FacetIndexingParams iParams) throws IOException {
+    FacetFields facetFields = new FacetFields(tw, iParams);
+    for (CategoryPath cp : CATEGORIES) {
+      Document doc = new Document();
+      facetFields.addFields(doc, Collections.singletonList(cp));
+      doc.add(new TextField("content", "alpha", Field.Store.YES));
+      iw.addDocument(doc);
+    }
   }
 
   private static void checkResult(FacetResultNode sub, String label, double value) {
-    assertEquals("Label of subresult " + sub.getLabel() + " was incorrect",
-        label, sub.getLabel().toString());
-    assertEquals(
-        "Value for " + sub.getLabel() + " subresult was incorrect",
-        value, sub.getValue(), 0.0);
+    assertEquals("Label of subresult " + sub.getLabel() + " was incorrect", label, sub.getLabel().toString());
+    assertEquals("Value for " + sub.getLabel() + " subresult was incorrect", value, sub.getValue(), 0.0);
   }
 
 }
\ No newline at end of file

Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestScoredDocIdCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestScoredDocIdCollector.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestScoredDocIdCollector.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestScoredDocIdCollector.java Fri Jan 18 18:30:54 2013
@@ -80,7 +80,7 @@ public class TestScoredDocIdCollector ex
     }
 
     // verify by facet values
-    List<FacetResult> countRes = findFacets(scoredDocIDs, getFacetedSearchParams());
+    List<FacetResult> countRes = findFacets(scoredDocIDs, getFacetSearchParams());
     List<FacetResult> scoreRes = findFacets(scoredDocIDs, sumScoreSearchParams());
 
     assertEquals("Wrong number of facet count results!", 1, countRes.size());
@@ -160,16 +160,11 @@ public class TestScoredDocIdCollector ex
   /* use a scoring aggregator */
   private FacetSearchParams sumScoreSearchParams() {
     // this will use default faceted indexing params, not altering anything about indexing
-    FacetSearchParams res = super.getFacetedSearchParams();
-    res.addFacetRequest(new ScoreFacetRequest(new CategoryPath("root", "a"), 10));
-    return res;
+    return new FacetSearchParams(new ScoreFacetRequest(new CategoryPath("root", "a"), 10));
   }
 
-  @Override
-  protected FacetSearchParams getFacetedSearchParams() {
-    FacetSearchParams res = super.getFacetedSearchParams();
-    res.addFacetRequest(new CountFacetRequest(new CategoryPath("root","a"), 10));
-    return res;
+  private FacetSearchParams getFacetSearchParams() {
+    return new FacetSearchParams(new CountFacetRequest(new CategoryPath("root","a"), 10));
   }
 
 }
\ No newline at end of file

Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java Fri Jan 18 18:30:54 2013
@@ -2,28 +2,19 @@ package org.apache.lucene.facet.search;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.TextField;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriterConfig.OpenMode;
-import org.apache.lucene.index.RandomIndexWriter;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.store.Directory;
-import org.junit.Test;
-
-import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.facet.index.CategoryDocumentBuilder;
-import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams;
+import org.apache.lucene.facet.index.FacetFields;
+import org.apache.lucene.facet.index.params.FacetIndexingParams;
 import org.apache.lucene.facet.search.params.CountFacetRequest;
-import org.apache.lucene.facet.search.params.FacetSearchParams;
+import org.apache.lucene.facet.search.params.FacetRequest;
 import org.apache.lucene.facet.search.params.FacetRequest.ResultMode;
+import org.apache.lucene.facet.search.params.FacetSearchParams;
 import org.apache.lucene.facet.search.results.FacetResult;
 import org.apache.lucene.facet.search.results.FacetResultNode;
 import org.apache.lucene.facet.taxonomy.CategoryPath;
@@ -31,6 +22,16 @@ import org.apache.lucene.facet.taxonomy.
 import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
 import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
 import org.apache.lucene.facet.util.PartitionsUtils;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriterConfig.OpenMode;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+import org.junit.Test;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -69,9 +70,9 @@ public class TestTopKInEachNodeResultHan
       }
       
       final int pSize = partitionSize;
-      DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams() {
+      FacetIndexingParams iParams = new FacetIndexingParams() {
         @Override
-        protected int fixedPartitionSize() {
+        public int getPartitionSize() {
           return pSize;
         }
       };
@@ -153,19 +154,19 @@ public class TestTopKInEachNodeResultHan
       cfrb20.setDepth(0);
       cfrb20.setResultMode(ResultMode.PER_NODE_IN_TREE);
 
-      FacetSearchParams facetSearchParams = new FacetSearchParams(iParams);
-      facetSearchParams.addFacetRequest(cfra23);
-      facetSearchParams.addFacetRequest(cfra22);
-      facetSearchParams.addFacetRequest(cfra21);
-      facetSearchParams.addFacetRequest(cfrb23);
-      facetSearchParams.addFacetRequest(cfrb22);
-      facetSearchParams.addFacetRequest(cfrb21);
-      facetSearchParams.addFacetRequest(doctor);
-      facetSearchParams.addFacetRequest(cfrb20);
+      List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
+      facetRequests.add(cfra23);
+      facetRequests.add(cfra22);
+      facetRequests.add(cfra21);
+      facetRequests.add(cfrb23);
+      facetRequests.add(cfrb22);
+      facetRequests.add(cfrb21);
+      facetRequests.add(doctor);
+      facetRequests.add(cfrb20);
+      FacetSearchParams facetSearchParams = new FacetSearchParams(facetRequests, iParams);
       
-      IntArrayAllocator iaa = new IntArrayAllocator(PartitionsUtils.partitionSize(facetSearchParams,tr), 1);
-      FloatArrayAllocator faa = new FloatArrayAllocator(PartitionsUtils.partitionSize(facetSearchParams,tr), 1);
-      FacetsAccumulator fctExtrctr = new StandardFacetsAccumulator(facetSearchParams, is.getIndexReader(), tr, iaa, faa);
+      FacetArrays facetArrays = new FacetArrays(PartitionsUtils.partitionSize(facetSearchParams.getFacetIndexingParams(), tr));
+      FacetsAccumulator fctExtrctr = new StandardFacetsAccumulator(facetSearchParams, is.getIndexReader(), tr, facetArrays);
       fctExtrctr.setComplementThreshold(FacetsAccumulator.DISABLE_COMPLEMENT);
       long start = System.currentTimeMillis();
 
@@ -177,7 +178,7 @@ public class TestTopKInEachNodeResultHan
       }
       
       FacetResult fr = facetResults.get(0); // a, depth=3, K=2
-      boolean hasDoctor = "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
+      boolean hasDoctor = "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
       assertEquals(9, fr.getNumValidDescendants());
       FacetResultNode parentRes = fr.getFacetResultNode();
       assertEquals(16.0, parentRes.getValue(), Double.MIN_VALUE);
@@ -218,7 +219,7 @@ public class TestTopKInEachNodeResultHan
       }
 
       fr = facetResults.get(1); // a, depth=2, K=2. same result as before
-      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
+      hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
       assertEquals(9, fr.getNumValidDescendants());
       parentRes = fr.getFacetResultNode();
       assertEquals(16.0, parentRes.getValue(), Double.MIN_VALUE);
@@ -238,7 +239,7 @@ public class TestTopKInEachNodeResultHan
       }
 
       fr = facetResults.get(2); // a, depth=1, K=2
-      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
+      hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
       assertEquals(4, fr.getNumValidDescendants(), 4);
       parentRes = fr.getFacetResultNode();
       assertEquals(16.0, parentRes.getValue(), Double.MIN_VALUE);
@@ -256,7 +257,7 @@ public class TestTopKInEachNodeResultHan
       }
       
       fr = facetResults.get(3); // a/b, depth=3, K=2
-      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
+      hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
       assertEquals(4, fr.getNumValidDescendants());
       parentRes = fr.getFacetResultNode();
       assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
@@ -271,7 +272,7 @@ public class TestTopKInEachNodeResultHan
       }
 
       fr = facetResults.get(4); // a/b, depth=2, K=2
-      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
+      hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
       assertEquals(4, fr.getNumValidDescendants());
       parentRes = fr.getFacetResultNode();
       assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
@@ -285,7 +286,7 @@ public class TestTopKInEachNodeResultHan
       }
 
       fr = facetResults.get(5); // a/b, depth=1, K=2
-      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
+      hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
       assertEquals(4, fr.getNumValidDescendants());
       parentRes = fr.getFacetResultNode();
       assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
@@ -299,13 +300,13 @@ public class TestTopKInEachNodeResultHan
       }
       
       fr = facetResults.get(6); // a/b, depth=0, K=2
-      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
+      hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
       assertEquals(0, fr.getNumValidDescendants()); // 0 descendants but rootnode
       parentRes = fr.getFacetResultNode();
       assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
       assertEquals(0.0, parentRes.getResidue(), Double.MIN_VALUE);
       assertEquals(0, parentRes.getNumSubResults());
-      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
+      hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
 
       // doctor, depth=1, K=2
       assertFalse("Shouldn't have found anything for a FacetRequest " +
@@ -319,13 +320,11 @@ public class TestTopKInEachNodeResultHan
 
   }
 
-  private void prvt_add(DefaultFacetIndexingParams iParams, RandomIndexWriter iw,
-                    TaxonomyWriter tw, String... strings) throws IOException {
-    ArrayList<CategoryPath> cps = new ArrayList<CategoryPath>();
-    CategoryPath cp = new CategoryPath(strings);
-    cps.add(cp);
+  private void prvt_add(FacetIndexingParams iParams, RandomIndexWriter iw,
+      TaxonomyWriter tw, String... strings) throws IOException {
     Document d = new Document();
-    new CategoryDocumentBuilder(tw, iParams).setCategoryPaths(cps).build(d);
+    FacetFields facetFields = new FacetFields(tw, iParams);
+    facetFields.addFields(d, Collections.singletonList(new CategoryPath(strings)));
     d.add(new TextField("content", "alpha", Field.Store.YES));
     iw.addDocument(d);
   }

Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandler.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandler.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandler.java Fri Jan 18 18:30:54 2013
@@ -1,18 +1,20 @@
 package org.apache.lucene.facet.search;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.MatchAllDocsQuery;
-import org.junit.Test;
-
 import org.apache.lucene.facet.search.params.CountFacetRequest;
+import org.apache.lucene.facet.search.params.FacetRequest;
+import org.apache.lucene.facet.search.params.FacetRequest.ResultMode;
 import org.apache.lucene.facet.search.params.FacetSearchParams;
 import org.apache.lucene.facet.search.results.FacetResult;
 import org.apache.lucene.facet.search.results.FacetResultNode;
 import org.apache.lucene.facet.taxonomy.CategoryPath;
 import org.apache.lucene.facet.taxonomy.TaxonomyReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.junit.Test;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -65,7 +67,7 @@ public class TestTopKResultsHandler exte
   }
   
   /**
-   * Strait forward test: Adding specific documents with specific facets and
+   * Straightforward test: Adding specific documents with specific facets and
    * counting them in the most basic form.
    */
   @Test
@@ -73,16 +75,19 @@ public class TestTopKResultsHandler exte
     for (int partitionSize : partitionSizes) {
       initIndex(partitionSize);
 
-      // do different facet counts and compare to control
-      FacetSearchParams sParams = getFacetedSearchParams(partitionSize);
-      
-      sParams.addFacetRequest(new CountFacetRequest(new CategoryPath("a"), 100));
+      List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
+      facetRequests.add(new CountFacetRequest(new CategoryPath("a"), 100));
       CountFacetRequest cfra = new CountFacetRequest(new CategoryPath("a"), 100);
       cfra.setDepth(3);
-      sParams.addFacetRequest(cfra);
-      sParams.addFacetRequest(new CountFacetRequest(new CategoryPath("a", "b"), 100));
-      sParams.addFacetRequest(new CountFacetRequest(new CategoryPath("a", "b", "1"), 100));
-      sParams.addFacetRequest(new CountFacetRequest(new CategoryPath("a", "c"), 100));
+      // makes it easier to check the results in the test.
+      cfra.setResultMode(ResultMode.GLOBAL_FLAT);
+      facetRequests.add(cfra);
+      facetRequests.add(new CountFacetRequest(new CategoryPath("a", "b"), 100));
+      facetRequests.add(new CountFacetRequest(new CategoryPath("a", "b", "1"), 100));
+      facetRequests.add(new CountFacetRequest(new CategoryPath("a", "c"), 100));
+      
+      // do different facet counts and compare to control
+      FacetSearchParams sParams = getFacetSearchParams(facetRequests, getFacetIndexingParams(partitionSize));
 
       FacetsCollector fc = new FacetsCollector(sParams, indexReader, taxoReader) {
         @Override
@@ -154,8 +159,8 @@ public class TestTopKResultsHandler exte
 
       // do different facet counts and compare to control
       CategoryPath path = new CategoryPath("a", "b");
-      FacetSearchParams sParams = getFacetedSearchParams(partitionSize);
-      sParams.addFacetRequest(new CountFacetRequest(path, Integer.MAX_VALUE));
+      FacetSearchParams sParams = getFacetSearchParams(
+          getFacetIndexingParams(partitionSize), new CountFacetRequest(path, Integer.MAX_VALUE));
 
       FacetsCollector fc = new FacetsCollector(sParams, indexReader, taxoReader) {
         @Override
@@ -180,8 +185,8 @@ public class TestTopKResultsHandler exte
       assertEquals(path + " should only have 4 desendants", 4, res.getNumValidDescendants());
 
       // As a control base results, ask for top-1000 results
-      FacetSearchParams sParams2 = getFacetedSearchParams(partitionSize);
-      sParams2.addFacetRequest(new CountFacetRequest(path, Integer.MAX_VALUE));
+      FacetSearchParams sParams2 = getFacetSearchParams(
+          getFacetIndexingParams(partitionSize), new CountFacetRequest(path, Integer.MAX_VALUE));
 
       FacetsCollector fc2 = new FacetsCollector(sParams2, indexReader, taxoReader) {
         @Override
@@ -217,8 +222,9 @@ public class TestTopKResultsHandler exte
       initIndex(partitionSize);
 
       CategoryPath path = new CategoryPath("Miau Hattulla");
-      FacetSearchParams sParams = getFacetedSearchParams(partitionSize);
-      sParams.addFacetRequest(new CountFacetRequest(path, 10));
+      FacetSearchParams sParams = getFacetSearchParams(
+          getFacetIndexingParams(partitionSize),
+          new CountFacetRequest(path, 10));
 
       FacetsCollector fc = new FacetsCollector(sParams, indexReader, taxoReader);
       

Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java Fri Jan 18 18:30:54 2013
@@ -4,17 +4,16 @@ import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
 
+import org.apache.lucene.facet.FacetTestUtils;
+import org.apache.lucene.facet.FacetTestUtils.IndexTaxonomyReaderPair;
+import org.apache.lucene.facet.FacetTestUtils.IndexTaxonomyWriterPair;
+import org.apache.lucene.facet.index.params.FacetIndexingParams;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util._TestUtil;
 import org.junit.Test;
 
-import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.facet.FacetTestUtils;
-import org.apache.lucene.facet.FacetTestUtils.IndexTaxonomyReaderPair;
-import org.apache.lucene.facet.FacetTestUtils.IndexTaxonomyWriterPair;
-import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -56,9 +55,9 @@ public class TestTotalFacetCounts extend
     // Create our index/taxonomy writers
     IndexTaxonomyWriterPair[] writers = FacetTestUtils
     .createIndexTaxonomyWriterPair(dirs);
-    DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams() {
+    FacetIndexingParams iParams = new FacetIndexingParams() {
       @Override
-      protected int fixedPartitionSize() {
+      public int getPartitionSize() {
         return partitionSize;
       }
     };
@@ -86,12 +85,12 @@ public class TestTotalFacetCounts extend
 
     TotalFacetCountsCache tfcc = TotalFacetCountsCache.getSingleton();
     File tmpFile = _TestUtil.createTempFile("test", "tmp", TEMP_DIR);
-    tfcc.store(tmpFile, readers[0].indexReader, readers[0].taxReader, iParams, null);
+    tfcc.store(tmpFile, readers[0].indexReader, readers[0].taxReader, iParams);
     tfcc.clear(); // not really required because TFCC overrides on load(), but in the test we need not rely on this.
     tfcc.load(tmpFile, readers[0].indexReader, readers[0].taxReader, iParams);
     
     // now retrieve the one just loaded
-    TotalFacetCounts totalCounts = tfcc.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+    TotalFacetCounts totalCounts = tfcc.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
 
     int partition = 0;
     for (int i=0; i<expectedCounts.length; i+=partitionSize) {

Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java Fri Jan 18 18:30:54 2013
@@ -2,22 +2,12 @@ package org.apache.lucene.facet.search;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.analysis.MockTokenizer;
 import org.apache.lucene.document.Document;
-import org.apache.lucene.index.DirectoryReader;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.MockDirectoryWrapper;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.facet.FacetTestUtils;
 import org.apache.lucene.facet.FacetTestUtils.IndexTaxonomyReaderPair;
 import org.apache.lucene.facet.FacetTestUtils.IndexTaxonomyWriterPair;
@@ -25,8 +15,7 @@ import org.apache.lucene.facet.example.E
 import org.apache.lucene.facet.example.TestMultiCLExample;
 import org.apache.lucene.facet.example.multiCL.MultiCLIndexer;
 import org.apache.lucene.facet.example.multiCL.MultiCLSearcher;
-import org.apache.lucene.facet.index.CategoryDocumentBuilder;
-import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams;
+import org.apache.lucene.facet.index.FacetFields;
 import org.apache.lucene.facet.index.params.FacetIndexingParams;
 import org.apache.lucene.facet.search.TotalFacetCounts.CreationType;
 import org.apache.lucene.facet.search.results.FacetResult;
@@ -36,9 +25,18 @@ import org.apache.lucene.facet.taxonomy.
 import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
 import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
 import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.MockDirectoryWrapper;
 import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.SlowRAMDirectory;
 import org.apache.lucene.util._TestUtil;
+import org.junit.Before;
+import org.junit.Test;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -80,7 +78,7 @@ public class TestTotalFacetCountsCache e
     @Override
     public void run() {
       try {
-        tfc = TFC.getTotalCounts(r, tr, iParams, null);
+        tfc = TFC.getTotalCounts(r, tr, iParams);
       } catch (Exception e) {
         throw new RuntimeException(e);
       }
@@ -90,10 +88,10 @@ public class TestTotalFacetCountsCache e
   /** Utility method to add a document and facets to an index/taxonomy. */
   static void addFacets(FacetIndexingParams iParams, IndexWriter iw,
                         TaxonomyWriter tw, String... strings) throws IOException {
-    ArrayList<CategoryPath> cps = new ArrayList<CategoryPath>();
-    cps.add(new CategoryPath(strings));
-    CategoryDocumentBuilder builder = new CategoryDocumentBuilder(tw, iParams);
-    iw.addDocument(builder.setCategoryPaths(cps).build(new Document()));
+    Document doc = new Document();
+    FacetFields facetFields = new FacetFields(tw, iParams);
+    facetFields.addFields(doc, Collections.singletonList(new CategoryPath(strings)));
+    iw.addDocument(doc);
   }
 
   /** Clears the cache and sets its size to one. */
@@ -145,7 +143,6 @@ public class TestTotalFacetCountsCache e
     MockDirectoryWrapper indexDir = new MockDirectoryWrapper(random(), slowIndexDir);
     SlowRAMDirectory slowTaxoDir = new SlowRAMDirectory(-1, random());
     MockDirectoryWrapper taxoDir = new MockDirectoryWrapper(random(), slowTaxoDir);
-    
 
     // Index documents without the "slowness"
     MultiCLIndexer.index(indexDir, taxoDir);
@@ -196,7 +193,7 @@ public class TestTotalFacetCountsCache e
     // it references a different TFC cache. This will still result
     // in valid results, but will only search one of the category lists
     // instead of all of them.
-    multis[numThreads - 1] = new Multi(slowIndexReader, slowTaxoReader, new DefaultFacetIndexingParams());
+    multis[numThreads - 1] = new Multi(slowIndexReader, slowTaxoReader, FacetIndexingParams.ALL_PARENTS);
 
     // Gentleman, start your engines
     for (Multi m : multis) {
@@ -252,7 +249,7 @@ public class TestTotalFacetCountsCache e
 
     // Create our index/taxonomy writers
     IndexTaxonomyWriterPair[] writers = FacetTestUtils.createIndexTaxonomyWriterPair(dirs);
-    DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams();
+    FacetIndexingParams iParams = FacetIndexingParams.ALL_PARENTS;
 
     // Add a facet to the index
     addFacets(iParams, writers[0].indexWriter, writers[0].taxWriter, "a", "b");
@@ -267,29 +264,29 @@ public class TestTotalFacetCountsCache e
     // As this is the first time we have invoked the TotalFacetCountsManager, 
     // we should expect to compute and not read from disk.
     TotalFacetCounts totalCounts = 
-      TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+      TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
     int prevGen = assertRecomputed(totalCounts, 0, "after first attempt to get it!");
 
     // Repeating same operation should pull from the cache - not recomputed. 
     assertTrue("Should be obtained from cache at 2nd attempt",totalCounts == 
-      TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null));
+      TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams));
 
     // Repeat the same operation as above. but clear first - now should recompute again
     initCache();
-    totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+    totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
     prevGen = assertRecomputed(totalCounts, prevGen, "after cache clear, 3rd attempt to get it!");
     
     //store to file
     File outputFile = _TestUtil.createTempFile("test", "tmp", TEMP_DIR);
     initCache();
-    TFC.store(outputFile, readers[0].indexReader, readers[0].taxReader, iParams, null);
-    totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+    TFC.store(outputFile, readers[0].indexReader, readers[0].taxReader, iParams);
+    totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
     prevGen = assertRecomputed(totalCounts, prevGen, "after cache clear, 4th attempt to get it!");
 
     //clear and load
     initCache();
     TFC.load(outputFile, readers[0].indexReader, readers[0].taxReader, iParams);
-    totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+    totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
     prevGen = assertReadFromDisc(totalCounts, prevGen, "after 5th attempt to get it!");
 
     // Add a new facet to the index, commit and refresh readers
@@ -309,12 +306,12 @@ public class TestTotalFacetCountsCache e
     readers[0].indexReader = r2;
 
     // now use the new reader - should recompute
-    totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+    totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
     prevGen = assertRecomputed(totalCounts, prevGen, "after updating the index - 7th attempt!");
 
     // try again - should not recompute
     assertTrue("Should be obtained from cache at 8th attempt",totalCounts == 
-      TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null));
+      TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams));
     
     readers[0].close();
     outputFile.delete();
@@ -347,11 +344,10 @@ public class TestTotalFacetCountsCache e
     // Create temporary RAMDirectories
     Directory[][] dirs = FacetTestUtils.createIndexTaxonomyDirs(1);
     // Create our index/taxonomy writers
-    IndexTaxonomyWriterPair[] writers = FacetTestUtils
-    .createIndexTaxonomyWriterPair(dirs);
-    DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams() {
+    IndexTaxonomyWriterPair[] writers = FacetTestUtils.createIndexTaxonomyWriterPair(dirs);
+    FacetIndexingParams iParams = new FacetIndexingParams() {
       @Override
-      protected int fixedPartitionSize() {
+      public int getPartitionSize() {
         return 2;
       }
     };
@@ -365,7 +361,7 @@ public class TestTotalFacetCountsCache e
 
     // Create TFC and write cache to disk
     File outputFile = _TestUtil.createTempFile("test", "tmp", TEMP_DIR);
-    TFC.store(outputFile, readers[0].indexReader, readers[0].taxReader, iParams, null);
+    TFC.store(outputFile, readers[0].indexReader, readers[0].taxReader, iParams);
     
     // Make the taxonomy grow without touching the index
     for (int i = 0; i < 10; i++) {
@@ -381,8 +377,7 @@ public class TestTotalFacetCountsCache e
 
     // With the bug, this next call should result in an exception
     TFC.load(outputFile, readers[0].indexReader, readers[0].taxReader, iParams);
-    TotalFacetCounts totalCounts = TFC.getTotalCounts(
-        readers[0].indexReader, readers[0].taxReader, iParams, null);
+    TotalFacetCounts totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
     assertReadFromDisc(totalCounts, 0, "after reading from disk.");
     outputFile.delete();
     writers[0].close();
@@ -403,7 +398,7 @@ public class TestTotalFacetCountsCache e
     IndexWriter w = new IndexWriter(indexDir, new IndexWriterConfig(
         TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
     DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
-    DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams();
+    FacetIndexingParams iParams = FacetIndexingParams.ALL_PARENTS;
     // Add documents and facets
     for (int i = 0; i < 1000; i++) {
       addFacets(iParams, w, tw, "facet", Integer.toString(i));
@@ -454,7 +449,7 @@ public class TestTotalFacetCountsCache e
     Directory[][] dirs = FacetTestUtils.createIndexTaxonomyDirs(2);
     // Create our index/taxonomy writers
     IndexTaxonomyWriterPair[] writers = FacetTestUtils.createIndexTaxonomyWriterPair(dirs);
-    DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams();
+    FacetIndexingParams iParams = FacetIndexingParams.ALL_PARENTS;
 
     // Add a facet to the index
     addFacets(iParams, writers[0].indexWriter, writers[0].taxWriter, "a", "b");
@@ -471,28 +466,25 @@ public class TestTotalFacetCountsCache e
     // As this is the first time we have invoked the TotalFacetCountsManager, we
     // should expect to compute.
     TotalFacetCounts totalCounts0 = 
-      TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+      TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
     int prevGen = -1;
     prevGen = assertRecomputed(totalCounts0, prevGen, "after attempt 1");
     assertTrue("attempt 1b for same input [0] shout find it in cache",
-        totalCounts0 == TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null));
+        totalCounts0 == TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams));
     
     // 2nd Reader - As this is the first time we have invoked the
     // TotalFacetCountsManager, we should expect a state of NEW to be returned.
-    TotalFacetCounts totalCounts1 = 
-      TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams, null);
+    TotalFacetCounts totalCounts1 = TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams);
     prevGen = assertRecomputed(totalCounts1, prevGen, "after attempt 2");
     assertTrue("attempt 2b for same input [1] shout find it in cache",
-        totalCounts1 == TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams, null));
+        totalCounts1 == TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams));
 
     // Right now cache size is one, so first TFC is gone and should be recomputed  
-    totalCounts0 = 
-      TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+    totalCounts0 = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
     prevGen = assertRecomputed(totalCounts0, prevGen, "after attempt 3");
     
     // Similarly will recompute the second result  
-    totalCounts1 = 
-      TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams, null);
+    totalCounts1 = TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams);
     prevGen = assertRecomputed(totalCounts1, prevGen, "after attempt 4");
 
     // Now we set the cache size to two, meaning both should exist in the
@@ -500,17 +492,15 @@ public class TestTotalFacetCountsCache e
     TFC.setCacheSize(2);
 
     // Re-compute totalCounts0 (was evicted from the cache when the cache was smaller)
-    totalCounts0 = 
-      TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+    totalCounts0 = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
     prevGen = assertRecomputed(totalCounts0, prevGen, "after attempt 5");
 
     // now both are in the larger cache and should not be recomputed 
-    totalCounts1 = TFC.getTotalCounts(readers[1].indexReader,
-        readers[1].taxReader, iParams, null);
+    totalCounts1 = TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams);
     assertTrue("with cache of size 2 res no. 0 should come from cache",
-        totalCounts0 == TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null));
+        totalCounts0 == TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams));
     assertTrue("with cache of size 2 res no. 1 should come from cache",
-        totalCounts1 == TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams, null));
+        totalCounts1 == TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams));
     
     writers[0].close();
     writers[1].close();

Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java Fri Jan 18 18:30:54 2013
@@ -32,12 +32,12 @@ public class FacetRequestTest extends Lu
 
   @Test(expected=IllegalArgumentException.class)
   public void testIllegalNumResults() throws Exception {
-    new CountFacetRequest(new CategoryPath("a", "b"), 0);
+    assertNotNull(new CountFacetRequest(new CategoryPath("a", "b"), 0));
   }
   
   @Test(expected=IllegalArgumentException.class)
   public void testIllegalCategoryPath() throws Exception {
-    new CountFacetRequest(null, 1);
+    assertNotNull(new CountFacetRequest(null, 1));
   }
 
   @Test

Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java Fri Jan 18 18:30:54 2013
@@ -1,16 +1,7 @@
 package org.apache.lucene.facet.search.params;
 
-import org.apache.lucene.store.Directory;
-import org.junit.Test;
-
 import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams;
-import org.apache.lucene.facet.taxonomy.CategoryPath;
-import org.apache.lucene.facet.taxonomy.TaxonomyReader;
-import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
-import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
-import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
-import org.apache.lucene.facet.util.PartitionsUtils;
+import org.junit.Test;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -32,47 +23,10 @@ import org.apache.lucene.facet.util.Part
 public class FacetSearchParamsTest extends LuceneTestCase {
 
   @Test
-  public void testDefaultSettings() throws Exception {
-    FacetSearchParams fsp = new FacetSearchParams();
-    assertEquals("unexpected default facet indexing params class", DefaultFacetIndexingParams.class.getName(), fsp.getFacetIndexingParams().getClass().getName());
-    assertEquals("no facet requests should be added by default", 0, fsp.getFacetRequests().size());
-    Directory dir = newDirectory();
-    new DirectoryTaxonomyWriter(dir).close();
-    TaxonomyReader tr = new DirectoryTaxonomyReader(dir);
-    assertEquals("unexpected partition offset for 0 categories", 1, PartitionsUtils.partitionOffset(fsp, 1, tr));
-    assertEquals("unexpected partition size for 0 categories", 1, PartitionsUtils.partitionSize(fsp,tr));
-    tr.close();
-    dir.close();
-  }
-  
-  @Test
-  public void testAddFacetRequest() throws Exception {
-    FacetSearchParams fsp = new FacetSearchParams();
-    fsp.addFacetRequest(new CountFacetRequest(new CategoryPath("a", "b"), 1));
-    assertEquals("expected 1 facet request", 1, fsp.getFacetRequests().size());
-  }
-  
-  @Test
-  public void testPartitionSizeWithCategories() throws Exception {
-    FacetSearchParams fsp = new FacetSearchParams();
-    Directory dir = newDirectory();
-    TaxonomyWriter tw = new DirectoryTaxonomyWriter(dir);
-    tw.addCategory(new CategoryPath("a"));
-    tw.commit();
-    tw.close();
-    TaxonomyReader tr = new DirectoryTaxonomyReader(dir);
-    assertEquals("unexpected partition offset for 1 categories", 2, PartitionsUtils.partitionOffset(fsp, 1, tr));
-    assertEquals("unexpected partition size for 1 categories", 2, PartitionsUtils.partitionSize(fsp,tr));
-    tr.close();
-    dir.close();
-  }
-  
-  @Test
   public void testSearchParamsWithNullRequest() throws Exception {
-    FacetSearchParams fsp = new FacetSearchParams();
     try {
-      fsp.addFacetRequest(null);
-      fail("FacetSearchParams should throw IllegalArgumentException when trying to add a null FacetRequest");
+      assertNull(new FacetSearchParams());
+      fail("FacetSearchParams should throw IllegalArgumentException when not adding requests");
     } catch (IllegalArgumentException e) {
     }
   }

Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java Fri Jan 18 18:30:54 2013
@@ -14,6 +14,8 @@ import org.apache.lucene.facet.search.Fa
 import org.apache.lucene.facet.search.FacetsCollector;
 import org.apache.lucene.facet.search.ScoredDocIDs;
 import org.apache.lucene.facet.search.ScoredDocIdCollector;
+import org.apache.lucene.facet.search.params.FacetRequest;
+import org.apache.lucene.facet.search.params.FacetRequest.ResultMode;
 import org.apache.lucene.facet.search.params.FacetSearchParams;
 import org.apache.lucene.facet.search.results.FacetResult;
 import org.apache.lucene.facet.taxonomy.TaxonomyReader;
@@ -43,16 +45,29 @@ public abstract class BaseSampleTestTopK
   /** since there is a chance that this test would fail even if the code is correct, retry the sampling */
   protected static final int RETRIES = 10;
   
-  protected abstract FacetsAccumulator getSamplingAccumulator(Sampler sampler,
-      TaxonomyReader taxoReader, IndexReader indexReader,
-      FacetSearchParams searchParams);
+  @Override
+  protected FacetSearchParams searchParamsWithRequests(int numResults, int partitionSize) {
+    FacetSearchParams res = super.searchParamsWithRequests(numResults, partitionSize);
+    for (FacetRequest req : res.getFacetRequests()) {
+      // randomize the way we aggregate results
+      if (random().nextBoolean()) {
+        req.setResultMode(ResultMode.GLOBAL_FLAT);
+      } else {
+        req.setResultMode(ResultMode.PER_NODE_IN_TREE);
+      }
+    }
+    return res;
+  }
+  
+  protected abstract FacetsAccumulator getSamplingAccumulator(Sampler sampler, TaxonomyReader taxoReader, 
+      IndexReader indexReader, FacetSearchParams searchParams);
   
   /**
    * Try out faceted search with sampling enabled and complements either disabled or enforced
    * Lots of randomly generated data is being indexed, and later on a "90% docs" faceted search
    * is performed. The results are compared to non-sampled ones.
    */
-  public void testCountUsingSamping() throws Exception {
+  public void testCountUsingSampling() throws Exception {
     boolean useRandomSampler = random().nextBoolean();
     for (int partitionSize : partitionSizes) {
       try {
@@ -73,7 +88,7 @@ public abstract class BaseSampleTestTopK
         
         // try several times in case of failure, because the test has a chance to fail 
         // if the top K facets are not sufficiently common with the sample set
-        for (int nTrial=0; nTrial<RETRIES; nTrial++) {
+        for (int nTrial = 0; nTrial < RETRIES; nTrial++) {
           try {
             // complement with sampling!
             final Sampler sampler = createSampler(nTrial, docCollector.getScoredDocIDs(), useRandomSampler);
@@ -83,7 +98,7 @@ public abstract class BaseSampleTestTopK
             
             break; // succeeded
           } catch (NotSameResultError e) {
-            if (nTrial>=RETRIES-1) {
+            if (nTrial >= RETRIES - 1) {
               throw e; // no more retries allowed, must fail
             }
           }
@@ -103,14 +118,11 @@ public abstract class BaseSampleTestTopK
     assertSameResults(expected, sampledResults);
   }
   
-  private FacetsCollector samplingCollector(
-      final boolean complement,
-      final Sampler sampler,
+  private FacetsCollector samplingCollector(final boolean complement, final Sampler sampler,
       FacetSearchParams samplingSearchParams) {
     FacetsCollector samplingFC = new FacetsCollector(samplingSearchParams, indexReader, taxoReader) {
       @Override
-      protected FacetsAccumulator initFacetsAccumulator(
-          FacetSearchParams facetSearchParams, IndexReader indexReader,
+      protected FacetsAccumulator initFacetsAccumulator(FacetSearchParams facetSearchParams, IndexReader indexReader,
           TaxonomyReader taxonomyReader) {
         FacetsAccumulator acc = getSamplingAccumulator(sampler, taxonomyReader, indexReader, facetSearchParams);
         acc.setComplementThreshold(complement ? FacetsAccumulator.FORCE_COMPLEMENT : FacetsAccumulator.DISABLE_COMPLEMENT);
@@ -128,12 +140,13 @@ public abstract class BaseSampleTestTopK
     samplingParams.setMinSampleSize((int) (100 * retryFactor));
     samplingParams.setMaxSampleSize((int) (10000 * retryFactor));
     samplingParams.setOversampleFactor(5.0 * retryFactor);
+    samplingParams.setSamplingThreshold(11000); //force sampling
 
-    samplingParams.setSampingThreshold(11000); //force sampling 
     Sampler sampler = useRandomSampler ? 
         new RandomSampler(samplingParams, new Random(random().nextLong())) :
           new RepeatableSampler(samplingParams);
     assertTrue("must enable sampling for this test!",sampler.shouldSample(scoredDocIDs));
     return sampler;
   }
+  
 }

Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/OversampleWithDepthTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/OversampleWithDepthTest.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/OversampleWithDepthTest.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/OversampleWithDepthTest.java Fri Jan 18 18:30:54 2013
@@ -1,11 +1,11 @@
 package org.apache.lucene.facet.search.sampling;
 
 import java.io.IOException;
-import java.util.ArrayList;
+import java.util.Collections;
 
 import org.apache.lucene.analysis.core.KeywordAnalyzer;
 import org.apache.lucene.document.Document;
-import org.apache.lucene.facet.index.CategoryDocumentBuilder;
+import org.apache.lucene.facet.index.FacetFields;
 import org.apache.lucene.facet.search.FacetsAccumulator;
 import org.apache.lucene.facet.search.FacetsCollector;
 import org.apache.lucene.facet.search.params.CountFacetRequest;
@@ -52,7 +52,7 @@ import org.junit.Test;
 public class OversampleWithDepthTest extends LuceneTestCase {
   
   @Test
-  public void testCountWithdepthUsingSamping() throws Exception, IOException {
+  public void testCountWithdepthUsingSampling() throws Exception, IOException {
     Directory indexDir = newDirectory();
     Directory taxoDir = newDirectory();
     
@@ -63,21 +63,19 @@ public class OversampleWithDepthTest ext
     DirectoryReader r = DirectoryReader.open(indexDir);
     TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
     
-    FacetSearchParams fsp = new FacetSearchParams();
-    
     CountFacetRequest facetRequest = new CountFacetRequest(new CategoryPath("root"), 10);
-    
     // Setting the depth to '2', should potentially get all categories
     facetRequest.setDepth(2);
     facetRequest.setResultMode(ResultMode.PER_NODE_IN_TREE);
-    fsp.addFacetRequest(facetRequest);
+
+    FacetSearchParams fsp = new FacetSearchParams(facetRequest);
     
     // Craft sampling params to enforce sampling
     final SamplingParams params = new SamplingParams();
     params.setMinSampleSize(2);
     params.setMaxSampleSize(50);
     params.setOversampleFactor(5);
-    params.setSampingThreshold(60);
+    params.setSamplingThreshold(60);
     params.setSampleRatio(0.1);
     
     FacetResult res = searchWithFacets(r, tr, fsp, params);
@@ -102,14 +100,12 @@ public class OversampleWithDepthTest ext
     IndexWriter w = new IndexWriter(indexDir, iwc);
     TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
     
-    CategoryDocumentBuilder cdb = new CategoryDocumentBuilder(tw);
-    ArrayList<CategoryPath> categoryPaths = new ArrayList<CategoryPath>(1);
-    
+    FacetFields facetFields = new FacetFields(tw);
     for (int i = 0; i < 100; i++) {
-      categoryPaths.clear();
-      categoryPaths.add(new CategoryPath("root",Integer.toString(i / 10), Integer.toString(i)));
-      cdb.setCategoryPaths(categoryPaths);
-      w.addDocument(cdb.build(new Document()));
+      Document doc = new Document();
+      CategoryPath cp = new CategoryPath("root",Integer.toString(i / 10), Integer.toString(i));
+      facetFields.addFields(doc, Collections.singletonList(cp));
+      w.addDocument(doc);
     }
     IOUtils.close(tw, w);
   }