Search in sources :

Example 26 with FacetsCollector

use of org.apache.lucene.facet.FacetsCollector in project searchcode-server by boyter.

the class CodeSearcher method getRepoFacetResults.

/**
     * Returns the matching repository facets for a given query
     */
private List<CodeFacetRepo> getRepoFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
    List<CodeFacetRepo> codeFacetRepo = new ArrayList<>();
    try {
        SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.REPONAME);
        FacetsCollector fc = new FacetsCollector();
        FacetsCollector.search(searcher, query, 10, fc);
        Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
        FacetResult result = facets.getTopChildren(200, Values.REPONAME);
        if (result != null) {
            int stepThru = result.childCount > 200 ? 200 : result.childCount;
            for (int i = 0; i < stepThru; i++) {
                LabelAndValue lv = result.labelValues[i];
                if (lv != null && lv.value != null) {
                    codeFacetRepo.add(new CodeFacetRepo(lv.label, lv.value.intValue()));
                }
            }
        }
    } catch (IOException ex) {
    } catch (Exception ex) {
    }
    return codeFacetRepo;
}
Also used : SortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) Facets(org.apache.lucene.facet.Facets) IOException(java.io.IOException) LabelAndValue(org.apache.lucene.facet.LabelAndValue) IOException(java.io.IOException) FacetsCollector(org.apache.lucene.facet.FacetsCollector) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts) FacetResult(org.apache.lucene.facet.FacetResult)

Example 27 with FacetsCollector

use of org.apache.lucene.facet.FacetsCollector in project searchcode-server by boyter.

the class TimeCodeSearcher method getRepoFacetResults.

/**
     * Returns the matching repository facets for a given query
     */
private List<CodeFacetRepo> getRepoFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
    List<CodeFacetRepo> codeFacetRepo = new ArrayList<>();
    try {
        SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.REPONAME);
        FacetsCollector fc = new FacetsCollector();
        FacetsCollector.search(searcher, query, 10, fc);
        Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
        FacetResult result = facets.getTopChildren(200, Values.REPONAME);
        if (result != null) {
            int stepThru = result.childCount > 200 ? 200 : result.childCount;
            for (int i = 0; i < stepThru; i++) {
                LabelAndValue lv = result.labelValues[i];
                if (lv != null && lv.value != null) {
                    codeFacetRepo.add(new CodeFacetRepo(lv.label, lv.value.intValue()));
                }
            }
        }
    } catch (IOException ex) {
        LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
    } catch (Exception ex) {
        LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
    }
    return codeFacetRepo;
}
Also used : SortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) Facets(org.apache.lucene.facet.Facets) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LabelAndValue(org.apache.lucene.facet.LabelAndValue) IOException(java.io.IOException) FacetsCollector(org.apache.lucene.facet.FacetsCollector) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts) FacetResult(org.apache.lucene.facet.FacetResult)

Example 28 with FacetsCollector

use of org.apache.lucene.facet.FacetsCollector in project lucene-solr by apache.

the class SimpleFacetsExample method facetsWithSearch.

/** User runs a query and counts facets. */
private List<FacetResult> facetsWithSearch() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
    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:
    FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);
    // Retrieve results
    List<FacetResult> results = new ArrayList<>();
    // Count both "Publish Date" and "Author" dimensions
    Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);
    results.add(facets.getTopChildren(10, "Author"));
    results.add(facets.getTopChildren(10, "Publish Date"));
    indexReader.close();
    taxoReader.close();
    return results;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) FastTaxonomyFacetCounts(org.apache.lucene.facet.taxonomy.FastTaxonomyFacetCounts) Facets(org.apache.lucene.facet.Facets) DirectoryReader(org.apache.lucene.index.DirectoryReader) TaxonomyReader(org.apache.lucene.facet.taxonomy.TaxonomyReader) DirectoryTaxonomyReader(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader) ArrayList(java.util.ArrayList) FacetResult(org.apache.lucene.facet.FacetResult) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DirectoryTaxonomyReader(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader) FacetsCollector(org.apache.lucene.facet.FacetsCollector)

Example 29 with FacetsCollector

use of org.apache.lucene.facet.FacetsCollector in project lucene-solr by apache.

the class SimpleSortedSetFacetsExample method search.

/** User runs a query and counts facets. */
private List<FacetResult> search() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(indexReader);
    // Aggregatses the facet counts
    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:
    FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);
    // Retrieve results
    Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
    List<FacetResult> results = new ArrayList<>();
    results.add(facets.getTopChildren(10, "Author"));
    results.add(facets.getTopChildren(10, "Publish Year"));
    indexReader.close();
    return results;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) SortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) Facets(org.apache.lucene.facet.Facets) DirectoryReader(org.apache.lucene.index.DirectoryReader) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) ArrayList(java.util.ArrayList) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts) FacetResult(org.apache.lucene.facet.FacetResult) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) FacetsCollector(org.apache.lucene.facet.FacetsCollector)

Example 30 with FacetsCollector

use of org.apache.lucene.facet.FacetsCollector in project lucene-solr by apache.

the class SimpleSortedSetFacetsExample method drillDown.

/** User drills down on 'Publish Year/2010'. */
private FacetResult drillDown() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(indexReader);
    // Now user drills down on Publish Year/2010:
    DrillDownQuery q = new DrillDownQuery(config);
    q.add("Publish Year", "2010");
    FacetsCollector fc = new FacetsCollector();
    FacetsCollector.search(searcher, q, 10, fc);
    // Retrieve results
    Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
    FacetResult result = facets.getTopChildren(10, "Author");
    indexReader.close();
    return result;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) SortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) Facets(org.apache.lucene.facet.Facets) DirectoryReader(org.apache.lucene.index.DirectoryReader) DrillDownQuery(org.apache.lucene.facet.DrillDownQuery) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts) FacetResult(org.apache.lucene.facet.FacetResult) FacetsCollector(org.apache.lucene.facet.FacetsCollector)

Aggregations

FacetsCollector (org.apache.lucene.facet.FacetsCollector)67 Facets (org.apache.lucene.facet.Facets)60 FacetResult (org.apache.lucene.facet.FacetResult)42 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)42 IndexSearcher (org.apache.lucene.search.IndexSearcher)41 DirectoryTaxonomyReader (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader)30 Directory (org.apache.lucene.store.Directory)27 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)25 Document (org.apache.lucene.document.Document)24 DirectoryReader (org.apache.lucene.index.DirectoryReader)24 FacetsConfig (org.apache.lucene.facet.FacetsConfig)22 LabelAndValue (org.apache.lucene.facet.LabelAndValue)22 ArrayList (java.util.ArrayList)18 DirectoryTaxonomyWriter (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter)17 FacetField (org.apache.lucene.facet.FacetField)14 DefaultSortedSetDocValuesReaderState (org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState)14 SortedSetDocValuesFacetCounts (org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts)14 IOException (java.io.IOException)13 DrillDownQuery (org.apache.lucene.facet.DrillDownQuery)13 SortedSetDocValuesReaderState (org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState)13