Search in sources :

Example 1 with SortedSetDocValuesFacetCounts

use of org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts in project jackrabbit-oak by apache.

the class FacetHelper method getFacets.

public static Facets getFacets(IndexSearcher searcher, Query query, TopDocs docs, QueryIndex.IndexPlan plan, boolean secure) throws IOException {
    Facets facets = null;
    @SuppressWarnings("unchecked") List<String> facetFields = (List<String>) plan.getAttribute(ATTR_FACET_FIELDS);
    if (facetFields != null && facetFields.size() > 0) {
        Map<String, Facets> facetsMap = new HashMap<String, Facets>();
        for (String facetField : facetFields) {
            FacetsCollector facetsCollector = new FacetsCollector();
            try {
                DefaultSortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(searcher.getIndexReader(), FieldNames.createFacetFieldName(facetField));
                FacetsCollector.search(searcher, query, 10, facetsCollector);
                facetsMap.put(facetField, secure ? new FilteredSortedSetDocValuesFacetCounts(state, facetsCollector, plan.getFilter(), docs) : new SortedSetDocValuesFacetCounts(state, facetsCollector));
            } catch (IllegalArgumentException iae) {
                LOGGER.warn("facets for {} not yet indexed", facetField);
            }
        }
        if (facetsMap.size() > 0) {
            facets = new MultiFacets(facetsMap);
        }
    }
    return facets;
}
Also used : MultiFacets(org.apache.lucene.facet.MultiFacets) Facets(org.apache.lucene.facet.Facets) HashMap(java.util.HashMap) FacetsCollector(org.apache.lucene.facet.FacetsCollector) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) List(java.util.List) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts) MultiFacets(org.apache.lucene.facet.MultiFacets)

Example 2 with SortedSetDocValuesFacetCounts

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

the class TimeCodeSearcher method getYearMonthDayFacetResults.

/**
     * Returns the matching yearmonthday facets for a given query
     */
private List<CodeFacetYearMonthDay> getYearMonthDayFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
    List<CodeFacetYearMonthDay> codeFacetYearMonthDay = new ArrayList<>();
    try {
        SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.DATEYEARMONTHDAY);
        FacetsCollector fc = new FacetsCollector();
        FacetsCollector.search(searcher, query, 10, fc);
        Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
        FacetResult result = facets.getTopChildren(200, Values.DATEYEARMONTHDAY);
        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) {
                    codeFacetYearMonthDay.add(new CodeFacetYearMonthDay(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 codeFacetYearMonthDay;
}
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 3 with SortedSetDocValuesFacetCounts

use of org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts 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 4 with SortedSetDocValuesFacetCounts

use of org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts 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 5 with SortedSetDocValuesFacetCounts

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

the class DrillSideways method buildFacetsResult.

/**
   * Subclass can override to customize per-dim Facets
   * impl.
   */
protected Facets buildFacetsResult(FacetsCollector drillDowns, FacetsCollector[] drillSideways, String[] drillSidewaysDims) throws IOException {
    Facets drillDownFacets;
    Map<String, Facets> drillSidewaysFacets = new HashMap<>();
    if (taxoReader != null) {
        drillDownFacets = new FastTaxonomyFacetCounts(taxoReader, config, drillDowns);
        if (drillSideways != null) {
            for (int i = 0; i < drillSideways.length; i++) {
                drillSidewaysFacets.put(drillSidewaysDims[i], new FastTaxonomyFacetCounts(taxoReader, config, drillSideways[i]));
            }
        }
    } else {
        drillDownFacets = new SortedSetDocValuesFacetCounts(state, drillDowns);
        if (drillSideways != null) {
            for (int i = 0; i < drillSideways.length; i++) {
                drillSidewaysFacets.put(drillSidewaysDims[i], new SortedSetDocValuesFacetCounts(state, drillSideways[i]));
            }
        }
    }
    if (drillSidewaysFacets.isEmpty()) {
        return drillDownFacets;
    } else {
        return new MultiFacets(drillSidewaysFacets, drillDownFacets);
    }
}
Also used : FastTaxonomyFacetCounts(org.apache.lucene.facet.taxonomy.FastTaxonomyFacetCounts) HashMap(java.util.HashMap) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts)

Aggregations

SortedSetDocValuesFacetCounts (org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts)15 Facets (org.apache.lucene.facet.Facets)14 FacetsCollector (org.apache.lucene.facet.FacetsCollector)14 DefaultSortedSetDocValuesReaderState (org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState)14 FacetResult (org.apache.lucene.facet.FacetResult)13 SortedSetDocValuesReaderState (org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState)13 IOException (java.io.IOException)11 LabelAndValue (org.apache.lucene.facet.LabelAndValue)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)2 DirectoryReader (org.apache.lucene.index.DirectoryReader)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 List (java.util.List)1 DrillDownQuery (org.apache.lucene.facet.DrillDownQuery)1 MultiFacets (org.apache.lucene.facet.MultiFacets)1 FastTaxonomyFacetCounts (org.apache.lucene.facet.taxonomy.FastTaxonomyFacetCounts)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1