LUCENE-5339: migrate some more tests; fix 'ignores IntsRef.offset bug' in TaxoFacetCounts; add FacetTestCase.getFacetCounts

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5339@1543506 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2013-11-19 17:13:14 +00:00
parent 7027c5690e
commit d815a3608b
5 changed files with 53 additions and 44 deletions

View File

@ -248,6 +248,7 @@ 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) {

View File

@ -60,7 +60,7 @@ public class TaxonomyFacetCounts extends TaxonomyFacets {
while (doc < length && (doc = bits.nextSetBit(doc)) != -1) {
ords.get(doc, scratch);
for(int i=0;i<scratch.length;i++) {
++counts[scratch.ints[i]];
counts[scratch.ints[scratch.offset+i]]++;
}
++doc;
}

View File

@ -40,17 +40,23 @@ import org.apache.lucene.util.IntsRef;
/** Aggregates sum of values from a {@link ValueSource}, for
* each facet label. */
// nocommit jdoc that this assumes/requires the default encoding
public class TaxonomyFacetSumValueSource extends TaxonomyFacets {
private final float[] values;
private final OrdinalsReader ordinalsReader;
/** Aggreggates float facet values from the provided
* {@link ValueSource}, pulling ordinals using {@link
* DocValuesOrdinalsReader} against the default indexed
* facet field {@link
* FacetsConfig#DEFAULT_INDEX_FIELD_NAME}. */
public TaxonomyFacetSumValueSource(TaxonomyReader taxoReader, FacetsConfig config,
SimpleFacetsCollector fc, ValueSource valueSource) throws IOException {
this(new DocValuesOrdinalsReader(FacetsConfig.DEFAULT_INDEX_FIELD_NAME), taxoReader, config, fc, valueSource);
}
/** Aggreggates float facet values from the provided
* {@link ValueSource}, and pulls ordinals from the
* provided {@link OrdinalsReader}. */
public TaxonomyFacetSumValueSource(OrdinalsReader ordinalsReader, TaxonomyReader taxoReader,
FacetsConfig config, SimpleFacetsCollector fc, ValueSource valueSource) throws IOException {
super(ordinalsReader.getIndexFieldName(), taxoReader, config);

View File

@ -1,5 +1,6 @@
package org.apache.lucene.facet;
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.facet.encoding.DGapIntEncoder;
@ -12,6 +13,15 @@ import org.apache.lucene.facet.encoding.SortingIntEncoder;
import org.apache.lucene.facet.encoding.UniqueValuesIntEncoder;
import org.apache.lucene.facet.encoding.VInt8IntEncoder;
import org.apache.lucene.facet.params.CategoryListParams;
import org.apache.lucene.facet.simple.CachedOrdinalsReader;
import org.apache.lucene.facet.simple.DocValuesOrdinalsReader;
import org.apache.lucene.facet.simple.Facets;
import org.apache.lucene.facet.simple.FacetsConfig;
import org.apache.lucene.facet.simple.FastTaxonomyFacetCounts;
import org.apache.lucene.facet.simple.OrdinalsReader;
import org.apache.lucene.facet.simple.SimpleFacetsCollector;
import org.apache.lucene.facet.simple.TaxonomyFacetCounts;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.util.LuceneTestCase;
/*
@ -60,5 +70,19 @@ public abstract class FacetTestCase extends LuceneTestCase {
}
};
}
public Facets getFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, SimpleFacetsCollector c) throws IOException {
Facets facets;
if (random().nextBoolean()) {
facets = new FastTaxonomyFacetCounts(taxoReader, config, c);
} else {
OrdinalsReader ordsReader = new DocValuesOrdinalsReader();
if (random().nextBoolean()) {
ordsReader = new CachedOrdinalsReader(ordsReader);
}
facets = new TaxonomyFacetCounts(ordsReader, taxoReader, config, c);
}
return facets;
}
}

View File

@ -183,16 +183,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
SimpleFacetsCollector c = new SimpleFacetsCollector();
searcher.search(new MatchAllDocsQuery(), c);
Facets facets;
if (random().nextBoolean()) {
facets = new FastTaxonomyFacetCounts(taxoReader, new FacetsConfig(), c);
} else {
OrdinalsReader ordsReader = new DocValuesOrdinalsReader();
if (random().nextBoolean()) {
ordsReader = new CachedOrdinalsReader(ordsReader);
}
facets = new TaxonomyFacetCounts(ordsReader, taxoReader, new FacetsConfig(), c);
}
Facets facets = getFacetCounts(taxoReader, new FacetsConfig(), c);
// Ask for top 10 labels for any dims that have counts:
List<SimpleFacetResult> results = facets.getAllDims(10);
@ -275,7 +266,6 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
// nocommit in the sparse case test that we are really
// sorting by the correct dim count
/*
public void testReallyNoNormsForDrillDown() throws Exception {
Directory dir = newDirectory();
Directory taxoDir = newDirectory();
@ -289,13 +279,12 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
return sim;
}
});
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
FacetFields facetFields = new FacetFields(taxoWriter);
IndexWriter writer = new FacetIndexWriter(dir, iwc, taxoWriter, new FacetsConfig());
Document doc = new Document();
doc.add(newTextField("field", "text", Field.Store.NO));
facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a/path", '/')));
doc.add(new FacetField("a", "path"));
writer.addDocument(doc);
writer.close();
taxoWriter.close();
@ -303,54 +292,42 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
taxoDir.close();
}
public void testAllParents() throws Exception {
public void testMultiValuedHierarchy() throws Exception {
Directory dir = newDirectory();
Directory taxoDir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
CategoryListParams clp = new CategoryListParams("$facets") {
@Override
public OrdinalPolicy getOrdinalPolicy(String fieldName) {
return OrdinalPolicy.ALL_PARENTS;
}
};
FacetIndexingParams fip = new FacetIndexingParams(clp);
FacetFields facetFields = new FacetFields(taxoWriter, fip);
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);
Document doc = new Document();
doc.add(newTextField("field", "text", Field.Store.NO));
facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a/path", '/')));
doc.add(new FacetField("a", "path", "x"));
doc.add(new FacetField("a", "path", "y"));
writer.addDocument(doc);
// NRT open
IndexSearcher searcher = newSearcher(writer.getReader());
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
writer.close();
// NRT open
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
taxoWriter.close();
FacetSearchParams fsp = new FacetSearchParams(fip,
new CountFacetRequest(new CategoryPath("a", '/'), 10));
// Aggregate the facet counts:
FacetsCollector c = FacetsCollector.create(fsp, searcher.getIndexReader(), taxoReader);
SimpleFacetsCollector c = new SimpleFacetsCollector();
// MatchAllDocsQuery is for "browsing" (counts facets
// for all non-deleted docs in the index); normally
// you'd use a "normal" query, and use MultiCollector to
// wrap collecting the "normal" hits and also facets:
searcher.search(new MatchAllDocsQuery(), c);
List<FacetResult> results = c.getFacetResults();
assertEquals(1, results.size());
assertEquals(1, (int) results.get(0).getFacetResultNode().value);
// LUCENE-4913:
for(FacetResultNode childNode : results.get(0).getFacetResultNode().subResults) {
assertTrue(childNode.ordinal != 0);
}
Facets facets = getFacetCounts(taxoReader, config, c);
SimpleFacetResult result = facets.getTopChildren(10, "a");
assertEquals(1, result.labelValues.length);
assertEquals(1, result.labelValues[0].value.intValue());
searcher.getIndexReader().close();
taxoReader.close();
@ -358,6 +335,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
taxoDir.close();
}
/*
public void testLabelWithDelimiter() throws Exception {
Directory dir = newDirectory();
Directory taxoDir = newDirectory();