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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations