Example usage for org.apache.lucene.facet DrillDownQuery DrillDownQuery

List of usage examples for org.apache.lucene.facet DrillDownQuery DrillDownQuery

Introduction

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

Prototype

public DrillDownQuery(FacetsConfig config) 

Source Link

Document

Creates a new DrillDownQuery without a base query, to perform a pure browsing query (equivalent to using MatchAllDocsQuery as base).

Usage

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

License:Apache License

/** User drills down on 'tags/solr'. */
private FacetResult drillDown() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):
    DrillDownQuery q = new DrillDownQuery(config);

    // Now user drills down on Publish Date/2010:
    q.add("tags", "solr");
    FacetsCollector fc = new FacetsCollector();
    FacetsCollector.search(searcher, q, 10, fc);

    // Retrieve results
    Facets facets = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc);
    FacetResult result = facets.getTopChildren(10, "genre");

    indexReader.close();/* www .  ja  v  a2 s .  c  o  m*/
    taxoReader.close();

    return result;
}

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

License:Apache License

/** User drills down on the specified range. */
public TopDocs drillDown(DoubleRange range) throws IOException {

    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):
    DrillDownQuery q = new DrillDownQuery(null);
    final DoubleValuesSource vs = getDistanceValueSource();
    q.add("field", range.getQuery(getBoundingBoxQuery(ORIGIN_LATITUDE, ORIGIN_LONGITUDE, range.max), vs));
    DrillSideways ds = new DrillSideways(searcher, config, (TaxonomyReader) null) {
        @Override/* ww w .  j  a va 2  s. c o  m*/
        protected Facets buildFacetsResult(FacetsCollector drillDowns, FacetsCollector[] drillSideways,
                String[] drillSidewaysDims) throws IOException {
            assert drillSideways.length == 1;
            return new DoubleRangeFacetCounts("field", vs, drillSideways[0], ONE_KM, TWO_KM, FIVE_KM, TEN_KM);
        }
    };
    return ds.search(q, 10).hits;
}

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

License:Apache License

/** User drills down on the specified range. */
public TopDocs drillDown(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));
    return searcher.search(q, 10);
}

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.j  a  va2  s .co 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;
}

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

License:Apache License

/**
 * User drills down on 'Publish Date/2011', and we
 * return facets for 'Author'//from  ww  w  .j a  v a 2s. com
 */
private FacetResult drillDown() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):
    DrillDownQuery q = new DrillDownQuery(config);

    // Now user drills down on Publish Date/2010:
    q.add("Publish Date", "2010");
    FacetsCollector fc = new FacetsCollector();
    FacetsCollector.search(searcher, q, 10, fc);

    // Retrieve results
    Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);
    FacetResult result = facets.getTopChildren(10, "Author");

    indexReader.close();
    taxoReader.close();

    return result;
}

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

License:Apache License

/**
 * User drills down on 'Publish Date/2012', and we
 * return facets for both 'Publish Date' and 'Author',
 * using DrillSideways.// w  w w .  ja  v  a2 s  . c  o m
 */
private List<FacetResult> drillSideways() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):
    DrillDownQuery q = new DrillDownQuery(config);

    // Now user drills down on Publish Date/2010:
    q.add("Publish Date", "2010");

    DrillSideways ds = new DrillSideways(searcher, config, taxoReader);
    DrillSidewaysResult result = ds.search(q, 10);

    // Retrieve results
    List<FacetResult> facets = result.facets.getAllDims(10);
    System.out.println("totalHits:" + result.hits.totalHits);
    ScoreDoc[] docs = result.hits.scoreDocs;
    System.out.println(searcher.doc(docs[0].doc));

    indexReader.close();
    taxoReader.close();

    return facets;
}

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

License:Apache License

/**
 * User drills down on 'Publish Year/2010'.
 */// www .  j  a v  a2 s  .  c om
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;
}

From source file:com.justinleegrant.myluceneplayground.SimpleFacetsExample.java

License:Apache License

/** User drills down on 'Publish Date/2010', and we
 *  return facets for both 'Publish Date' and 'Author',
 *  using DrillSideways. *///w  ww  .ja  v a  2s  . c  om
private List<FacetResult> drillSideways() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):
    DrillDownQuery q = new DrillDownQuery(config);

    // Now user drills down on Publish Date/2010:
    q.add("Publish Date", "2010");

    DrillSideways ds = new DrillSideways(searcher, config, taxoReader);
    DrillSidewaysResult result = ds.search(q, 10);

    // Retrieve results
    List<FacetResult> facets = result.facets.getAllDims(10);

    indexReader.close();
    taxoReader.close();

    return facets;
}

From source file:com.orientechnologies.lucene.test.LuceneNativeFacet.java

License:Apache License

/** User drills down on 'Publish Date/2010', and we
 *  return facets for both 'Publish Date' and 'Author',
 *  using DrillSideways. */// w w  w  .j  a va2 s .co  m
private List<FacetResult> drillSideways() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):
    DrillDownQuery q = new DrillDownQuery(config);

    // Now user drills down on Publish Date/2010:
    q.add("Publish Date", "2010");

    DrillSideways ds = new DrillSideways(searcher, config, taxoReader);
    DrillSidewaysResult result = ds.search(q, 10);

    // Retrieve results

    List<FacetResult> facets = result.facets.getAllDims(10);

    indexReader.close();
    taxoReader.close();

    return facets;
}

From source file:com.search.lucene.demo.facet.DistanceFacetsExample.java

License:Apache License

/** User drills down on the specified range. */
public TopDocs drillDown(DoubleRange range) throws IOException {

    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):
    DrillDownQuery q = new DrillDownQuery(null);
    final ValueSource vs = getDistanceValueSource();
    //    q.add("field", range.getFilter(getBoundingBoxFilter(ORIGIN_LATITUDE, ORIGIN_LONGITUDE, range.max), vs));
    DrillSideways ds = new DrillSideways(searcher, config, (TaxonomyReader) null) {
        @Override//from   w w  w .j  a  v a  2 s  .  c om
        protected Facets buildFacetsResult(FacetsCollector drillDowns, FacetsCollector[] drillSideways,
                String[] drillSidewaysDims) throws IOException {
            assert drillSideways.length == 1;
            return new DoubleRangeFacetCounts("field", vs, drillSideways[0], ONE_KM, TWO_KM, FIVE_KM, TEN_KM);
        }
    };
    return ds.search(q, 10).hits;
}