Example usage for org.apache.lucene.facet.range LongRangeFacetCounts LongRangeFacetCounts

List of usage examples for org.apache.lucene.facet.range LongRangeFacetCounts LongRangeFacetCounts

Introduction

In this page you can find the example usage for org.apache.lucene.facet.range LongRangeFacetCounts LongRangeFacetCounts.

Prototype

public LongRangeFacetCounts(String field, LongValuesSource valueSource, FacetsCollector hits,
        Query fastMatchQuery, LongRange... ranges) throws IOException 

Source Link

Document

Create LongRangeFacetCounts , using the provided LongValuesSource , and using the provided Filter as a fastmatch: only documents passing the filter are checked for the matching ranges, which is helpful when the provided LongValuesSource is costly per-document, such as a geo distance.

Usage

From source file:com.czw.search.lucene.example.facet.RangeFacetsExample.java

License:Apache License

/** User runs a query and counts facets. */
public FacetResult search() throws IOException {

    // Aggregates 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);

    Facets facets = new LongRangeFacetCounts("timestamp", fc, PAST_HOUR, PAST_SIX_HOURS, PAST_DAY);
    return facets.getTopChildren(10, "timestamp");
}

From source file:com.czw.search.lucene.example.facet.RangeFacetsExample.java

License:Apache License

/** User drills down on the specified range, and also computes drill sideways counts. */
public DrillSideways.DrillSidewaysResult drillSideways(LongRange range) throws IOException {
    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):
    DrillDownQuery q = new DrillDownQuery(getConfig());
    q.add("timestamp", LongPoint.newRangeQuery("timestamp", range.min, range.max));

    // DrillSideways only handles taxonomy and sorted set drill facets by default; to do range facets we must subclass and override the
    // buildFacetsResult method.
    DrillSideways.DrillSidewaysResult result = new DrillSideways(searcher, getConfig(), null, null) {
        @Override//from   w ww.  ja  v a  2 s  .c o  m
        protected Facets buildFacetsResult(FacetsCollector drillDowns, FacetsCollector[] drillSideways,
                String[] drillSidewaysDims) throws IOException {
            // If we had other dims we would also compute their drill-down or drill-sideways facets here:
            assert drillSidewaysDims[0].equals("timestamp");
            return new LongRangeFacetCounts("timestamp", drillSideways[0], PAST_HOUR, PAST_SIX_HOURS, PAST_DAY);
        }
    }.search(q, 10);

    return result;
}