Apache Lucene open-source search software
LUCENE-5339: fix some nocommits; move taxoWriter out of FacetsConfig; move search + collect utility methods to FacetsCollector
Michael McCandless3693346afa9f
diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.javaindex a7487736acb..3ae32f115ee 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.java@@ -66,7 +66,7 @@ public class AddFacetedDocTask extends AddDocTask {// nocommit is this called once? are we adding same// facets over and over!?FacetSource facetsSource = getRunData().getFacetSource();- config = new FacetsConfig(getRunData().getTaxonomyWriter());+ config = new FacetsConfig();facetsSource.getNextFacets(facets);facetsSource.configure(config);}@@ -89,7 +89,7 @@ public class AddFacetedDocTask extends AddDocTask {for(FacetField ff : facets) {doc2.add(ff);}- IndexDocument doc3 = config.build(doc2);+ IndexDocument doc3 = config.build(getRunData().getTaxonomyWriter(), doc2);for(StorableField field : doc3.storableFields()) {doc.add((Field) field);}diff --git a/lucene/demo/src/java/org/apache/lucene/demo/facet/AssociationsFacetsExample.java b/lucene/demo/src/java/org/apache/lucene/demo/facet/AssociationsFacetsExample.javaindex 27664eaed44..08aa78fd961 100644--- a/lucene/demo/src/java/org/apache/lucene/demo/facet/AssociationsFacetsExample.java+++ b/lucene/demo/src/java/org/apache/lucene/demo/facet/AssociationsFacetsExample.java@@ -49,9 +49,16 @@ public class AssociationsFacetsExample {private final Directory indexDir = new RAMDirectory();private final Directory taxoDir = new RAMDirectory();+ private final FacetsConfig config;/** Empty constructor */- public AssociationsFacetsExample() {}+ public AssociationsFacetsExample() {+ config = new FacetsConfig();+ config.setMultiValued("tags", true);+ config.setIndexFieldName("tags", "$tags");+ config.setMultiValued("genre", true);+ config.setIndexFieldName("genre", "$genre");+ }/** Build the example index. */private void index() throws IOException {@@ -62,15 +69,12 @@ public class AssociationsFacetsExample {// Writes facet ords to a separate directory from the main indexDirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);- // Reused across documents, to add the necessary facet fields- FacetsConfig config = getConfig(taxoWriter);-Document doc = new Document();// 3 occurrences for tag 'lucene'doc.add(new IntAssociationFacetField(3, "tags", "lucene"));// 87% confidence level of genre 'computing'doc.add(new FloatAssociationFacetField(0.87f, "genre", "computing"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();// 1 occurrence for tag 'lucene'@@ -81,35 +85,24 @@ public class AssociationsFacetsExample {doc.add(new FloatAssociationFacetField(0.75f, "genre", "computing"));// 34% confidence level of genre 'software'doc.add(new FloatAssociationFacetField(0.34f, "genre", "software"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));indexWriter.close();taxoWriter.close();}- /** It's fine if taxoWriter is null (i.e., at search time) */- private FacetsConfig getConfig(TaxonomyWriter taxoWriter) {- FacetsConfig config = new FacetsConfig(taxoWriter);- config.setMultiValued("tags", true);- config.setIndexFieldName("tags", "$tags");- config.setMultiValued("genre", true);- config.setIndexFieldName("genre", "$genre");- return config;- }-/** User runs a query and aggregates facets by summing their association values. */private List<FacetResult> sumAssociations() throws IOException {DirectoryReader indexReader = DirectoryReader.open(indexDir);IndexSearcher searcher = new IndexSearcher(indexReader);TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);- FacetsConfig config = getConfig(null);FacetsCollector fc = new FacetsCollector();// MatchAllDocsQuery is for "browsing" (counts facets// for all non-deleted docs in the index); normally// you'd use a "normal" query:- Facets.search(searcher, new MatchAllDocsQuery(), 10, fc);+ FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);Facets tags = new TaxonomyFacetSumIntAssociations("$tags", taxoReader, config, fc);Facets genre = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc);diff --git a/lucene/demo/src/java/org/apache/lucene/demo/facet/ExpressionAggregationFacetsExample.java b/lucene/demo/src/java/org/apache/lucene/demo/facet/ExpressionAggregationFacetsExample.javaindex 6062e4d62f5..e6088c995a7 100644--- a/lucene/demo/src/java/org/apache/lucene/demo/facet/ExpressionAggregationFacetsExample.java+++ b/lucene/demo/src/java/org/apache/lucene/demo/facet/ExpressionAggregationFacetsExample.java@@ -54,6 +54,7 @@ public class ExpressionAggregationFacetsExample {private final Directory indexDir = new RAMDirectory();private final Directory taxoDir = new RAMDirectory();+ private final FacetsConfig config = new FacetsConfig();/** Empty constructor */public ExpressionAggregationFacetsExample() {}@@ -66,20 +67,17 @@ public class ExpressionAggregationFacetsExample {// Writes facet ords to a separate directory from the main indexDirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);- // Reused across documents, to add the necessary facet fields- FacetsConfig config = new FacetsConfig(taxoWriter);-Document doc = new Document();doc.add(new TextField("c", "foo bar", Store.NO));doc.add(new NumericDocValuesField("popularity", 5L));doc.add(new FacetField("A", "B"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new TextField("c", "foo foo bar", Store.NO));doc.add(new NumericDocValuesField("popularity", 3L));doc.add(new FacetField("A", "C"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));indexWriter.close();taxoWriter.close();@@ -90,7 +88,6 @@ public class ExpressionAggregationFacetsExample {DirectoryReader indexReader = DirectoryReader.open(indexDir);IndexSearcher searcher = new IndexSearcher(indexReader);TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);- FacetsConfig config = new FacetsConfig();// Aggregate categories by an expression that combines the document's score// and its popularity field@@ -105,7 +102,7 @@ public class ExpressionAggregationFacetsExample {// MatchAllDocsQuery is for "browsing" (counts facets// for all non-deleted docs in the index); normally// you'd use a "normal" query:- Facets.search(searcher, new MatchAllDocsQuery(), 10, fc);+ FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);// Retrieve resultsFacets facets = new TaxonomyFacetSumValueSource(taxoReader, config, fc, expr.getValueSource(bindings));diff --git a/lucene/demo/src/java/org/apache/lucene/demo/facet/MultiCategoryListsFacetsExample.java b/lucene/demo/src/java/org/apache/lucene/demo/facet/MultiCategoryListsFacetsExample.javaindex 1ec6ffb8a62..11d8eb70fe0 100644--- a/lucene/demo/src/java/org/apache/lucene/demo/facet/MultiCategoryListsFacetsExample.java+++ b/lucene/demo/src/java/org/apache/lucene/demo/facet/MultiCategoryListsFacetsExample.java@@ -49,20 +49,15 @@ public class MultiCategoryListsFacetsExample {private final Directory indexDir = new RAMDirectory();private final Directory taxoDir = new RAMDirectory();+ private final FacetsConfig config = new FacetsConfig();/** Creates a new instance and populates the catetory list params mapping. */public MultiCategoryListsFacetsExample() {- }-- /** It's fine if taxoWriter is null (i.e., at search time) */- private FacetsConfig getConfig(TaxonomyWriter taxoWriter) {- FacetsConfig config = new FacetsConfig(taxoWriter);config.setIndexFieldName("Author", "author");config.setIndexFieldName("Publish Date", "pubdate");config.setHierarchical("Publish Date", true);- return config;}-+/** Build the example index. */private void index() throws IOException {IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig(FacetExamples.EXAMPLES_VER,@@ -71,32 +66,30 @@ public class MultiCategoryListsFacetsExample {// Writes facet ords to a separate directory from the main indexDirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);- FacetsConfig config = getConfig(taxoWriter);-Document doc = new Document();doc.add(new FacetField("Author", "Bob"));doc.add(new FacetField("Publish Date", "2010", "10", "15"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Lisa"));doc.add(new FacetField("Publish Date", "2010", "10", "20"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Lisa"));doc.add(new FacetField("Publish Date", "2012", "1", "1"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Susan"));doc.add(new FacetField("Publish Date", "2012", "1", "7"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Frank"));doc.add(new FacetField("Publish Date", "1999", "5", "5"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));indexWriter.close();taxoWriter.close();@@ -107,14 +100,13 @@ public class MultiCategoryListsFacetsExample {DirectoryReader indexReader = DirectoryReader.open(indexDir);IndexSearcher searcher = new IndexSearcher(indexReader);TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);- FacetsConfig config = getConfig(null);FacetsCollector fc = new FacetsCollector();// MatchAllDocsQuery is for "browsing" (counts facets// for all non-deleted docs in the index); normally// you'd use a "normal" query:- Facets.search(searcher, new MatchAllDocsQuery(), 10, fc);+ FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);// Retrieve resultsList<FacetResult> results = new ArrayList<FacetResult>();diff --git a/lucene/demo/src/java/org/apache/lucene/demo/facet/RangeFacetsExample.java b/lucene/demo/src/java/org/apache/lucene/demo/facet/RangeFacetsExample.javaindex 606d9daca46..8a7d4b4be48 100644--- a/lucene/demo/src/java/org/apache/lucene/demo/facet/RangeFacetsExample.java+++ b/lucene/demo/src/java/org/apache/lucene/demo/facet/RangeFacetsExample.java@@ -94,7 +94,7 @@ public class RangeFacetsExample implements Closeable {// MatchAllDocsQuery is for "browsing" (counts facets// for all non-deleted docs in the index); normally// you'd use a "normal" query:- Facets.search(searcher, new MatchAllDocsQuery(), 10, fc);+ FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);Facets facets = new RangeFacetCounts("timestamp", fc,PAST_HOUR,diff --git a/lucene/demo/src/java/org/apache/lucene/demo/facet/SimpleFacetsExample.java b/lucene/demo/src/java/org/apache/lucene/demo/facet/SimpleFacetsExample.javaindex b5d5376bbf9..8f9de58706f 100644--- a/lucene/demo/src/java/org/apache/lucene/demo/facet/SimpleFacetsExample.java+++ b/lucene/demo/src/java/org/apache/lucene/demo/facet/SimpleFacetsExample.java@@ -48,17 +48,13 @@ public class SimpleFacetsExample {private final Directory indexDir = new RAMDirectory();private final Directory taxoDir = new RAMDirectory();+ private final FacetsConfig config = new FacetsConfig();/** Empty constructor */- public SimpleFacetsExample() {}-- /** It's fine if taxoWriter is null (i.e., at search time) */- private FacetsConfig getConfig(TaxonomyWriter taxoWriter) {- FacetsConfig config = new FacetsConfig(taxoWriter);+ public SimpleFacetsExample() {config.setHierarchical("Publish Date", true);- return config;}-+/** Build the example index. */private void index() throws IOException {IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig(FacetExamples.EXAMPLES_VER,@@ -67,32 +63,30 @@ public class SimpleFacetsExample {// Writes facet ords to a separate directory from the main indexDirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);- FacetsConfig config = getConfig(taxoWriter);-Document doc = new Document();doc.add(new FacetField("Author", "Bob"));doc.add(new FacetField("Publish Date", "2010", "10", "15"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Lisa"));doc.add(new FacetField("Publish Date", "2010", "10", "20"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Lisa"));doc.add(new FacetField("Publish Date", "2012", "1", "1"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Susan"));doc.add(new FacetField("Publish Date", "2012", "1", "7"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Frank"));doc.add(new FacetField("Publish Date", "1999", "5", "5"));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));indexWriter.close();taxoWriter.close();@@ -103,14 +97,13 @@ public class SimpleFacetsExample {DirectoryReader indexReader = DirectoryReader.open(indexDir);IndexSearcher searcher = new IndexSearcher(indexReader);TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);- FacetsConfig config = getConfig(null);FacetsCollector fc = new FacetsCollector();// MatchAllDocsQuery is for "browsing" (counts facets// for all non-deleted docs in the index); normally// you'd use a "normal" query:- Facets.search(searcher, new MatchAllDocsQuery(), 10, fc);+ FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);// Retrieve resultsList<FacetResult> results = new ArrayList<FacetResult>();@@ -131,7 +124,6 @@ public class SimpleFacetsExample {DirectoryReader indexReader = DirectoryReader.open(indexDir);IndexSearcher searcher = new IndexSearcher(indexReader);TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);- FacetsConfig config = getConfig(null);// Passing no baseQuery means we drill down on all// documents ("browse only"):@@ -140,7 +132,7 @@ public class SimpleFacetsExample {// Now user drills down on Publish Date/2010:q.add("Publish Date", "2010");FacetsCollector fc = new FacetsCollector();- Facets.search(searcher, q, 10, fc);+ FacetsCollector.search(searcher, q, 10, fc);// Retrieve resultsFacets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);diff --git a/lucene/demo/src/java/org/apache/lucene/demo/facet/SimpleSortedSetFacetsExample.java b/lucene/demo/src/java/org/apache/lucene/demo/facet/SimpleSortedSetFacetsExample.javaindex 5f6d1901b00..3493c0a6835 100644--- a/lucene/demo/src/java/org/apache/lucene/demo/facet/SimpleSortedSetFacetsExample.java+++ b/lucene/demo/src/java/org/apache/lucene/demo/facet/SimpleSortedSetFacetsExample.java@@ -47,19 +47,16 @@ import org.apache.lucene.store.RAMDirectory;public class SimpleSortedSetFacetsExample {private final Directory indexDir = new RAMDirectory();+ private final FacetsConfig config = new FacetsConfig();/** Empty constructor */- public SimpleSortedSetFacetsExample() {}-- private FacetsConfig getConfig() {- return new FacetsConfig();+ public SimpleSortedSetFacetsExample() {}/** Build the example index. */private void index() throws IOException {IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig(FacetExamples.EXAMPLES_VER,new WhitespaceAnalyzer(FacetExamples.EXAMPLES_VER)));- FacetsConfig config = getConfig();Document doc = new Document();doc.add(new SortedSetDocValuesFacetField("Author", "Bob"));doc.add(new SortedSetDocValuesFacetField("Publish Year", "2010"));@@ -93,7 +90,6 @@ public class SimpleSortedSetFacetsExample {DirectoryReader indexReader = DirectoryReader.open(indexDir);IndexSearcher searcher = new IndexSearcher(indexReader);SortedSetDocValuesReaderState state = new SortedSetDocValuesReaderState(indexReader);- FacetsConfig config = getConfig();// Aggregatses the facet countsFacetsCollector fc = new FacetsCollector();@@ -101,7 +97,7 @@ public class SimpleSortedSetFacetsExample {// MatchAllDocsQuery is for "browsing" (counts facets// for all non-deleted docs in the index); normally// you'd use a "normal" query:- Facets.search(searcher, new MatchAllDocsQuery(), 10, fc);+ FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);// Retrieve resultsFacets facets = new SortedSetDocValuesFacetCounts(state, fc);@@ -119,13 +115,12 @@ public class SimpleSortedSetFacetsExample {DirectoryReader indexReader = DirectoryReader.open(indexDir);IndexSearcher searcher = new IndexSearcher(indexReader);SortedSetDocValuesReaderState state = new SortedSetDocValuesReaderState(indexReader);- FacetsConfig config = getConfig();// Now user drills down on Publish Year/2010:DrillDownQuery q = new DrillDownQuery(config);q.add("Publish Year", "2010");FacetsCollector fc = new FacetsCollector();- Facets.search(searcher, q, 10, fc);+ FacetsCollector.search(searcher, q, 10, fc);// Retrieve resultsFacets facets = new SortedSetDocValuesFacetCounts(state, fc);diff --git a/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.java b/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.javaindex 41e08a85a73..f8f74d78e38 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.java@@ -148,12 +148,6 @@ public final class DrillDownQuery extends Query {String indexedField = config.getDimConfig(dim).indexFieldName;BooleanQuery bq = new BooleanQuery(true); // disable coord- // nocommit too anal?- /*- if (path.length == 0) {- throw new IllegalArgumentException("must have at least one facet label under dim");- }- */bq.add(new TermQuery(term(indexedField, dim, path)), Occur.SHOULD);add(dim, bq);diff --git a/lucene/facet/src/java/org/apache/lucene/facet/FacetResult.java b/lucene/facet/src/java/org/apache/lucene/facet/FacetResult.javaindex efa204e38e3..7cbcae9d04f 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/FacetResult.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/FacetResult.java@@ -64,5 +64,12 @@ public final class FacetResult {Arrays.equals(labelValues, other.labelValues);}- // nocommit hashCode+ @Override+ public int hashCode() {+ int hashCode = value.hashCode() + 31 * childCount;+ for(LabelAndValue labelValue : labelValues) {+ hashCode = labelValue.hashCode() + 31 * hashCode;+ }+ return hashCode;+ }}diff --git a/lucene/facet/src/java/org/apache/lucene/facet/Facets.java b/lucene/facet/src/java/org/apache/lucene/facet/Facets.javaindex 330115c8095..b44ead21265 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/Facets.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/Facets.java@@ -54,109 +54,4 @@ public abstract class Facets {* different dimensions were indexed, for example* depending on the type of document. */public abstract List<FacetResult> getAllDims(int topN) throws IOException;-- // nocommit where to put these utility methods?-- /** Utility method, to search and also collect all hits- * into the provided {@link FacetsCollector}. */- public static TopDocs search(IndexSearcher searcher, Query q, int n, FacetsCollector fc) throws IOException {- return doSearch(searcher, null, q, null, n, null, false, false, fc);- }-- /** Utility method, to search and also collect all hits- * into the provided {@link FacetsCollector}. */- public static TopDocs search(IndexSearcher searcher, Query q, Filter filter, int n, FacetsCollector fc) throws IOException {- return doSearch(searcher, null, q, filter, n, null, false, false, fc);- }-- /** Utility method, to search and also collect all hits- * into the provided {@link FacetsCollector}. */- public static TopFieldDocs search(IndexSearcher searcher, Query q, Filter filter, int n, Sort sort, FacetsCollector fc) throws IOException {- if (sort == null) {- throw new IllegalArgumentException("sort must not be null");- }- return (TopFieldDocs) doSearch(searcher, null, q, filter, n, sort, false, false, fc);- }-- /** Utility method, to search and also collect all hits- * into the provided {@link FacetsCollector}. */- public static TopFieldDocs search(IndexSearcher searcher, Query q, Filter filter, int n, Sort sort, boolean doDocScores, boolean doMaxScore, FacetsCollector fc) throws IOException {- if (sort == null) {- throw new IllegalArgumentException("sort must not be null");- }- return (TopFieldDocs) doSearch(searcher, null, q, filter, n, sort, doDocScores, doMaxScore, fc);- }-- /** Utility method, to search and also collect all hits- * into the provided {@link FacetsCollector}. */- public TopDocs searchAfter(IndexSearcher searcher, ScoreDoc after, Query q, int n, FacetsCollector fc) throws IOException {- return doSearch(searcher, after, q, null, n, null, false, false, fc);- }-- /** Utility method, to search and also collect all hits- * into the provided {@link FacetsCollector}. */- public static TopDocs searchAfter(IndexSearcher searcher, ScoreDoc after, Query q, Filter filter, int n, FacetsCollector fc) throws IOException {- return doSearch(searcher, after, q, filter, n, null, false, false, fc);- }-- /** Utility method, to search and also collect all hits- * into the provided {@link FacetsCollector}. */- public static TopDocs searchAfter(IndexSearcher searcher, ScoreDoc after, Query q, Filter filter, int n, Sort sort, FacetsCollector fc) throws IOException {- if (sort == null) {- throw new IllegalArgumentException("sort must not be null");- }- return (TopFieldDocs) doSearch(searcher, after, q, filter, n, sort, false, false, fc);- }-- /** Utility method, to search and also collect all hits- * into the provided {@link FacetsCollector}. */- public static TopDocs searchAfter(IndexSearcher searcher, ScoreDoc after, Query q, Filter filter, int n, Sort sort, boolean doDocScores, boolean doMaxScore, FacetsCollector fc) throws IOException {- if (sort == null) {- throw new IllegalArgumentException("sort must not be null");- }- return (TopFieldDocs) doSearch(searcher, after, q, filter, n, sort, doDocScores, doMaxScore, fc);- }-- private static TopDocs doSearch(IndexSearcher searcher, ScoreDoc after, Query q, Filter filter, int n, Sort sort,- boolean doDocScores, boolean doMaxScore, FacetsCollector fc) throws IOException {-- if (filter != null) {- q = new FilteredQuery(q, filter);- }-- int limit = searcher.getIndexReader().maxDoc();- if (limit == 0) {- limit = 1;- }- n = Math.min(n, limit);-- if (after != null && after.doc >= limit) {- throw new IllegalArgumentException("after.doc exceeds the number of documents in the reader: after.doc="- + after.doc + " limit=" + limit);- }-- TopDocsCollector<?> hitsCollector;- if (sort != null) {- if (after != null && !(after instanceof FieldDoc)) {- // TODO: if we fix type safety of TopFieldDocs we can- // remove this- throw new IllegalArgumentException("after must be a FieldDoc; got " + after);- }- boolean fillFields = true;- hitsCollector = TopFieldCollector.create(sort, n,- (FieldDoc) after,- fillFields,- doDocScores,- doMaxScore,- false);- } else {- // TODO: can we pass the right boolean for- // in-order instead of hardwired to false...? we'd- // need access to the protected IS.search methods- // taking Weight... could use reflection...- hitsCollector = TopScoreDocCollector.create(n, after, false);- }- searcher.search(q, MultiCollector.wrap(hitsCollector, fc));- return hitsCollector.topDocs();- }}diff --git a/lucene/facet/src/java/org/apache/lucene/facet/FacetsCollector.java b/lucene/facet/src/java/org/apache/lucene/facet/FacetsCollector.javaindex 715ee0ebf51..7836139bdb8 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/FacetsCollector.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/FacetsCollector.java@@ -26,11 +26,29 @@ import org.apache.lucene.facet.taxonomy.TaxonomyReader;import org.apache.lucene.index.AtomicReaderContext;import org.apache.lucene.index.IndexReader;import org.apache.lucene.search.Collector;+import org.apache.lucene.search.FieldDoc;+import org.apache.lucene.search.Filter;+import org.apache.lucene.search.FilteredQuery;+import org.apache.lucene.search.IndexSearcher;+import org.apache.lucene.search.MultiCollector;+import org.apache.lucene.search.Query;+import org.apache.lucene.search.ScoreDoc;import org.apache.lucene.search.Scorer;+import org.apache.lucene.search.Sort;+import org.apache.lucene.search.TopDocs;+import org.apache.lucene.search.TopDocsCollector;+import org.apache.lucene.search.TopFieldCollector;+import org.apache.lucene.search.TopFieldDocs;+import org.apache.lucene.search.TopScoreDocCollector;import org.apache.lucene.util.ArrayUtil;import org.apache.lucene.util.FixedBitSet;-// nocommit javadocs+/** Collects hits for subsequent faceting. Once you've run+ * a search and collect hits into this, instantiate one of+ * the {@link Facets} subclasses to do the facet+ * counting. Use the {@code search} utility methods to+ * perform an "ordinary" search but also collect into a+ * {@link Collector}. */public final class FacetsCollector extends Collector {private AtomicReaderContext context;@@ -89,8 +107,10 @@ public final class FacetsCollector extends Collector {@Overridepublic final boolean acceptsDocsOutOfOrder() {- // nocommit why not true?- return false;+ // If we are keeping scores then we require in-order+ // because we append each score to the float[] and+ // expect that they correlate in order to the hits:+ return keepScores == false;}@Override@@ -124,4 +144,107 @@ public final class FacetsCollector extends Collector {}this.context = context;}++ /** Utility method, to search and also collect all hits+ * into the provided {@link Collector}. */+ public static TopDocs search(IndexSearcher searcher, Query q, int n, Collector fc) throws IOException {+ return doSearch(searcher, null, q, null, n, null, false, false, fc);+ }++ /** Utility method, to search and also collect all hits+ * into the provided {@link Collector}. */+ public static TopDocs search(IndexSearcher searcher, Query q, Filter filter, int n, Collector fc) throws IOException {+ return doSearch(searcher, null, q, filter, n, null, false, false, fc);+ }++ /** Utility method, to search and also collect all hits+ * into the provided {@link Collector}. */+ public static TopFieldDocs search(IndexSearcher searcher, Query q, Filter filter, int n, Sort sort, Collector fc) throws IOException {+ if (sort == null) {+ throw new IllegalArgumentException("sort must not be null");+ }+ return (TopFieldDocs) doSearch(searcher, null, q, filter, n, sort, false, false, fc);+ }++ /** Utility method, to search and also collect all hits+ * into the provided {@link Collector}. */+ public static TopFieldDocs search(IndexSearcher searcher, Query q, Filter filter, int n, Sort sort, boolean doDocScores, boolean doMaxScore, Collector fc) throws IOException {+ if (sort == null) {+ throw new IllegalArgumentException("sort must not be null");+ }+ return (TopFieldDocs) doSearch(searcher, null, q, filter, n, sort, doDocScores, doMaxScore, fc);+ }++ /** Utility method, to search and also collect all hits+ * into the provided {@link Collector}. */+ public TopDocs searchAfter(IndexSearcher searcher, ScoreDoc after, Query q, int n, Collector fc) throws IOException {+ return doSearch(searcher, after, q, null, n, null, false, false, fc);+ }++ /** Utility method, to search and also collect all hits+ * into the provided {@link Collector}. */+ public static TopDocs searchAfter(IndexSearcher searcher, ScoreDoc after, Query q, Filter filter, int n, Collector fc) throws IOException {+ return doSearch(searcher, after, q, filter, n, null, false, false, fc);+ }++ /** Utility method, to search and also collect all hits+ * into the provided {@link Collector}. */+ public static TopDocs searchAfter(IndexSearcher searcher, ScoreDoc after, Query q, Filter filter, int n, Sort sort, Collector fc) throws IOException {+ if (sort == null) {+ throw new IllegalArgumentException("sort must not be null");+ }+ return (TopFieldDocs) doSearch(searcher, after, q, filter, n, sort, false, false, fc);+ }++ /** Utility method, to search and also collect all hits+ * into the provided {@link Collector}. */+ public static TopDocs searchAfter(IndexSearcher searcher, ScoreDoc after, Query q, Filter filter, int n, Sort sort, boolean doDocScores, boolean doMaxScore, Collector fc) throws IOException {+ if (sort == null) {+ throw new IllegalArgumentException("sort must not be null");+ }+ return (TopFieldDocs) doSearch(searcher, after, q, filter, n, sort, doDocScores, doMaxScore, fc);+ }++ private static TopDocs doSearch(IndexSearcher searcher, ScoreDoc after, Query q, Filter filter, int n, Sort sort,+ boolean doDocScores, boolean doMaxScore, Collector fc) throws IOException {++ if (filter != null) {+ q = new FilteredQuery(q, filter);+ }++ int limit = searcher.getIndexReader().maxDoc();+ if (limit == 0) {+ limit = 1;+ }+ n = Math.min(n, limit);++ if (after != null && after.doc >= limit) {+ throw new IllegalArgumentException("after.doc exceeds the number of documents in the reader: after.doc="+ + after.doc + " limit=" + limit);+ }++ TopDocsCollector<?> hitsCollector;+ if (sort != null) {+ if (after != null && !(after instanceof FieldDoc)) {+ // TODO: if we fix type safety of TopFieldDocs we can+ // remove this+ throw new IllegalArgumentException("after must be a FieldDoc; got " + after);+ }+ boolean fillFields = true;+ hitsCollector = TopFieldCollector.create(sort, n,+ (FieldDoc) after,+ fillFields,+ doDocScores,+ doMaxScore,+ false);+ } else {+ // TODO: can we pass the right boolean for+ // in-order instead of hardwired to false...? we'd+ // need access to the protected IS.search methods+ // taking Weight... could use reflection...+ hitsCollector = TopScoreDocCollector.create(n, after, false);+ }+ searcher.search(q, MultiCollector.wrap(hitsCollector, fc));+ return hitsCollector.topDocs();+ }}diff --git a/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java b/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.javaindex f1d02fab192..5af6034da23 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java@@ -63,26 +63,23 @@ public class FacetsConfig {// int/float/bytes in a single indexed field:private final Map<String,String> assocDimTypes = new ConcurrentHashMap<String,String>();- private final TaxonomyWriter taxoWriter;-/** Holds the configuration for one dimension** @lucene.experimental */- // nocommit expose this to the user, vs the setters?public static final class DimConfig {/** True if this dimension is hierarchical. */- boolean hierarchical;+ public boolean hierarchical;/** True if this dimension is multi-valued. */- boolean multiValued;+ public boolean multiValued;/** True if the count/aggregate for the entire dimension* is required, which is unusual (default is false). */- boolean requireDimCount;+ public boolean requireDimCount;/** Actual field where this dimension's facet labels* should be indexed */- String indexFieldName = DEFAULT_INDEX_FIELD_NAME;+ public String indexFieldName = DEFAULT_INDEX_FIELD_NAME;}/** Default per-dimension configuration. */@@ -90,18 +87,10 @@ public class FacetsConfig {/** Default constructor. */public FacetsConfig() {- this(null);- }-- /** Use this constructor at index time, with the provided- * {@link TaxonomyWriter}, and then use the {@link- * #build} method to index documents. */- public FacetsConfig(TaxonomyWriter taxoWriter) {- this.taxoWriter = taxoWriter;}/** Get the current configuration for a dimension. */- public DimConfig getDimConfig(String dimName) {+ public synchronized DimConfig getDimConfig(String dimName) {DimConfig ft = fieldTypes.get(dimName);if (ft == null) {ft = DEFAULT_DIM_CONFIG;@@ -155,7 +144,7 @@ public class FacetsConfig {ft.indexFieldName = indexFieldName;}- Map<String,DimConfig> getDimConfigs() {+ public Map<String,DimConfig> getDimConfigs() {return fieldTypes;}@@ -167,8 +156,16 @@ public class FacetsConfig {}/** Translates any added {@link FacetField}s into normal- * fields for indexing. */+ * fields for indexing; only use this version if you+ * did not add any taxonomy-based fields ({@link+ * FacetField} or {@link AssociationFacetField}) */public IndexDocument build(IndexDocument doc) throws IOException {+ return build(null, doc);+ }++ /** Translates any added {@link FacetField}s into normal+ * fields for indexing. */+ public IndexDocument build(TaxonomyWriter taxoWriter, IndexDocument doc) throws IOException {// Find all FacetFields, collated by the actual field:Map<String,List<FacetField>> byField = new HashMap<String,List<FacetField>>();@@ -255,9 +252,9 @@ public class FacetsConfig {List<Field> addedIndexedFields = new ArrayList<Field>();List<Field> addedStoredFields = new ArrayList<Field>();- processFacetFields(byField, addedIndexedFields, addedStoredFields);+ processFacetFields(taxoWriter, byField, addedIndexedFields, addedStoredFields);processSSDVFacetFields(dvByField, addedIndexedFields, addedStoredFields);- processAssocFacetFields(assocByField, addedIndexedFields, addedStoredFields);+ processAssocFacetFields(taxoWriter, assocByField, addedIndexedFields, addedStoredFields);//System.out.println("add stored: " + addedStoredFields);@@ -292,7 +289,7 @@ public class FacetsConfig {};}- private void processFacetFields(Map<String,List<FacetField>> byField, List<Field> addedIndexedFields, List<Field> addedStoredFields) throws IOException {+ private void processFacetFields(TaxonomyWriter taxoWriter, Map<String,List<FacetField>> byField, List<Field> addedIndexedFields, List<Field> addedStoredFields) throws IOException {for(Map.Entry<String,List<FacetField>> ent : byField.entrySet()) {@@ -307,9 +304,9 @@ public class FacetsConfig {throw new IllegalArgumentException("dimension \"" + facetField.dim + "\" is not hierarchical yet has " + facetField.path.length + " components");}- FacetLabel cp = FacetLabel.create(facetField.dim, facetField.path);+ FacetLabel cp = new FacetLabel(facetField.dim, facetField.path);- checkTaxoWriter();+ checkTaxoWriter(taxoWriter);int ordinal = taxoWriter.addCategory(cp);if (ordinals.length == ordinals.ints.length) {ordinals.grow(ordinals.length+1);@@ -368,7 +365,7 @@ public class FacetsConfig {}}- private void processAssocFacetFields(Map<String,List<AssociationFacetField>> byField,+ private void processAssocFacetFields(TaxonomyWriter taxoWriter, Map<String,List<AssociationFacetField>> byField,List<Field> addedIndexedFields, List<Field> addedStoredFields) throws IOException {for(Map.Entry<String,List<AssociationFacetField>> ent : byField.entrySet()) {byte[] bytes = new byte[16];@@ -379,8 +376,8 @@ public class FacetsConfig {// nocommit is that right? maybe we are supposed to// add to taxo writer, and just not index the parent// ords?- checkTaxoWriter();- int ordinal = taxoWriter.addCategory(FacetLabel.create(field.dim, field.path));+ checkTaxoWriter(taxoWriter);+ int ordinal = taxoWriter.addCategory(new FacetLabel(field.dim, field.path));if (upto + 4 > bytes.length) {bytes = ArrayUtil.grow(bytes, upto+4);}@@ -448,9 +445,9 @@ public class FacetsConfig {return new BytesRef(bytes, 0, upto);}- private void checkTaxoWriter() {+ private void checkTaxoWriter(TaxonomyWriter taxoWriter) {if (taxoWriter == null) {- throw new IllegalStateException("a valid TaxonomyWriter must be provided to the constructor (got null), when using FacetField or AssociationFacetField");+ throw new IllegalStateException("a non-null TaxonomyWriter must be provided when indexing FacetField or AssociationFacetField");}}@@ -476,14 +473,6 @@ public class FacetsConfig {/** Turns the first {@code} length elements of {@code* path} into an encoded string. */public static String pathToString(String[] path, int length) {- // nocommit .... too anal? shouldn't we allow drill- // down on just dim, to get all docs that have that- // dim...?- /*- if (path.length < 2) {- throw new IllegalArgumentException("path length must be > 0 (dim=" + path[0] + ")");- }- */if (length == 0) {return "";}diff --git a/lucene/facet/src/java/org/apache/lucene/facet/FastTaxonomyFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/FastTaxonomyFacetCounts.javaindex 6fb61145713..4d151a79eb7 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/FastTaxonomyFacetCounts.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/FastTaxonomyFacetCounts.java@@ -59,9 +59,7 @@ public class FastTaxonomyFacetCounts extends IntTaxonomyFacets {final int length = hits.bits.length();int doc = 0;BytesRef scratch = new BytesRef();- //System.out.println("count seg=" + hits.context.reader());while (doc < length && (doc = bits.nextSetBit(doc)) != -1) {- //System.out.println(" doc=" + doc);dv.get(doc, scratch);byte[] bytes = scratch.bytes;int end = scratch.offset + scratch.length;@@ -72,7 +70,6 @@ public class FastTaxonomyFacetCounts extends IntTaxonomyFacets {byte b = bytes[offset++];if (b >= 0) {prev = ord = ((ord << 7) | b) + prev;- assert ord < values.length: "ord=" + ord + " vs maxOrd=" + values.length;++values[ord];ord = 0;} else {diff --git a/lucene/facet/src/java/org/apache/lucene/facet/FloatTaxonomyFacets.java b/lucene/facet/src/java/org/apache/lucene/facet/FloatTaxonomyFacets.javaindex 9356906cdb5..8f89a67c963 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/FloatTaxonomyFacets.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/FloatTaxonomyFacets.java@@ -62,7 +62,7 @@ public abstract class FloatTaxonomyFacets extends TaxonomyFacets {@Overridepublic Number getSpecificValue(String dim, String... path) throws IOException {verifyDim(dim);- int ord = taxoReader.getOrdinal(FacetLabel.create(dim, path));+ int ord = taxoReader.getOrdinal(new FacetLabel(dim, path));if (ord < 0) {return -1;}@@ -75,7 +75,7 @@ public abstract class FloatTaxonomyFacets extends TaxonomyFacets {throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")");}FacetsConfig.DimConfig dimConfig = verifyDim(dim);- FacetLabel cp = FacetLabel.create(dim, path);+ FacetLabel cp = new FacetLabel(dim, path);int dimOrd = taxoReader.getOrdinal(cp);if (dimOrd == -1) {return null;diff --git a/lucene/facet/src/java/org/apache/lucene/facet/IntTaxonomyFacets.java b/lucene/facet/src/java/org/apache/lucene/facet/IntTaxonomyFacets.javaindex 6ff76cf9954..7289a0e2ce4 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/IntTaxonomyFacets.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/IntTaxonomyFacets.java@@ -65,7 +65,7 @@ public abstract class IntTaxonomyFacets extends TaxonomyFacets {@Overridepublic Number getSpecificValue(String dim, String... path) throws IOException {verifyDim(dim);- int ord = taxoReader.getOrdinal(FacetLabel.create(dim, path));+ int ord = taxoReader.getOrdinal(new FacetLabel(dim, path));if (ord < 0) {return -1;}@@ -78,7 +78,7 @@ public abstract class IntTaxonomyFacets extends TaxonomyFacets {throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")");}FacetsConfig.DimConfig dimConfig = verifyDim(dim);- FacetLabel cp = FacetLabel.create(dim, path);+ FacetLabel cp = new FacetLabel(dim, path);int dimOrd = taxoReader.getOrdinal(cp);if (dimOrd == -1) {return null;diff --git a/lucene/facet/src/java/org/apache/lucene/facet/LabelAndValue.java b/lucene/facet/src/java/org/apache/lucene/facet/LabelAndValue.javaindex 5656a28b8b8..88b871a8b24 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/LabelAndValue.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/LabelAndValue.java@@ -18,7 +18,7 @@ package org.apache.lucene.facet;*/public final class LabelAndValue {- // nocommit BytesRef?+ /** Facet's label. */public final String label;/** Value associated with this label. */diff --git a/lucene/facet/src/java/org/apache/lucene/facet/LongRange.java b/lucene/facet/src/java/org/apache/lucene/facet/LongRange.javaindex bb83d80fe13..0ed21db3dd9 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/LongRange.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/LongRange.java@@ -30,7 +30,7 @@ public final class LongRange extends Range {public final boolean minInclusive;public final boolean maxInclusive;- // nocommit can we require fewer args? (same for+ // TODO: can we require fewer args? (same for// Double/FloatRange too)/** Create a LongRange. */diff --git a/lucene/facet/src/java/org/apache/lucene/facet/SortedSetDocValuesFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/SortedSetDocValuesFacetCounts.javaindex 616f32efcb0..04aba8404b3 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/SortedSetDocValuesFacetCounts.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/SortedSetDocValuesFacetCounts.java@@ -49,8 +49,9 @@ import org.apache.lucene.util.PriorityQueue;* label) facets, but it uses quite a bit less RAM to do* so.*- * After creating this class, invoke {@link #getDim} or- * {@link #getAllDims} to retrieve facet results. */+ * <p><b>NOTE</b>: this class should be instantiated and+ * then used from a single thread, because it holds a+ * thread-private instance of {@link SortedSetDocValues}. */public class SortedSetDocValuesFacetCounts extends Facets {@@ -167,8 +168,6 @@ public class SortedSetDocValuesFacetCounts extends Facets {SortedSetDocValues segValues = reader.getSortedSetDocValues(field);if (segValues == null) {- // nocommit in trunk this was a "return" which is- // wrong; make a failing testcontinue;}@@ -176,7 +175,7 @@ public class SortedSetDocValuesFacetCounts extends Facets {assert maxDoc == hits.bits.length();//System.out.println(" dv=" + dv);- // nocommit, yet another option is to count all segs+ // TODO: yet another option is to count all segs// first, only in seg-ord space, and then do a// merge-sort-PQ in the end to only "resolve to// global" those seg ords that can compete, if we know@@ -255,8 +254,6 @@ public class SortedSetDocValuesFacetCounts extends Facets {if (path.length != 1) {throw new IllegalArgumentException("path must be length=1");}- // nocommit this is not thread safe in general? add- // jdocs that app must instantiate & use from same thread?int ord = (int) dv.lookupTerm(new BytesRef(FacetsConfig.pathToString(dim, path)));if (ord < 0) {return -1;diff --git a/lucene/facet/src/java/org/apache/lucene/facet/TaxonomyFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/TaxonomyFacetCounts.javaindex 84037aa458d..40c11e5b785 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/TaxonomyFacetCounts.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/TaxonomyFacetCounts.java@@ -27,12 +27,10 @@ import org.apache.lucene.util.FixedBitSet;import org.apache.lucene.util.IntsRef;/** Reads from any {@link OrdinalsReader}; use {@link- * FastTaxonomyFacetCounts} if you are just using the+ * FastTaxonomyFacetCounts} if you are using the* default encoding from {@link BinaryDocValues}.** @lucene.experimental */--// nocommit remove & add specialized Cached variation only?public class TaxonomyFacetCounts extends IntTaxonomyFacets {private final OrdinalsReader ordinalsReader;diff --git a/lucene/facet/src/java/org/apache/lucene/facet/TaxonomyFacets.java b/lucene/facet/src/java/org/apache/lucene/facet/TaxonomyFacets.javaindex b35575a0be3..85bb7e9707d 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/TaxonomyFacets.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/TaxonomyFacets.java@@ -46,7 +46,6 @@ public abstract class TaxonomyFacets extends Facets {protected FacetsConfig.DimConfig verifyDim(String dim) {FacetsConfig.DimConfig dimConfig = config.getDimConfig(dim);if (!dimConfig.indexFieldName.equals(indexFieldName)) {- // nocommit get test case to cover this:throw new IllegalArgumentException("dimension \"" + dim + "\" was not indexed into field \"" + indexFieldName);}return dimConfig;diff --git a/lucene/facet/src/java/org/apache/lucene/facet/TopOrdAndFloatQueue.java b/lucene/facet/src/java/org/apache/lucene/facet/TopOrdAndFloatQueue.javaindex 9514c06de05..af9fecf9ed4 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/TopOrdAndFloatQueue.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/TopOrdAndFloatQueue.java@@ -19,8 +19,6 @@ package org.apache.lucene.facet;import org.apache.lucene.util.PriorityQueue;-// nocommit make value a double and merge with TopOrdCountValueQueue?-/** Keeps highest results, first by largest float value,* then tie break by smallest ord. */class TopOrdAndFloatQueue extends PriorityQueue<TopOrdAndFloatQueue.OrdAndValue> {diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FacetLabel.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FacetLabel.javaindex e793d41bcf2..cc4662ff0ed 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FacetLabel.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FacetLabel.java@@ -76,6 +76,21 @@ public class FacetLabel implements Comparable<FacetLabel> {/** Construct from the given path components. */public FacetLabel(final String... components) {+ this.components = components;+ length = components.length;+ checkComponents();+ }++ /** Construct from the dimension plus the given path components. */+ public FacetLabel(String dim, String[] path) {+ components = new String[1+path.length];+ components[0] = dim;+ System.arraycopy(path, 0, components, 1, path.length);+ length = components.length;+ checkComponents();+ }++ private void checkComponents() {// nocommit why so anal?// assert components.length > 0 : "use CategoryPath.EMPTY to create an empty path";long len = 0;@@ -91,16 +106,6 @@ public class FacetLabel implements Comparable<FacetLabel> {+ MAX_CATEGORY_PATH_LENGTH + " len=" + len+ " path=" + Arrays.toString(components).substring(0, 30) + "...");}- this.components = components;- length = components.length;- }-- // nocommit javadocs/rename- public static FacetLabel create(String dim, String... path) {- String[] components = new String[1+path.length];- components[0] = dim;- System.arraycopy(path, 0, components, 1, path.length);- return new FacetLabel(components);}/**diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.javaindex 716dbaa63e8..921f5b201bc 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.java@@ -216,6 +216,13 @@ public abstract class TaxonomyReader implements Closeable {* wasn't foun.*/public abstract int getOrdinal(FacetLabel categoryPath) throws IOException;++ public int getOrdinal(String dim, String[] path) throws IOException {+ String[] fullPath = new String[path.length+1];+ fullPath[0] = dim;+ System.arraycopy(path, 0, fullPath, 1, path.length);+ return getOrdinal(new FacetLabel(fullPath));+ }/** Returns the path name of the category with the given ordinal. */public abstract FacetLabel getPath(int ordinal) throws IOException;diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestCachedOrdinalsReader.java b/lucene/facet/src/test/org/apache/lucene/facet/TestCachedOrdinalsReader.javaindex 5b6fb56dd16..a42d615cb40 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/TestCachedOrdinalsReader.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestCachedOrdinalsReader.java@@ -40,14 +40,14 @@ public class TestCachedOrdinalsReader extends FacetTestCase {IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));IndexWriter writer = new IndexWriter(indexDir, conf);DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();Document doc = new Document();doc.add(new FacetField("A", "1"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("A", "2"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));final DirectoryReader reader = DirectoryReader.open(writer, true);final CachedOrdinalsReader ordsReader = new CachedOrdinalsReader(new DocValuesOrdinalsReader(FacetsConfig.DEFAULT_INDEX_FIELD_NAME));diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillDownQuery.java b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillDownQuery.javaindex 263c11407aa..fc946c262ec 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillDownQuery.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillDownQuery.java@@ -70,7 +70,7 @@ public class TestDrillDownQuery extends FacetTestCase {taxoDir = newDirectory();TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);- config = new FacetsConfig(taxoWriter);+ config = new FacetsConfig();// Randomize the per-dim config:config.setHierarchical("a", random().nextBoolean());@@ -105,7 +105,7 @@ public class TestDrillDownQuery extends FacetTestCase {if (i % 5 == 0) { // 20doc.add(new FacetField("b", "1"));}- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));}taxoWriter.close();diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.javaindex 65f96b149f5..cb48ef3436b 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java@@ -72,7 +72,7 @@ public class TestDrillSideways extends FacetTestCase {// main index:DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setHierarchical("Publish Date", true);RandomIndexWriter writer = new RandomIndexWriter(random(), dir);@@ -80,27 +80,27 @@ public class TestDrillSideways extends FacetTestCase {Document doc = new Document();doc.add(new FacetField("Author", "Bob"));doc.add(new FacetField("Publish Date", "2010", "10", "15"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Lisa"));doc.add(new FacetField("Publish Date", "2010", "10", "20"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Lisa"));doc.add(new FacetField("Publish Date", "2012", "1", "1"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Susan"));doc.add(new FacetField("Publish Date", "2012", "1", "7"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Frank"));doc.add(new FacetField("Publish Date", "1999", "5", "5"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -244,18 +244,18 @@ public class TestDrillSideways extends FacetTestCase {// main index:DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setHierarchical("Publish Date", true);Document doc = new Document();doc.add(new FacetField("Author", "Bob"));doc.add(new FacetField("Publish Date", "2010", "10", "15"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Lisa"));doc.add(new FacetField("Publish Date", "2010", "10", "20"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));writer.commit();@@ -263,7 +263,7 @@ public class TestDrillSideways extends FacetTestCase {doc = new Document();doc.add(new FacetField("Foobar", "Lisa"));doc.add(new FacetField("Publish Date", "2012", "1", "1"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -298,32 +298,32 @@ public class TestDrillSideways extends FacetTestCase {// main index:DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setHierarchical("dim", true);Document doc = new Document();doc.add(new FacetField("dim", "a", "x"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("dim", "a", "y"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("dim", "a", "z"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("dim", "b"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("dim", "c"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("dim", "d"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -474,7 +474,7 @@ public class TestDrillSideways extends FacetTestCase {iwc.setInfoStream(InfoStream.NO_OUTPUT);RandomIndexWriter w = new RandomIndexWriter(random(), d, iwc);DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(td, IndexWriterConfig.OpenMode.CREATE);- FacetsConfig config = new FacetsConfig(tw);+ FacetsConfig config = new FacetsConfig();for(int i=0;i<numDims;i++) {config.setMultiValued("dim"+i, true);}@@ -516,7 +516,7 @@ public class TestDrillSideways extends FacetTestCase {}}- w.addDocument(config.build(doc));+ w.addDocument(config.build(tw, doc));}if (random().nextBoolean()) {@@ -702,12 +702,30 @@ public class TestDrillSideways extends FacetTestCase {TestFacetResult expected = slowDrillSidewaysSearch(s, docs, contentToken, drillDowns, dimValues, filter);Sort sort = new Sort(new SortField("id", SortField.Type.STRING));- // nocommit subclass & override to use FacetsTestCase.getFacetCountsDrillSideways ds;if (doUseDV) {ds = new DrillSideways(s, config, sortedSetDVState);} else {- ds = new DrillSideways(s, config, tr);+ ds = new DrillSideways(s, config, tr) {+ @Override+ protected Facets buildFacetsResult(FacetsCollector drillDowns, FacetsCollector[] drillSideways, String[] drillSidewaysDims) throws IOException {+ Map<String,Facets> drillSidewaysFacets = new HashMap<String,Facets>();+ Facets drillDownFacets = getTaxonomyFacetCounts(taxoReader, config, drillDowns);+ if (drillSideways != null) {+ for(int i=0;i<drillSideways.length;i++) {+ drillSidewaysFacets.put(drillSidewaysDims[i],+ getTaxonomyFacetCounts(taxoReader, config, drillSideways[i]));+ }+ }++ if (drillSidewaysFacets.isEmpty()) {+ return drillDownFacets;+ } else {+ return new MultiFacets(drillSidewaysFacets, drillDownFacets);+ }++ }+ };}// Retrieve all facets:@@ -954,6 +972,7 @@ public class TestDrillSideways extends FacetTestCase {idx++;}}+ assertEquals("dim=" + dim, expected.uniqueCounts[dim], fr.childCount);}if (topN < dimValues[dim].length) {@@ -1013,9 +1032,6 @@ public class TestDrillSideways extends FacetTestCase {}assertEquals(setCount, actualValues.size());}-- // nocommit if we add this to FR then re-enable this:- // assertEquals("dim=" + dim, expected.uniqueCounts[dim], fr.getNumValidDescendants());}}diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestMultipleIndexFields.java b/lucene/facet/src/test/org/apache/lucene/facet/TestMultipleIndexFields.javaindex 3bc4670033f..22a281e20a1 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/TestMultipleIndexFields.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestMultipleIndexFields.java@@ -64,10 +64,8 @@ public class TestMultipleIndexFields extends FacetTestCase {new FacetField("Composer", "Bach"),};- private FacetsConfig getConfig(TaxonomyWriter taxoWriter) {- FacetsConfig config = new FacetsConfig(taxoWriter);- //config.setMultiValued("Author", true);- //config.setMultiValued("Band", true);+ private FacetsConfig getConfig() {+ FacetsConfig config = new FacetsConfig();config.setHierarchical("Band", true);return config;}@@ -82,9 +80,9 @@ public class TestMultipleIndexFields extends FacetTestCase {TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));// create and open a taxonomy writerTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);- FacetsConfig config = getConfig(tw);+ FacetsConfig config = getConfig();- seedIndex(iw, config);+ seedIndex(tw, iw, config);IndexReader ir = iw.getReader();tw.commit();@@ -116,9 +114,9 @@ public class TestMultipleIndexFields extends FacetTestCase {// create and open a taxonomy writerTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);- FacetsConfig config = getConfig(tw);+ FacetsConfig config = getConfig();config.setIndexFieldName("Author", "$author");- seedIndex(iw, config);+ seedIndex(tw, iw, config);IndexReader ir = iw.getReader();tw.commit();@@ -155,10 +153,10 @@ public class TestMultipleIndexFields extends FacetTestCase {// create and open a taxonomy writerTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);- FacetsConfig config = getConfig(tw);+ FacetsConfig config = getConfig();config.setIndexFieldName("Band", "$music");config.setIndexFieldName("Composer", "$music");- seedIndex(iw, config);+ seedIndex(tw, iw, config);IndexReader ir = iw.getReader();tw.commit();@@ -208,10 +206,10 @@ public class TestMultipleIndexFields extends FacetTestCase {// create and open a taxonomy writerTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);- FacetsConfig config = getConfig(tw);+ FacetsConfig config = getConfig();config.setIndexFieldName("Band", "$bands");config.setIndexFieldName("Composer", "$composers");- seedIndex(iw, config);+ seedIndex(tw, iw, config);IndexReader ir = iw.getReader();tw.commit();@@ -249,11 +247,11 @@ public class TestMultipleIndexFields extends FacetTestCase {// create and open a taxonomy writerTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);- FacetsConfig config = getConfig(tw);+ FacetsConfig config = getConfig();config.setIndexFieldName("Band", "$music");config.setIndexFieldName("Composer", "$music");config.setIndexFieldName("Author", "$literature");- seedIndex(iw, config);+ seedIndex(tw, iw, config);IndexReader ir = iw.getReader();tw.commit();@@ -291,17 +289,17 @@ public class TestMultipleIndexFields extends FacetTestCase {private FacetsCollector performSearch(TaxonomyReader tr, IndexReader ir,IndexSearcher searcher) throws IOException {- FacetsCollector sfc = new FacetsCollector();- Facets.search(searcher, new MatchAllDocsQuery(), 10, sfc);- return sfc;+ FacetsCollector fc = new FacetsCollector();+ FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);+ return fc;}- private void seedIndex(RandomIndexWriter iw, FacetsConfig config) throws IOException {+ private void seedIndex(TaxonomyWriter tw, RandomIndexWriter iw, FacetsConfig config) throws IOException {for (FacetField ff : CATEGORIES) {Document doc = new Document();doc.add(ff);doc.add(new TextField("content", "alpha", Field.Store.YES));- iw.addDocument(config.build(doc));+ iw.addDocument(config.build(tw, doc));}}}\ No newline at end of filediff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestRangeFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/TestRangeFacetCounts.javaindex 43b64cc9f9a..7ea1f418b0f 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/TestRangeFacetCounts.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestRangeFacetCounts.java@@ -89,7 +89,7 @@ public class TestRangeFacetCounts extends FacetTestCase {Directory td = newDirectory();DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(td, IndexWriterConfig.OpenMode.CREATE);- FacetsConfig config = new FacetsConfig(tw);+ FacetsConfig config = new FacetsConfig();for (long l = 0; l < 100; l++) {Document doc = new Document();@@ -103,7 +103,7 @@ public class TestRangeFacetCounts extends FacetTestCase {} else {doc.add(new FacetField("dim", "b"));}- w.addDocument(config.build(doc));+ w.addDocument(config.build(tw, doc));}final IndexReader r = w.getReader();diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestSearcherTaxonomyManager.java b/lucene/facet/src/test/org/apache/lucene/facet/TestSearcherTaxonomyManager.javaindex ef41b6a36f8..6982d870a3d 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/TestSearcherTaxonomyManager.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestSearcherTaxonomyManager.java@@ -40,7 +40,7 @@ public class TestSearcherTaxonomyManager extends FacetTestCase {Directory taxoDir = newDirectory();final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));final DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);- final FacetsConfig config = new FacetsConfig(tw);+ final FacetsConfig config = new FacetsConfig();config.setMultiValued("field", true);final AtomicBoolean stop = new AtomicBoolean();@@ -76,7 +76,7 @@ public class TestSearcherTaxonomyManager extends FacetTestCase {doc.add(new FacetField("field", path));}try {- w.addDocument(config.build(doc));+ w.addDocument(config.build(tw, doc));} catch (IOException ioe) {throw new RuntimeException(ioe);}diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestSortedSetDocValuesFacets.java b/lucene/facet/src/test/org/apache/lucene/facet/TestSortedSetDocValuesFacets.javaindex 8e892762f0a..4d0825ba3ce 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/TestSortedSetDocValuesFacets.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestSortedSetDocValuesFacets.java@@ -180,6 +180,46 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {dir.close();}+ public void testSomeSegmentsMissing() throws Exception {+ assumeTrue("Test requires SortedSetDV support", defaultCodecSupportsSortedSet());+ Directory dir = newDirectory();++ RandomIndexWriter writer = new RandomIndexWriter(random(), dir);++ FacetsConfig config = new FacetsConfig();++ Document doc = new Document();+ doc.add(new SortedSetDocValuesFacetField("a", "foo1"));+ writer.addDocument(config.build(doc));+ writer.commit();++ doc = new Document();+ writer.addDocument(config.build(doc));+ writer.commit();++ doc = new Document();+ doc.add(new SortedSetDocValuesFacetField("a", "foo2"));+ writer.addDocument(config.build(doc));+ writer.commit();++ // NRT open+ IndexSearcher searcher = newSearcher(writer.getReader());+ writer.close();++ // Per-top-reader state:+ SortedSetDocValuesReaderState state = new SortedSetDocValuesReaderState(searcher.getIndexReader());++ FacetsCollector c = new FacetsCollector();+ searcher.search(new MatchAllDocsQuery(), c);+ SortedSetDocValuesFacetCounts facets = new SortedSetDocValuesFacetCounts(state, c);++ // Ask for top 10 labels for any dims that have counts:+ assertEquals("value=2 childCount=2\n foo1 (1)\n foo2 (1)\n", facets.getTopChildren(10, "a").toString());++ searcher.getIndexReader().close();+ dir.close();+ }+// nocommit test different delim char & using the default// one in a dimdiff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetAssociations.java b/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetAssociations.javaindex 8fb3384613e..2e5839a3380 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetAssociations.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetAssociations.java@@ -51,7 +51,7 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);// Cannot mix ints & floats in the same indexed field:- config = new FacetsConfig(taxoWriter);+ config = new FacetsConfig();config.setIndexFieldName("int", "$facets.int");config.setMultiValued("int", true);config.setIndexFieldName("float", "$facets.float");@@ -72,7 +72,7 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {doc.add(new FloatAssociationFacetField(0.2f, "float", "b"));}}- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));}taxoWriter.close();@@ -161,14 +161,14 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {Directory taxoDir = newDirectory();TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();RandomIndexWriter writer = new RandomIndexWriter(random(), dir);Document doc = new Document();doc.add(new IntAssociationFacetField(14, "a", "x"));doc.add(new FloatAssociationFacetField(55.0f, "b", "y"));try {- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));fail("did not hit expected exception");} catch (IllegalArgumentException exc) {// expected@@ -181,14 +181,14 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {Directory taxoDir = newDirectory();TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setHierarchical("a", true);RandomIndexWriter writer = new RandomIndexWriter(random(), dir);Document doc = new Document();doc.add(new IntAssociationFacetField(14, "a", "x"));try {- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));fail("did not hit expected exception");} catch (IllegalArgumentException exc) {// expected@@ -201,14 +201,14 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {Directory taxoDir = newDirectory();TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setRequireDimCount("a", true);RandomIndexWriter writer = new RandomIndexWriter(random(), dir);Document doc = new Document();doc.add(new IntAssociationFacetField(14, "a", "x"));try {- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));fail("did not hit expected exception");} catch (IllegalArgumentException exc) {// expecteddiff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetCounts.javaindex 3bf34c9632f..28ab67e8f64 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetCounts.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetCounts.java@@ -60,7 +60,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {// main index:DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setHierarchical("Publish Date", true);RandomIndexWriter writer = new RandomIndexWriter(random(), dir);@@ -68,27 +68,27 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {Document doc = new Document();doc.add(new FacetField("Author", "Bob"));doc.add(new FacetField("Publish Date", "2010", "10", "15"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Lisa"));doc.add(new FacetField("Publish Date", "2010", "10", "20"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Lisa"));doc.add(new FacetField("Publish Date", "2012", "1", "1"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Susan"));doc.add(new FacetField("Publish Date", "2012", "1", "7"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Frank"));doc.add(new FacetField("Publish Date", "1999", "5", "5"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -145,11 +145,11 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);RandomIndexWriter writer = new RandomIndexWriter(random(), dir);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();Document doc = new Document();doc.add(new FacetField("a", "foo1"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));if (random().nextBoolean()) {writer.commit();@@ -158,7 +158,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {doc = new Document();doc.add(new FacetField("a", "foo2"));doc.add(new FacetField("b", "bar1"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));if (random().nextBoolean()) {writer.commit();@@ -168,7 +168,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {doc.add(new FacetField("a", "foo3"));doc.add(new FacetField("b", "bar2"));doc.add(new FacetField("c", "baz1"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -200,13 +200,13 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {// main index:DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setIndexFieldName("a", "$facets2");RandomIndexWriter writer = new RandomIndexWriter(random(), dir);Document doc = new Document();doc.add(new FacetField("a", "foo1"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -269,12 +269,12 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {});TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();Document doc = new Document();doc.add(newTextField("field", "text", Field.Store.NO));doc.add(new FacetField("a", "path"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));IOUtils.close(writer, taxoWriter, dir, taxoDir);}@@ -282,7 +282,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {Directory dir = newDirectory();Directory taxoDir = newDirectory();DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setHierarchical("a", true);config.setMultiValued("a", true);RandomIndexWriter writer = new RandomIndexWriter(random(), dir);@@ -291,7 +291,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {doc.add(newTextField("field", "text", Field.Store.NO));doc.add(new FacetField("a", "path", "x"));doc.add(new FacetField("a", "path", "y"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -321,14 +321,14 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {RandomIndexWriter writer = new RandomIndexWriter(random(), dir);DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setMultiValued("dim", true);Document doc = new Document();doc.add(newTextField("field", "text", Field.Store.NO));doc.add(new FacetField("dim", "test\u001Fone"));doc.add(new FacetField("dim", "test\u001Etwo"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -354,7 +354,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {RandomIndexWriter writer = new RandomIndexWriter(random(), dir);DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setMultiValued("dim2", true);config.setMultiValued("dim3", true);config.setHierarchical("dim3", true);@@ -369,7 +369,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {doc.add(new FacetField("dim2", "b"));doc.add(new FacetField("dim3", "a", "b"));doc.add(new FacetField("dim3", "a", "c"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -397,7 +397,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setMultiValued("dim", true);int numLabels = _TestUtil.nextInt(random(), 40000, 100000);@@ -407,7 +407,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {for (int i = 0; i < numLabels; i++) {doc.add(new FacetField("dim", "" + i));}- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -444,13 +444,13 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {Directory taxoDir = newDirectory();TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);RandomIndexWriter writer = new RandomIndexWriter(random(), dir);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();Document doc = new Document();doc.add(newTextField("field", "text", Field.Store.NO));doc.add(new FacetField("a", "path", "other"));try {- config.build(doc);+ config.build(taxoWriter, doc);fail("did not hit expected exception");} catch (IllegalArgumentException iae) {// expected@@ -465,14 +465,14 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {Directory taxoDir = newDirectory();TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);RandomIndexWriter writer = new RandomIndexWriter(random(), dir);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();Document doc = new Document();doc.add(newTextField("field", "text", Field.Store.NO));doc.add(new FacetField("a", "path"));doc.add(new FacetField("a", "path2"));try {- config.build(doc);+ config.build(taxoWriter, doc);fail("did not hit expected exception");} catch (IllegalArgumentException iae) {// expected@@ -486,7 +486,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setIndexFieldName("b", "$b");for(int i = atLeast(30); i > 0; --i) {@@ -494,7 +494,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {doc.add(new StringField("f", "v", Field.Store.NO));doc.add(new FacetField("a", "1"));doc.add(new FacetField("b", "1"));- iw.addDocument(config.build(doc));+ iw.addDocument(config.build(taxoWriter, doc));}DirectoryReader r = DirectoryReader.open(iw, true);@@ -516,12 +516,12 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();for(int i = atLeast(30); i > 0; --i) {Document doc = new Document();doc.add(new FacetField("a", "1"));doc.add(new FacetField("b", "1"));- iw.addDocument(config.build(doc));+ iw.addDocument(config.build(taxoWriter, doc));}DirectoryReader r = DirectoryReader.open(iw, true);@@ -544,12 +544,12 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();Document doc = new Document();doc.add(new FacetField("a", "1"));doc.add(new FacetField("b", "1"));- iw.addDocument(config.build(doc));+ iw.addDocument(config.build(taxoWriter, doc));DirectoryReader r = DirectoryReader.open(iw, true);DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);@@ -572,11 +572,11 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();for (int i = 0; i < 10; i++) {Document doc = new Document();doc.add(new FacetField("a", Integer.toString(i)));- iw.addDocument(config.build(doc));+ iw.addDocument(config.build(taxoWriter, doc));}DirectoryReader r = DirectoryReader.open(iw, true);@@ -591,7 +591,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {IOUtils.close(taxoWriter, iw, taxoReader, taxoDir, r, indexDir);}- private void indexTwoDocs(IndexWriter indexWriter, FacetsConfig config, boolean withContent) throws Exception {+ private void indexTwoDocs(TaxonomyWriter taxoWriter, IndexWriter indexWriter, FacetsConfig config, boolean withContent) throws Exception {for (int i = 0; i < 2; i++) {Document doc = new Document();if (withContent) {@@ -599,7 +599,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {}if (config != null) {doc.add(new FacetField("A", Integer.toString(i)));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));} else {indexWriter.addDocument(doc);}@@ -618,14 +618,14 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {IndexWriter indexWriter = new IndexWriter(indexDir, iwc);TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);- FacetsConfig config = new FacetsConfig(taxoWriter);- indexTwoDocs(indexWriter, config, false); // 1st segment, no content, with categories- indexTwoDocs(indexWriter, null, true); // 2nd segment, with content, no categories- indexTwoDocs(indexWriter, config, true); // 3rd segment ok- indexTwoDocs(indexWriter, null, false); // 4th segment, no content, or categories- indexTwoDocs(indexWriter, null, true); // 5th segment, with content, no categories- indexTwoDocs(indexWriter, config, true); // 6th segment, with content, with categories- indexTwoDocs(indexWriter, null, true); // 7th segment, with content, no categories+ FacetsConfig config = new FacetsConfig();+ indexTwoDocs(taxoWriter, indexWriter, config, false); // 1st segment, no content, with categories+ indexTwoDocs(taxoWriter, indexWriter, null, true); // 2nd segment, with content, no categories+ indexTwoDocs(taxoWriter, indexWriter, config, true); // 3rd segment ok+ indexTwoDocs(taxoWriter, indexWriter, null, false); // 4th segment, no content, or categories+ indexTwoDocs(taxoWriter, indexWriter, null, true); // 5th segment, with content, no categories+ indexTwoDocs(taxoWriter, indexWriter, config, true); // 6th segment, with content, with categories+ indexTwoDocs(taxoWriter, indexWriter, null, true); // 7th segment, with content, no categoriesIOUtils.close(indexWriter, taxoWriter);DirectoryReader indexReader = DirectoryReader.open(indexDir);diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetCounts2.java b/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetCounts2.javaindex 0d0f28842a8..4563d5c6d8e 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetCounts2.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetCounts2.java@@ -138,8 +138,8 @@ public class TestTaxonomyFacetCounts2 extends FacetTestCase {}}- private static FacetsConfig getConfig(TaxonomyWriter taxoWriter) {- FacetsConfig config = new FacetsConfig(taxoWriter);+ private static FacetsConfig getConfig() {+ FacetsConfig config = new FacetsConfig();config.setMultiValued("A", true);config.setMultiValued("B", true);config.setRequireDimCount("B", true);@@ -147,10 +147,6 @@ public class TestTaxonomyFacetCounts2 extends FacetTestCase {return config;}- private static FacetsConfig getConfig() {- return getConfig(null);- }-private static void indexDocsNoFacets(IndexWriter indexWriter) throws IOException {int numDocs = atLeast(2);for (int i = 0; i < numDocs; i++) {@@ -165,11 +161,11 @@ public class TestTaxonomyFacetCounts2 extends FacetTestCase {Map<String,Integer> expectedCounts) throws IOException {Random random = random();int numDocs = atLeast(random, 2);- FacetsConfig config = getConfig(taxoWriter);+ FacetsConfig config = getConfig();for (int i = 0; i < numDocs; i++) {Document doc = new Document();addFacets(doc, config, false);- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));}indexWriter.commit(); // flush a segment}@@ -178,12 +174,12 @@ public class TestTaxonomyFacetCounts2 extends FacetTestCase {Map<String,Integer> expectedCounts) throws IOException {Random random = random();int numDocs = atLeast(random, 2);- FacetsConfig config = getConfig(taxoWriter);+ FacetsConfig config = getConfig();for (int i = 0; i < numDocs; i++) {Document doc = new Document();addFacets(doc, config, true);addField(doc);- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));}indexWriter.commit(); // flush a segment}@@ -192,7 +188,7 @@ public class TestTaxonomyFacetCounts2 extends FacetTestCase {Map<String,Integer> expectedCounts) throws IOException {Random random = random();int numDocs = atLeast(random, 2);- FacetsConfig config = getConfig(taxoWriter);+ FacetsConfig config = getConfig();for (int i = 0; i < numDocs; i++) {Document doc = new Document();boolean hasContent = random.nextBoolean();@@ -200,7 +196,7 @@ public class TestTaxonomyFacetCounts2 extends FacetTestCase {addField(doc);}addFacets(doc, config, hasContent);- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));}indexWriter.commit(); // flush a segment}diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetSumValueSource.java b/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetSumValueSource.javaindex 72cda326c91..dbb45d38bbc 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetSumValueSource.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestTaxonomyFacetSumValueSource.java@@ -63,34 +63,34 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);RandomIndexWriter writer = new RandomIndexWriter(random(), dir);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();// Reused across documents, to add the necessary facet// fields:Document doc = new Document();doc.add(new IntField("num", 10, Field.Store.NO));doc.add(new FacetField("Author", "Bob"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new IntField("num", 20, Field.Store.NO));doc.add(new FacetField("Author", "Lisa"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new IntField("num", 30, Field.Store.NO));doc.add(new FacetField("Author", "Lisa"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new IntField("num", 40, Field.Store.NO));doc.add(new FacetField("Author", "Susan"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new IntField("num", 45, Field.Store.NO));doc.add(new FacetField("Author", "Frank"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -130,12 +130,12 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);RandomIndexWriter writer = new RandomIndexWriter(random(), dir);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();Document doc = new Document();doc.add(new IntField("num", 10, Field.Store.NO));doc.add(new FacetField("a", "foo1"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));if (random().nextBoolean()) {writer.commit();@@ -145,7 +145,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {doc.add(new IntField("num", 20, Field.Store.NO));doc.add(new FacetField("a", "foo2"));doc.add(new FacetField("b", "bar1"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));if (random().nextBoolean()) {writer.commit();@@ -156,7 +156,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {doc.add(new FacetField("a", "foo3"));doc.add(new FacetField("b", "bar2"));doc.add(new FacetField("c", "baz1"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -191,7 +191,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {// main index:DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setIndexFieldName("a", "$facets2");RandomIndexWriter writer = new RandomIndexWriter(random(), dir);@@ -199,7 +199,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {Document doc = new Document();doc.add(new IntField("num", 10, Field.Store.NO));doc.add(new FacetField("a", "foo1"));- writer.addDocument(config.build(doc));+ writer.addDocument(config.build(taxoWriter, doc));// NRT openIndexSearcher searcher = newSearcher(writer.getReader());@@ -242,7 +242,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();for(int i = atLeast(30); i > 0; --i) {Document doc = new Document();@@ -250,7 +250,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {doc.add(new StringField("f", "v", Field.Store.NO));}doc.add(new FacetField("dim", "a"));- iw.addDocument(config.build(doc));+ iw.addDocument(config.build(taxoWriter, doc));}DirectoryReader r = DirectoryReader.open(iw, true);@@ -260,7 +260,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {ConstantScoreQuery csq = new ConstantScoreQuery(new MatchAllDocsQuery());csq.setBoost(2.0f);- TopDocs td = Facets.search(newSearcher(r), csq, 10, fc);+ TopDocs td = FacetsCollector.search(newSearcher(r), csq, 10, fc);Facets facets = new TaxonomyFacetSumValueSource(taxoReader, config, fc, new TaxonomyFacetSumValueSource.ScoreValueSource());@@ -276,12 +276,12 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();for (int i = 0; i < 4; i++) {Document doc = new Document();doc.add(new NumericDocValuesField("price", (i+1)));doc.add(new FacetField("a", Integer.toString(i % 2)));- iw.addDocument(config.build(doc));+ iw.addDocument(config.build(taxoWriter, doc));}DirectoryReader r = DirectoryReader.open(iw, true);@@ -302,12 +302,12 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();for (int i = 0; i < 4; i++) {Document doc = new Document();doc.add(new NumericDocValuesField("price", (i+1)));doc.add(new FacetField("a", Integer.toString(i % 2)));- iw.addDocument(config.build(doc));+ iw.addDocument(config.build(taxoWriter, doc));}DirectoryReader r = DirectoryReader.open(iw, true);@@ -339,7 +339,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {TopScoreDocCollector tsdc = TopScoreDocCollector.create(10, true);// score documents by their 'price' field - makes asserting the correct counts for the categories easierQuery q = new FunctionQuery(new LongFieldSource("price"));- Facets.search(newSearcher(r), q, 10, fc);+ FacetsCollector.search(newSearcher(r), q, 10, fc);Facets facets = new TaxonomyFacetSumValueSource(taxoReader, config, fc, valueSource);assertEquals("value=10.0 childCount=2\n 1 (6.0)\n 0 (4.0)\n", facets.getTopChildren(10, "a").toString());@@ -353,7 +353,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setHierarchical("a", true);//config.setRequireDimCount("a", true);@@ -361,7 +361,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {Document doc = new Document();doc.add(new NumericDocValuesField("price", (i+1)));doc.add(new FacetField("a", Integer.toString(i % 2), "1"));- iw.addDocument(config.build(doc));+ iw.addDocument(config.build(taxoWriter, doc));}DirectoryReader r = DirectoryReader.open(iw, true);@@ -383,7 +383,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();config.setIndexFieldName("b", "$b");for(int i = atLeast(30); i > 0; --i) {@@ -391,14 +391,14 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {doc.add(new StringField("f", "v", Field.Store.NO));doc.add(new FacetField("a", "1"));doc.add(new FacetField("b", "1"));- iw.addDocument(config.build(doc));+ iw.addDocument(config.build(taxoWriter, doc));}DirectoryReader r = DirectoryReader.open(iw, true);DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);FacetsCollector fc = new FacetsCollector(true);- TopDocs hits = Facets.search(newSearcher(r), new MatchAllDocsQuery(), 10, fc);+ TopDocs hits = FacetsCollector.search(newSearcher(r), new MatchAllDocsQuery(), 10, fc);Facets facets1 = getTaxonomyFacetCounts(taxoReader, config, fc);Facets facets2 = new TaxonomyFacetSumValueSource(new DocValuesOrdinalsReader("$b"), taxoReader, config, fc, new TaxonomyFacetSumValueSource.ScoreValueSource());diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestConcurrentFacetedIndexing.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestConcurrentFacetedIndexing.javaindex 635d504ecde..a7dbee6aa06 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestConcurrentFacetedIndexing.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestConcurrentFacetedIndexing.java@@ -86,7 +86,7 @@ public class TestConcurrentFacetedIndexing extends FacetTestCase {final IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, null));final DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE, newTaxoWriterCache(numDocs.get()));final Thread[] indexThreads = new Thread[atLeast(4)];- final FacetsConfig config = new FacetsConfig(tw);+ final FacetsConfig config = new FacetsConfig();for(int i=0;i<10;i++) {config.setHierarchical("l1." + i, true);config.setMultiValued("l1." + i, true);@@ -106,7 +106,7 @@ public class TestConcurrentFacetedIndexing extends FacetTestCase {FacetField ff = newCategory();doc.add(ff);- FacetLabel label = FacetLabel.create(ff.dim, ff.path);+ FacetLabel label = new FacetLabel(ff.dim, ff.path);// add all prefixes to valuesint level = label.length;while (level > 0) {@@ -115,7 +115,7 @@ public class TestConcurrentFacetedIndexing extends FacetTestCase {--level;}}- iw.addDocument(config.build(doc));+ iw.addDocument(config.build(tw, doc));} catch (IOException e) {throw new RuntimeException(e);}diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.javaindex a02ac0c1cc3..2dd61199b32 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java@@ -426,7 +426,7 @@ public class TestDirectoryTaxonomyWriter extends FacetTestCase {Directory indexDir = newDirectory(), taxoDir = newDirectory();IndexWriter indexWriter = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE, new Cl2oTaxonomyWriterCache(2, 1f, 1));- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();// Add one huge label:String bigs = null;@@ -435,11 +435,11 @@ public class TestDirectoryTaxonomyWriter extends FacetTestCase {int len = FacetLabel.MAX_CATEGORY_PATH_LENGTH - 4; // for the dimension and separatorbigs = _TestUtil.randomSimpleString(random(), len, len);FacetField ff = new FacetField("dim", bigs);- FacetLabel cp = FacetLabel.create("dim", bigs);+ FacetLabel cp = new FacetLabel("dim", bigs);ordinal = taxoWriter.addCategory(cp);Document doc = new Document();doc.add(ff);- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));// Add tiny ones to cause a re-hashfor (int i = 0; i < 3; i++) {@@ -447,7 +447,7 @@ public class TestDirectoryTaxonomyWriter extends FacetTestCase {taxoWriter.addCategory(new FacetLabel("dim", s));doc = new Document();doc.add(new FacetField("dim", s));- indexWriter.addDocument(config.build(doc));+ indexWriter.addDocument(config.build(taxoWriter, doc));}// when too large components were allowed to be added, this resulted in a new added categorydiff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.javaindex 711b443b662..0ded9fe323e 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java@@ -58,7 +58,6 @@ public class TestCompactLabelToOrdinal extends FacetTestCase {uniqueValues[i] = decoder.decode(ByteBuffer.wrap(buffer, 0, size)).toString();// we cannot have empty path components, so eliminate all prefix as well// as middle consecutive delimiter chars.- // nocommit removeuniqueValues[i] = uniqueValues[i].replaceAll("/+", "/");if (uniqueValues[i].startsWith("/")) {uniqueValues[i] = uniqueValues[i].substring(1);diff --git a/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java b/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.javaindex c54fc16ba45..c4ae13535d1 100644--- a/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java+++ b/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java@@ -183,7 +183,7 @@ public class IndexAndTaxonomyReplicationClientTest extends ReplicatorTestCase {private IndexDocument newDocument(TaxonomyWriter taxoWriter, int id) throws IOException {Document doc = new Document();doc.add(new FacetField("A", Integer.toString(id, 16)));- return config.build(doc);+ return config.build(publishTaxoWriter, doc);}@Override@@ -205,7 +205,7 @@ public class IndexAndTaxonomyReplicationClientTest extends ReplicatorTestCase {conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));publishIndexWriter = new IndexWriter(publishIndexDir, conf);publishTaxoWriter = new SnapshotDirectoryTaxonomyWriter(publishTaxoDir);- config = new FacetsConfig(publishTaxoWriter);+ config = new FacetsConfig();config.setHierarchical("A", true);}diff --git a/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyRevisionTest.java b/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyRevisionTest.javaindex c1f2de28fa4..df203c1ec3f 100644--- a/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyRevisionTest.java+++ b/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyRevisionTest.java@@ -44,10 +44,10 @@ import org.junit.Test;public class IndexAndTaxonomyRevisionTest extends ReplicatorTestCase {private IndexDocument newDocument(TaxonomyWriter taxoWriter) throws IOException {- FacetsConfig config = new FacetsConfig(taxoWriter);+ FacetsConfig config = new FacetsConfig();Document doc = new Document();doc.add(new FacetField("A", "1"));- return config.build(doc);+ return config.build(taxoWriter, doc);}@Test