use of org.apache.lucene.facet.FacetField in project lucene-solr by apache.
the class TestTaxonomyFacetCounts2 method addFacets.
private static void addFacets(Document doc, FacetsConfig config, boolean updateTermExpectedCounts) throws IOException {
List<FacetField> docCategories = randomCategories(random());
for (FacetField ff : docCategories) {
doc.add(ff);
String cp = ff.dim + "/" + ff.path[0];
allExpectedCounts.put(cp, allExpectedCounts.get(cp) + 1);
if (updateTermExpectedCounts) {
termExpectedCounts.put(cp, termExpectedCounts.get(cp) + 1);
}
}
// add 1 to each NO_PARENTS dimension
allExpectedCounts.put(CP_B, allExpectedCounts.get(CP_B) + 1);
allExpectedCounts.put(CP_C, allExpectedCounts.get(CP_C) + 1);
allExpectedCounts.put(CP_D, allExpectedCounts.get(CP_D) + 1);
if (updateTermExpectedCounts) {
termExpectedCounts.put(CP_B, termExpectedCounts.get(CP_B) + 1);
termExpectedCounts.put(CP_C, termExpectedCounts.get(CP_C) + 1);
termExpectedCounts.put(CP_D, termExpectedCounts.get(CP_D) + 1);
}
}
use of org.apache.lucene.facet.FacetField in project lucene-solr by apache.
the class TestConcurrentFacetedIndexing method newCategory.
static FacetField newCategory() {
Random r = random();
// l1.0-l1.9 (10 categories)
String l1 = "l1." + r.nextInt(10);
// l2.0-l2.29 (30 categories)
String l2 = "l2." + r.nextInt(30);
// l3.0-l3.99 (100 categories)
String l3 = "l3." + r.nextInt(100);
return new FacetField(l1, l2, l3);
}
use of org.apache.lucene.facet.FacetField in project lucene-solr by apache.
the class IndexAndTaxonomyRevisionTest method newDocument.
private Document newDocument(TaxonomyWriter taxoWriter) throws IOException {
FacetsConfig config = new FacetsConfig();
Document doc = new Document();
doc.add(new FacetField("A", "1"));
return config.build(taxoWriter, doc);
}
use of org.apache.lucene.facet.FacetField in project lucene-solr by apache.
the class RandomFacetSource method getNextFacets.
@Override
public void getNextFacets(List<FacetField> facets) throws NoMoreDataException, IOException {
facets.clear();
// at least one facet to each doc
int numFacets = 1 + random.nextInt(maxDocFacets);
for (int i = 0; i < numFacets; i++) {
int depth;
if (maxFacetDepth == 2) {
depth = 2;
} else {
// depth < 2 is not useful
depth = 2 + random.nextInt(maxFacetDepth - 2);
}
String dim = Integer.toString(random.nextInt(maxDims));
String[] components = new String[depth - 1];
for (int k = 0; k < depth - 1; k++) {
components[k] = Integer.toString(random.nextInt(maxValue));
addItem();
}
FacetField ff = new FacetField(dim, components);
facets.add(ff);
// very rough approximation
addBytes(ff.toString().length());
}
}
use of org.apache.lucene.facet.FacetField in project lucene-solr by apache.
the class AddFacetedDocTask method doLogic.
@Override
public int doLogic() throws Exception {
if (config != null) {
List<FacetField> facets = new ArrayList<>();
getRunData().getFacetSource().getNextFacets(facets);
for (FacetField ff : facets) {
doc.add(ff);
}
doc = config.build(getRunData().getTaxonomyWriter(), doc);
}
return super.doLogic();
}
Aggregations