Query baseQuery = new MatchAllDocsQuery(); DrillDownQuery ddQuery = new DrillDownQuery(config, baseQuery); ddQuery.add("city", "california"); FacetsCollector fc = new FacetsCollector(); FacetsCollector.search(searcher, ddQuery, 10, fc);
/** Adds one dimension of drill downs; if you pass the same * dimension more than once it is OR'd with the previous * cofnstraints on that dimension, and all dimensions are * AND'd against each other and the base query. */ public void add(String dim, String... path) { String indexedField = config.getDimConfig(dim).indexFieldName; add(dim, new TermQuery(term(indexedField, dim, path))); }
/** Adds one dimension of drill downs; if you pass the same * dimension more than once it is OR'd with the previous * cofnstraints on that dimension, and all dimensions are * AND'd against each other and the base query. */ public void add(String dim, String... path) { String indexedField = config.getDimConfig(dim).indexFieldName; add(dim, new TermQuery(term(indexedField, dim, path))); }
private DrillDownQuery getDrillDownQuery(final DrillDownQuery query, Query[] queries, final String excludedDimension) { final DrillDownQuery ddl = new DrillDownQuery(config, query.getBaseQuery()); query.getDims().forEach((dim, pos) -> { if (!dim.equals(excludedDimension)) ddl.add(dim, queries[pos]); }); return ddl.getDims().size() == queries.length ? null : ddl; }
/** 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); }
private static long countPages(IndexSearcher indexSearcher, RcCollectionMetadata rcCollMd) throws IOException { Query query = new TermQuery(new Term(RcIrStaticField.DOCUMENT_TYPE.getFieldName(), RcIrDocumentType.PAGE.name())); if (rcCollMd != null) { query = new DrillDownQuery(RcIrSearcher.FACETS_CONFIG, query); RcIrFacetPath facetPath = getFacetPath(rcCollMd); ((DrillDownQuery) query).add(facetPath.getDimension(), facetPath.getPath()); } int limit = 1; TopDocs topDocs = indexSearcher.search(query, limit); return topDocs.totalHits; }
@Override final public org.apache.lucene.facet.DrillDownQuery getQuery(final QueryContext queryContext) throws IOException, ParseException, ReflectiveOperationException, QueryNodeException { final org.apache.lucene.facet.DrillDownQuery drillDownQuery; final FieldMap fieldMap = queryContext.getFieldMap(); final Map<String, String> dimensions = new HashMap<>(); final Map<String, String> resolvedDimensions = new HashMap<>(); dimPath.forEach(map -> map.keySet().forEach(concreteField -> { final String genericField = genericFieldNames.getOrDefault(concreteField, concreteField); dimensions.put(concreteField, genericField); if (fieldMap != null) resolvedDimensions.put(concreteField, fieldMap.resolveQueryFieldName(genericField, concreteField)); })); final FacetsConfig facetsConfig = queryContext.getFacetsConfig(resolvedDimensions); Objects.requireNonNull(facetsConfig, "FacetsConfig is null"); if (baseQuery == null) drillDownQuery = new org.apache.lucene.facet.DrillDownQuery(facetsConfig); else drillDownQuery = new org.apache.lucene.facet.DrillDownQuery(facetsConfig, baseQuery.getQuery(queryContext)); dimPath.forEach(dimPath -> dimPath.forEach( (dim, path) -> drillDownQuery.add(resolvedDimensions.getOrDefault(dim, dim), path))); return drillDownQuery; }
private static long countPages(IndexSearcher indexSearcher, String title) throws IOException { Query query = new DrillDownQuery(RcIrSearcher.FACETS_CONFIG); RcIrFacetPath facetPath = new RcIrFacetPath(RcIrStaticField.TITLE.getFieldName(), title); ((DrillDownQuery) query).add(facetPath.getDimension(), facetPath.getPath()); int limit = 1; TopDocs topDocs = indexSearcher.search(query, limit); return topDocs.totalHits; }
/** User drills down on 'Publish Year/2010'. */ 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; }
/** User drills down on 'Publish Date/2010', and we * return facets for both 'Publish Date' and 'Author', * using DrillSideways. */ 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; }
/** 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(); taxoReader.close(); return result; }
/** User drills down on 'Publish Date/2010', and we * return facets for 'Author' */ 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; }
/** 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 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; }
/** 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 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; }
((DrillDownQuery) query).add(facetPath.getDimension(), facetPath.getPath());
String[] path = queryContext.getDrillDownQuery().split(":"); pathFacet = path[1].split("/"); drillDownQuery.add(path[0], pathFacet); FacetsCollector.search(queryContext.searcher, drillDownQuery, PAGE_SIZE, facetsCollector); } else {
/** User drills down on 'Publish Year/2010'. */ private FacetResult drillDown() throws IOException { DirectoryReader indexReader = DirectoryReader.open(directory); 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; }
path = new String[]{}; drillDownQuery.add(drillDownRequest.getFieldName(), path); drillSideways.search(drillDownQuery, facetsCollector); ValueSource valueSource = this.getCompiledScoreFunction(drillDownRequest.getScoreFunction(),