/** * Returns the set of document ids matching both the query and the filter. * This method is cache-aware and attempts to retrieve the answer from the cache if possible. * If the answer was not cached, it may have been inserted into the cache as a result of this call. * <p> * * @param query * @param filter may be null * @return DocSet meeting the specified criteria, should <b>not</b> be modified by the caller. */ public DocSet getDocSet(Query query, DocSet filter) throws IOException { return getDocSet(query, filter, null); }
/** * Returns the set of document ids matching both the query and the filter. * This method is cache-aware and attempts to retrieve the answer from the cache if possible. * If the answer was not cached, it may have been inserted into the cache as a result of this call. * <p> * * @param query * @param filter may be null * @return DocSet meeting the specified criteria, should <b>not</b> be modified by the caller. */ public DocSet getDocSet(Query query, DocSet filter, DocSetAwareCollector collector) throws IOException { if (filter==null) return getDocSet(query, collector); // Negative query if absolute value different from original Query absQ = QueryUtils.getAbs(query); boolean positive = absQ==query; DocSet first; if (filterCache != null) { first = (DocSet)filterCache.get(absQ); if (first==null) { first = getDocSetNC(absQ,null); filterCache.put(absQ,first); } return positive ? first.intersection(filter) : filter.andNot(first); } // If there isn't a cache, then do a single filtered query if positive. return positive ? getDocSetNC(absQ,filter,collector) : filter.andNot(getPositiveDocSet(absQ, collector)); }
/** * Returns the set of document ids matching a query. * This method is cache-aware and attempts to retrieve the answer from the cache if possible. * If the answer was not cached, it may have been inserted into the cache as a result of this call. * This method can handle negative queries. * <p> * The DocSet returned should <b>not</b> be modified. * * @param query The specified query that must match with the document ids * @return the set of document ids matching all queries. Set may not be modified * @throws IOException If an IO related exception occurs */ public DocSet getDocSet(Query query) throws IOException { return getDocSet(query, (DocSetAwareCollector) null); }
/** * SolrIndexSearch.numDocs(Query,Query) freaks out if the filtering * query is null, so we use this workarround. */ public static int numDocs(SolrIndexSearcher s, Query q, Query f) throws IOException { return (null == f) ? s.getDocSet(q).size() : s.numDocs(q,f); }
/** * Returns a count of the documents in the set which do not have any * terms for for the specified field. * * @see FacetParams#FACET_MISSING */ public static int getFieldMissingCount(SolrIndexSearcher searcher, DocSet docs, String fieldName) throws IOException { DocSet hasVal = searcher.getDocSet (new TermRangeQuery(fieldName, null, null, false, false)); return docs.andNotSize(hasVal); }
/** * Given a base docset, computes the subset of documents corresponding to the specified pivotValue * * @param base the set of documents to evaluate relative to * @param field the field type used by the pivotValue * @param pivotValue String representation of the value, may be null (ie: "missing") */ private DocSet getSubset(DocSet base, SchemaField field, String pivotValue) throws IOException { FieldType ft = field.getType(); if ( null == pivotValue ) { Query query = ft.getRangeQuery(null, field, null, null, false, false); DocSet hasVal = searcher.getDocSet(query); return base.andNot(hasVal); } else { Query query = ft.getFieldQuery(null, field, pivotValue); // for tokenizer chains that are not idempotent (values disappear // if passed thru twice) this blow up (same in facet module) // as query is null if(query == null) { // return empty DocSet return base.andNot(base); } return searcher.getDocSet(query, base); } } }
private Map<String, Set<String>> findParentIdsForNodes(SolrIndexSearcher searcher, Collection<String> nodeIds) throws IOException { Map<String, Set<String>> parentIds = new HashMap<>(); LOGGER.debug("Looking up parents for {} nodes", nodeIds.size()); Query filter = buildFilterQuery(getNodeField(), nodeIds); LOGGER.trace("Filter query: {}", filter); DocSet docs = searcher.getDocSet(filter); for (DocIterator it = docs.iterator(); it.hasNext(); ) { Document doc = searcher.doc(it.nextDoc(), docFields); String nodeId = doc.get(getNodeField()); Set<String> parentIdValues = new HashSet<>(Arrays.asList(doc.getValues(parentField))); parentIds.put(nodeId, parentIdValues); // Record the label, if required if (isLabelRequired(nodeId)) { recordLabel(nodeId, doc.getValues(getLabelField())); } } return parentIds; }
/** * {@inheritDoc} */ @Override protected void doQuery(Query mainQuery, List<Query> filterQueries, Sort sort) throws IOException { final int maxDoc = searcher.maxDoc(); if (containsSortOnScore(sort)) { DocSetScoreCollector docSetCollector = new DocSetScoreCollector(searcher.maxDoc()); long startTime = System.currentTimeMillis(); DocSet filter = searcher.getDocSet(filterQueries); uncollapsedDocSet = searcher.getDocSet(mainQuery, filter, docSetCollector); timeCreateUncollapedDocset = System.currentTimeMillis() - startTime; if (sort == null) { sort = new Sort(new SortField("score", SortField.SCORE, true)); } float[] scores; if (uncollapsedDocSet instanceof DocSetScoreCollector.DelegateDocSet) { scores = ((DocSetScoreCollector.DelegateDocSet) uncollapsedDocSet).getScores(); } else { scores = docSetCollector.getScores(); } documentComparator = new DocumentComparator(sort, maxDoc, searcher.getIndexReader(), scores); } else { long startTime = System.currentTimeMillis(); DocSet filter = searcher.getDocSet(filterQueries); uncollapsedDocSet = searcher.getDocSet(mainQuery, filter); timeCreateUncollapedDocset = System.currentTimeMillis() - startTime; documentComparator = new DocumentComparator(sort, maxDoc, searcher.getIndexReader()); } }
LOGGER.trace("Filter query: {}", filter); DocSet docs = searcher.getDocSet(filter);
if (queries.size()==1) return getDocSet(queries.get(0)); DocSet answer=null;
private DocSet getDocSet(ResponseBuilder rb, String buildQuery) throws SyntaxError, IOException { SolrParams params = rb.req.getParams(); String defType = params.get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE); QParser parser = QParser.getParser(buildQuery, defType, rb.req); Query query = parser.getQuery(); return rb.req.getSearcher().getDocSet(query); }
base = searcher.getDocSet(qlist);
final DocSet docSet = searcher.getDocSet(filterQueries);//hopefully in the cache
final DocSet docSet = searcher.getDocSet(filterQueries);//hopefully in the cache
/** * Calculates the pivot facets over documents matching the given filter query. Example output: * <p> * host: h01 * pivot: * ..metric: cpu * ..metric: heap * ..pivot: * ....process: java * ....process: php * host: h02 * ..metric: cpu * ..pivot: * ....process: java * * @param dimensions the comma separated list of fields * @param fq the filter query * @return pivot table * @throws IOException iff something goes wrong */ public List<NamedList<Object>> pivot(String dimensions, Query fq) throws IOException { ModifiableSolrParams params = new ModifiableSolrParams(req.getParams()); params.set(FACET_PIVOT, split(dimensions, ',')); params.set(FACET_ZEROS, false); params.set(FACET_LIMIT, -1); params.set(FACET_PIVOT_MINCOUNT, 1); DocSet matchingDocs = req.getSearcher().getDocSet(fq); PivotFacetProcessor pivot = dependencyProvider.pivotFacetProcessor(req, rsp, matchingDocs, params); return pivot.process(new String[]{dimensions}).get(dimensions); }
res.docSet = rb.req.getSearcher().getDocSet(queries); } catch (IOException e) { throw new RuntimeException("Error while creating docSet in ACSC!", e);
List<Query> filters = rb.getFilters(); if (filters != null) queries.addAll(filters); res.docSet = searcher.getDocSet(queries);
private void getDocListNC(QueryResult qr,QueryCommand cmd) throws IOException { DocSet filter = cmd.getFilter()!=null ? cmd.getFilter() : getDocSet(cmd.getFilterList()); final long timeAllowed = cmd.getTimeAllowed(); int len = cmd.getSupersetMaxDoc();
private DocSet getDocListAndSetNC(QueryResult qr,QueryCommand cmd) throws IOException { int len = cmd.getSupersetMaxDoc(); DocSet filter = cmd.getFilter()!=null ? cmd.getFilter() : getDocSet(cmd.getFilterList()); int last = len; if (last < 0 || last > maxDoc()) last=maxDoc();