Search in sources :

Example 21 with FacetField

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);
    }
}
Also used : FacetField(org.apache.lucene.facet.FacetField)

Example 22 with FacetField

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);
}
Also used : Random(java.util.Random) FacetField(org.apache.lucene.facet.FacetField)

Example 23 with FacetField

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);
}
Also used : FacetsConfig(org.apache.lucene.facet.FacetsConfig) FacetField(org.apache.lucene.facet.FacetField) Document(org.apache.lucene.document.Document)

Example 24 with FacetField

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());
    }
}
Also used : FacetField(org.apache.lucene.facet.FacetField)

Example 25 with FacetField

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();
}
Also used : ArrayList(java.util.ArrayList) FacetField(org.apache.lucene.facet.FacetField)

Aggregations

FacetField (org.apache.lucene.facet.FacetField)42 Document (org.apache.lucene.document.Document)36 DirectoryTaxonomyWriter (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter)31 FacetsConfig (org.apache.lucene.facet.FacetsConfig)29 Directory (org.apache.lucene.store.Directory)28 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)26 DirectoryTaxonomyReader (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader)22 Facets (org.apache.lucene.facet.Facets)19 IndexWriter (org.apache.lucene.index.IndexWriter)16 FacetsCollector (org.apache.lucene.facet.FacetsCollector)14 IndexSearcher (org.apache.lucene.search.IndexSearcher)14 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)13 FacetResult (org.apache.lucene.facet.FacetResult)11 DirectoryReader (org.apache.lucene.index.DirectoryReader)11 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)10 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)8 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)8 HashMap (java.util.HashMap)4 WhitespaceAnalyzer (org.apache.lucene.analysis.core.WhitespaceAnalyzer)4 StringField (org.apache.lucene.document.StringField)4