List of usage examples for org.apache.lucene.expressions Expression getDoubleValuesSource
public DoubleValuesSource getDoubleValuesSource(Bindings bindings)
From source file:com.czw.search.lucene.example.facet.DistanceFacetsExample.java
License:Apache License
private DoubleValuesSource getDistanceValueSource() { Expression distance; try {// w w w . j a va 2 s . com distance = JavascriptCompiler .compile("haversin(" + ORIGIN_LATITUDE + "," + ORIGIN_LONGITUDE + ",latitude,longitude)"); } catch (ParseException pe) { // Should not happen throw new RuntimeException(pe); } SimpleBindings bindings = new SimpleBindings(); bindings.add(new SortField("latitude", SortField.Type.DOUBLE)); bindings.add(new SortField("longitude", SortField.Type.DOUBLE)); return distance.getDoubleValuesSource(bindings); }
From source file:com.czw.search.lucene.example.facet.ExpressionAggregationFacetsExample.java
License:Apache License
/** User runs a query and aggregates facets. */ private FacetResult search() throws IOException, ParseException { DirectoryReader indexReader = DirectoryReader.open(indexDir); IndexSearcher searcher = new IndexSearcher(indexReader); TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir); // Aggregate categories by an expression that combines the document's score // and its popularity field Expression expr = JavascriptCompiler.compile("_score * sqrt(popularity)"); SimpleBindings bindings = new SimpleBindings(); bindings.add(new SortField("_score", SortField.Type.SCORE)); // the score of the document bindings.add(new SortField("popularity", SortField.Type.LONG)); // the value of the 'popularity' field // Aggregates the facet values FacetsCollector fc = new FacetsCollector(true); // 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 TaxonomyFacetSumValueSource(taxoReader, config, fc, expr.getDoubleValuesSource(bindings)); FacetResult result = facets.getTopChildren(10, "A"); indexReader.close();//from w ww . j a va2 s . c om taxoReader.close(); return result; }