mirror of https://github.com/apache/lucene.git
LUCENE-5339: switch to DocumentBuilder.build instead of FacetIndexWriter
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5339@1543530 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d815a3608b
commit
1accec983e
1
TODO
1
TODO
|
@ -2,6 +2,7 @@ nocommit this!
|
|||
|
||||
TODO
|
||||
- associations
|
||||
- can we do index time detection of invalid mixing?
|
||||
- cutover taxo writer/reader to pathToString/stringToPath
|
||||
- wrap an IW instead of extending one? or, FacetDocument?
|
||||
- re-enable ALL_BUT_DIM somehow?
|
||||
|
|
|
@ -42,25 +42,21 @@ import org.apache.lucene.util.ArrayUtil;
|
|||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.IntsRef;
|
||||
|
||||
public class FacetIndexWriter extends IndexWriter {
|
||||
/** Pass the {@link #Document} to index to {@link #build},
|
||||
* to translate any added {@link FacetField}s into
|
||||
* indexable and storable fields. It's safe to share a
|
||||
* single instance of this across multiple threads. */
|
||||
|
||||
public class DocumentBuilder {
|
||||
private final TaxonomyWriter taxoWriter;
|
||||
private final FacetsConfig config;
|
||||
|
||||
public FacetIndexWriter(Directory d, IndexWriterConfig conf, TaxonomyWriter taxoWriter, FacetsConfig config) throws IOException {
|
||||
super(d, conf);
|
||||
public DocumentBuilder(TaxonomyWriter taxoWriter, FacetsConfig config) {
|
||||
this.taxoWriter = taxoWriter;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
// nocommit maybe we could somehow "own" TaxonomyWriter
|
||||
// too? commit it in commit, close it in close, etc?
|
||||
|
||||
// nocommit also updateDocument, addDocument, addDocuments
|
||||
|
||||
@Override
|
||||
public void addDocument(final IndexDocument doc) throws IOException {
|
||||
|
||||
public IndexDocument build(IndexDocument doc) throws IOException {
|
||||
// Find all FacetFields, collated by the actual field:
|
||||
Map<String,List<FacetField>> byField = new HashMap<String,List<FacetField>>();
|
||||
|
||||
|
@ -137,7 +133,7 @@ public class FacetIndexWriter extends IndexWriter {
|
|||
//System.out.println("all indexed: " + allIndexedFields);
|
||||
//System.out.println("all stored: " + allStoredFields);
|
||||
|
||||
super.addDocument(new IndexDocument() {
|
||||
return new IndexDocument() {
|
||||
@Override
|
||||
public Iterable<IndexableField> indexableFields() {
|
||||
return allIndexedFields;
|
||||
|
@ -147,7 +143,7 @@ public class FacetIndexWriter extends IndexWriter {
|
|||
public Iterable<StorableField> storableFields() {
|
||||
return allStoredFields;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
private void processFacetFields(Map<String,List<FacetField>> byField, List<Field> addedIndexedFields, List<Field> addedStoredFields) throws IOException {
|
||||
|
@ -248,10 +244,9 @@ public class FacetIndexWriter extends IndexWriter {
|
|||
}
|
||||
}
|
||||
|
||||
// nocommit open this up
|
||||
/** We can open this up if/when we really need
|
||||
* pluggability on the encoding. */
|
||||
private final BytesRef dedupAndEncode(IntsRef ordinals) {
|
||||
/** Encodes ordinals into a BytesRef; expert: subclass can
|
||||
* override this to change encoding. */
|
||||
protected BytesRef dedupAndEncode(IntsRef ordinals) {
|
||||
Arrays.sort(ordinals.ints, ordinals.offset, ordinals.length);
|
||||
byte[] bytes = new byte[5*ordinals.length];
|
||||
int lastOrd = -1;
|
||||
|
@ -298,7 +293,7 @@ public class FacetIndexWriter extends IndexWriter {
|
|||
return new BytesRef(bytes, 0, upto);
|
||||
}
|
||||
|
||||
// nocommit move these constants / methods to Util?
|
||||
// nocommit move all of this to Util?
|
||||
|
||||
// Joins the path components together:
|
||||
private static final char DELIM_CHAR = '\u001F';
|
||||
|
@ -367,4 +362,4 @@ public class FacetIndexWriter extends IndexWriter {
|
|||
assert !lastEscape;
|
||||
return parts.toArray(new String[parts.size()]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,7 +53,7 @@ import org.apache.lucene.search.TermQuery;
|
|||
public final class SimpleDrillDownQuery extends Query {
|
||||
|
||||
private static Term term(String field, String dim, String[] path) {
|
||||
return new Term(field, FacetIndexWriter.pathToString(dim, path));
|
||||
return new Term(field, FacetDocument.pathToString(dim, path));
|
||||
}
|
||||
|
||||
private final FacetsConfig config;
|
||||
|
|
|
@ -230,7 +230,7 @@ public class SortedSetDocValuesFacetCounts extends Facets {
|
|||
throw new IllegalArgumentException("path must be length=1");
|
||||
}
|
||||
|
||||
int ord = (int) dv.lookupTerm(new BytesRef(FacetIndexWriter.pathToString(dim, path)));
|
||||
int ord = (int) dv.lookupTerm(new BytesRef(FacetDocument.pathToString(dim, path)));
|
||||
if (ord < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public final class SortedSetDocValuesReaderState {
|
|||
// support arbitrary hierarchy:
|
||||
for(int ord=0;ord<valueCount;ord++) {
|
||||
dv.lookupOrd(ord, spare);
|
||||
String[] components = FacetIndexWriter.stringToPath(spare.utf8ToString());
|
||||
String[] components = FacetDocument.stringToPath(spare.utf8ToString());
|
||||
if (components.length != 2) {
|
||||
throw new IllegalArgumentException("this class can only handle 2 level hierarchy (dim/value); got: " + Arrays.toString(components) + " " + spare.utf8ToString());
|
||||
}
|
||||
|
|
|
@ -89,35 +89,36 @@ public class TestSimpleDrillSideways extends FacetTestCase {
|
|||
FacetsConfig config = new FacetsConfig();
|
||||
config.setHierarchical("Publish Date");
|
||||
|
||||
IndexWriter writer = new FacetIndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())), taxoWriter, config);
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
DocumentBuilder builder = new DocumentBuilder(taxoWriter, config);
|
||||
|
||||
Document doc = new Document();
|
||||
doc.add(new FacetField("Author", "Bob"));
|
||||
doc.add(new FacetField("Publish Date", "2010", "10", "15"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new FacetField("Author", "Lisa"));
|
||||
doc.add(new FacetField("Publish Date", "2010", "10", "20"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new FacetField("Author", "Lisa"));
|
||||
doc.add(new FacetField("Publish Date", "2012", "1", "1"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new FacetField("Author", "Susan"));
|
||||
doc.add(new FacetField("Publish Date", "2012", "1", "7"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new FacetField("Author", "Frank"));
|
||||
doc.add(new FacetField("Publish Date", "1999", "5", "5"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
// NRT open
|
||||
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
|
||||
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||
writer.close();
|
||||
|
||||
//System.out.println("searcher=" + searcher);
|
||||
|
|
|
@ -46,24 +46,25 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
|
|||
Directory dir = newDirectory();
|
||||
|
||||
FacetsConfig config = new FacetsConfig();
|
||||
IndexWriter writer = new FacetIndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())), null, config);
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
FacetDocument facetDoc = new FacetDocument(null, config);
|
||||
|
||||
Document doc = new Document();
|
||||
doc.add(new SortedSetDocValuesFacetField("a", "foo"));
|
||||
doc.add(new SortedSetDocValuesFacetField("a", "bar"));
|
||||
doc.add(new SortedSetDocValuesFacetField("a", "zoo"));
|
||||
doc.add(new SortedSetDocValuesFacetField("b", "baz"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(facetDoc.build(doc));
|
||||
if (random().nextBoolean()) {
|
||||
writer.commit();
|
||||
}
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new SortedSetDocValuesFacetField("a", "foo"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(facetDoc.build(doc));
|
||||
|
||||
// NRT open
|
||||
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
|
||||
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||
writer.close();
|
||||
|
||||
// Per-top-reader state:
|
||||
|
@ -94,24 +95,25 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
|
|||
assumeTrue("Test requires SortedSetDV support", defaultCodecSupportsSortedSet());
|
||||
Directory dir = newDirectory();
|
||||
|
||||
IndexWriter writer = new FacetIndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())), null, new FacetsConfig());
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
DocumentBuilder builder = new DocumentBuilder(null, new FacetsConfig());
|
||||
|
||||
Document doc = new Document();
|
||||
doc.add(new SortedSetDocValuesFacetField("a", "foo"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
IndexReader r = DirectoryReader.open(writer, true);
|
||||
IndexReader r = writer.getReader();
|
||||
SortedSetDocValuesReaderState state = new SortedSetDocValuesReaderState(r);
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new SortedSetDocValuesFacetField("a", "bar"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new SortedSetDocValuesFacetField("a", "baz"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
|
||||
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||
|
||||
SimpleFacetsCollector c = new SimpleFacetsCollector();
|
||||
|
||||
|
@ -135,11 +137,12 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
|
|||
assumeTrue("Test requires SortedSetDV support", defaultCodecSupportsSortedSet());
|
||||
Directory dir = newDirectory();
|
||||
|
||||
IndexWriter writer = new FacetIndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())), null, new FacetsConfig());
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
DocumentBuilder builder = new DocumentBuilder(null, new FacetsConfig());
|
||||
|
||||
Document doc = new Document();
|
||||
doc.add(new SortedSetDocValuesFacetField("a", "foo1"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
if (random().nextBoolean()) {
|
||||
writer.commit();
|
||||
|
@ -148,7 +151,7 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
|
|||
doc = new Document();
|
||||
doc.add(new SortedSetDocValuesFacetField("a", "foo2"));
|
||||
doc.add(new SortedSetDocValuesFacetField("b", "bar1"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
if (random().nextBoolean()) {
|
||||
writer.commit();
|
||||
|
@ -158,10 +161,10 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
|
|||
doc.add(new SortedSetDocValuesFacetField("a", "foo3"));
|
||||
doc.add(new SortedSetDocValuesFacetField("b", "bar2"));
|
||||
doc.add(new SortedSetDocValuesFacetField("c", "baz1"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
// NRT open
|
||||
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
|
||||
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||
writer.close();
|
||||
|
||||
// Per-top-reader state:
|
||||
|
|
|
@ -56,7 +56,7 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {
|
|||
private static final FacetLabel afloat = new FacetLabel("float", "a");
|
||||
private static final FacetLabel bfloat = new FacetLabel("float", "b");
|
||||
private static final FacetsConfig config = new FacetsConfig();
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
dir = newDirectory();
|
||||
|
@ -69,8 +69,8 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {
|
|||
config.setIndexFieldName("int", "$facets.int");
|
||||
config.setIndexFieldName("float", "$facets.float");
|
||||
|
||||
IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
|
||||
IndexWriter writer = new FacetIndexWriter(dir, iwc, taxoWriter, config);
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
DocumentBuilder builder = new DocumentBuilder(taxoWriter, config);
|
||||
|
||||
// index documents, 50% have only 'b' and all have 'a'
|
||||
for (int i = 0; i < 110; i++) {
|
||||
|
@ -85,11 +85,11 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {
|
|||
doc.add(new AssociationFacetField(0.2f, "float", "b"));
|
||||
}
|
||||
}
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
}
|
||||
|
||||
taxoWriter.close();
|
||||
reader = DirectoryReader.open(writer, true);
|
||||
reader = writer.getReader();
|
||||
writer.close();
|
||||
taxoReader = new DirectoryTaxonomyReader(taxoDir);
|
||||
}
|
||||
|
|
|
@ -61,35 +61,36 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
|
|||
FacetsConfig config = new FacetsConfig();
|
||||
config.setHierarchical("Publish Date");
|
||||
|
||||
IndexWriter writer = new FacetIndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())), taxoWriter, config);
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
DocumentBuilder builder = new DocumentBuilder(taxoWriter, config);
|
||||
|
||||
Document doc = new Document();
|
||||
doc.add(new FacetField("Author", "Bob"));
|
||||
doc.add(new FacetField("Publish Date", "2010", "10", "15"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new FacetField("Author", "Lisa"));
|
||||
doc.add(new FacetField("Publish Date", "2010", "10", "20"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new FacetField("Author", "Lisa"));
|
||||
doc.add(new FacetField("Publish Date", "2012", "1", "1"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new FacetField("Author", "Susan"));
|
||||
doc.add(new FacetField("Publish Date", "2012", "1", "7"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new FacetField("Author", "Frank"));
|
||||
doc.add(new FacetField("Publish Date", "1999", "5", "5"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
// NRT open
|
||||
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
|
||||
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||
writer.close();
|
||||
|
||||
// NRT open
|
||||
|
@ -147,11 +148,12 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
|
|||
// main index:
|
||||
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
|
||||
|
||||
IndexWriter writer = new FacetIndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())), taxoWriter, new FacetsConfig());
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
DocumentBuilder builder = new DocumentBuilder(taxoWriter, new FacetsConfig());
|
||||
|
||||
Document doc = new Document();
|
||||
doc.add(new FacetField("a", "foo1"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
if (random().nextBoolean()) {
|
||||
writer.commit();
|
||||
|
@ -160,7 +162,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
|
|||
doc = new Document();
|
||||
doc.add(new FacetField("a", "foo2"));
|
||||
doc.add(new FacetField("b", "bar1"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
if (random().nextBoolean()) {
|
||||
writer.commit();
|
||||
|
@ -170,10 +172,10 @@ 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(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
// NRT open
|
||||
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
|
||||
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||
writer.close();
|
||||
|
||||
// NRT open
|
||||
|
@ -209,14 +211,15 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
|
|||
|
||||
FacetsConfig config = new FacetsConfig();
|
||||
config.setIndexFieldName("a", "$facets2");
|
||||
IndexWriter writer = new FacetIndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())), taxoWriter, config);
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
DocumentBuilder builder = new DocumentBuilder(taxoWriter, config);
|
||||
|
||||
Document doc = new Document();
|
||||
doc.add(new FacetField("a", "foo1"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
// NRT open
|
||||
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
|
||||
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||
writer.close();
|
||||
|
||||
// NRT open
|
||||
|
@ -280,12 +283,13 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
|
|||
}
|
||||
});
|
||||
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
|
||||
IndexWriter writer = new FacetIndexWriter(dir, iwc, taxoWriter, new FacetsConfig());
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
|
||||
DocumentBuilder builder = new DocumentBuilder(taxoWriter, new FacetsConfig());
|
||||
|
||||
Document doc = new Document();
|
||||
doc.add(newTextField("field", "text", Field.Store.NO));
|
||||
doc.add(new FacetField("a", "path"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
writer.close();
|
||||
taxoWriter.close();
|
||||
dir.close();
|
||||
|
@ -296,20 +300,20 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
|
|||
Directory dir = newDirectory();
|
||||
Directory taxoDir = newDirectory();
|
||||
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
|
||||
IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
|
||||
FacetsConfig config = new FacetsConfig();
|
||||
config.setHierarchical("a");
|
||||
config.setMultiValued("a");
|
||||
IndexWriter writer = new FacetIndexWriter(dir, iwc, taxoWriter, config);
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
DocumentBuilder builder = new DocumentBuilder(taxoWriter, config);
|
||||
|
||||
Document doc = new Document();
|
||||
doc.add(newTextField("field", "text", Field.Store.NO));
|
||||
doc.add(new FacetField("a", "path", "x"));
|
||||
doc.add(new FacetField("a", "path", "y"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
// NRT open
|
||||
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
|
||||
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||
writer.close();
|
||||
|
||||
// NRT open
|
||||
|
|
|
@ -63,37 +63,38 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
|
|||
// main index:
|
||||
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
|
||||
|
||||
IndexWriter writer = new FacetIndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())), taxoWriter, new FacetsConfig());
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
DocumentBuilder builder = new DocumentBuilder(taxoWriter, 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(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new IntField("num", 20, Field.Store.NO));
|
||||
doc.add(new FacetField("Author", "Lisa"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new IntField("num", 30, Field.Store.NO));
|
||||
doc.add(new FacetField("Author", "Lisa"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new IntField("num", 40, Field.Store.NO));
|
||||
doc.add(new FacetField("Author", "Susan"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
doc = new Document();
|
||||
doc.add(new IntField("num", 45, Field.Store.NO));
|
||||
doc.add(new FacetField("Author", "Frank"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
// NRT open
|
||||
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
|
||||
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||
writer.close();
|
||||
|
||||
// NRT open
|
||||
|
@ -129,12 +130,13 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
|
|||
// main index:
|
||||
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
|
||||
|
||||
IndexWriter writer = new FacetIndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())), taxoWriter, new FacetsConfig());
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
DocumentBuilder builder = new DocumentBuilder(taxoWriter, new FacetsConfig());
|
||||
|
||||
Document doc = new Document();
|
||||
doc.add(new IntField("num", 10, Field.Store.NO));
|
||||
doc.add(new FacetField("a", "foo1"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
if (random().nextBoolean()) {
|
||||
writer.commit();
|
||||
|
@ -144,7 +146,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(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
if (random().nextBoolean()) {
|
||||
writer.commit();
|
||||
|
@ -155,10 +157,10 @@ 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(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
// NRT open
|
||||
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
|
||||
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||
writer.close();
|
||||
|
||||
// NRT open
|
||||
|
@ -196,15 +198,16 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
|
|||
FacetsConfig config = new FacetsConfig();
|
||||
config.setIndexFieldName("a", "$facets2");
|
||||
|
||||
IndexWriter writer = new FacetIndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())), taxoWriter, config);
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
DocumentBuilder builder = new DocumentBuilder(taxoWriter, config);
|
||||
|
||||
Document doc = new Document();
|
||||
doc.add(new IntField("num", 10, Field.Store.NO));
|
||||
doc.add(new FacetField("a", "foo1"));
|
||||
writer.addDocument(doc);
|
||||
writer.addDocument(builder.build(doc));
|
||||
|
||||
// NRT open
|
||||
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
|
||||
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||
writer.close();
|
||||
|
||||
// NRT open
|
||||
|
|
Loading…
Reference in New Issue