Search in sources :

Example 16 with DocSet

use of org.apache.solr.search.DocSet in project lucene-solr by apache.

the class FacetRangeProcessor method rangeStats.

private void rangeStats(Range range, int slot) throws IOException {
    Query rangeQ = sf.getType().getRangeQuery(null, sf, range.low == null ? null : calc.formatValue(range.low), range.high == null ? null : calc.formatValue(range.high), range.includeLower, range.includeUpper);
    // TODO: specialize count only
    DocSet intersection = fcontext.searcher.getDocSet(rangeQ, fcontext.base);
    filters[slot] = rangeQ;
    // save for later  // TODO: only save if number of slots is small enough?
    intersections[slot] = intersection;
    int num = collect(intersection, slot);
    // TODO: roll this into collect()
    countAcc.incrementCount(slot, num);
}
Also used : Query(org.apache.lucene.search.Query) DocSet(org.apache.solr.search.DocSet)

Example 17 with DocSet

use of org.apache.solr.search.DocSet in project lucene-solr by apache.

the class PivotFacetProcessor method getSubset.

/**
   * 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);
        return searcher.getDocSet(query, base);
    }
}
Also used : Query(org.apache.lucene.search.Query) DocSet(org.apache.solr.search.DocSet) FieldType(org.apache.solr.schema.FieldType)

Example 18 with DocSet

use of org.apache.solr.search.DocSet in project lucene-solr by apache.

the class PivotFacetProcessor method getSubsetSize.

/**
   * Given a base docset, computes the size of 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 int getSubsetSize(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.andNotSize(hasVal);
    } else {
        Query query = ft.getFieldQuery(null, field, pivotValue);
        return searcher.numDocs(query, base);
    }
}
Also used : Query(org.apache.lucene.search.Query) DocSet(org.apache.solr.search.DocSet) FieldType(org.apache.solr.schema.FieldType)

Example 19 with DocSet

use of org.apache.solr.search.DocSet in project lucene-solr by apache.

the class RangeFacetProcessor method getFacetRangeCounts.

private <T extends Comparable<T>> NamedList getFacetRangeCounts(final RangeFacetRequest rfr) throws IOException, SyntaxError {
    final NamedList<Object> res = new SimpleOrderedMap<>();
    final NamedList<Integer> counts = new NamedList<>();
    res.add("counts", counts);
    // explicitly return the gap.
    res.add("gap", rfr.getGapObj());
    DocSet docSet = computeDocSet(docsOrig, rfr.getExcludeTags());
    for (RangeFacetRequest.FacetRange range : rfr.getFacetRanges()) {
        if (range.other != null) {
            // these are added to top-level NamedList
            // and we always include them regardless of mincount
            res.add(range.other.toString(), rangeCount(docSet, rfr, range));
        } else {
            final int count = rangeCount(docSet, rfr, range);
            if (count >= rfr.getMinCount()) {
                counts.add(range.lower, count);
            }
        }
    }
    // explicitly return the start and end so all the counts
    // (including before/after/between) are meaningful - even if mincount
    // has removed the neighboring ranges
    res.add("start", rfr.getStartObj());
    res.add("end", rfr.getEndObj());
    return res;
}
Also used : NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) DocSet(org.apache.solr.search.DocSet)

Example 20 with DocSet

use of org.apache.solr.search.DocSet in project lucene-solr by apache.

the class SimpleFacets method computeDocSet.

protected DocSet computeDocSet(DocSet baseDocSet, List<String> excludeTagList) throws SyntaxError, IOException {
    Map<?, ?> tagMap = (Map<?, ?>) req.getContext().get("tags");
    // rb can be null if facets are being calculated from a RequestHandler e.g. MoreLikeThisHandler
    if (tagMap == null || rb == null) {
        return baseDocSet;
    }
    IdentityHashMap<Query, Boolean> excludeSet = new IdentityHashMap<>();
    for (String excludeTag : excludeTagList) {
        Object olst = tagMap.get(excludeTag);
        // tagMap has entries of List<String,List<QParser>>, but subject to change in the future
        if (!(olst instanceof Collection))
            continue;
        for (Object o : (Collection<?>) olst) {
            if (!(o instanceof QParser))
                continue;
            QParser qp = (QParser) o;
            excludeSet.put(qp.getQuery(), Boolean.TRUE);
        }
    }
    if (excludeSet.size() == 0)
        return baseDocSet;
    List<Query> qlist = new ArrayList<>();
    // add the base query
    if (!excludeSet.containsKey(rb.getQuery())) {
        qlist.add(rb.getQuery());
    }
    // add the filters
    if (rb.getFilters() != null) {
        for (Query q : rb.getFilters()) {
            if (!excludeSet.containsKey(q)) {
                qlist.add(q);
            }
        }
    }
    // get the new base docset for this facet
    DocSet base = searcher.getDocSet(qlist);
    if (rb.grouping() && rb.getGroupingSpec().isTruncateGroups()) {
        Grouping grouping = new Grouping(searcher, null, rb.getQueryCommand(), false, 0, false);
        grouping.setWithinGroupSort(rb.getGroupingSpec().getSortWithinGroup());
        if (rb.getGroupingSpec().getFields().length > 0) {
            grouping.addFieldCommand(rb.getGroupingSpec().getFields()[0], req);
        } else if (rb.getGroupingSpec().getFunctions().length > 0) {
            grouping.addFunctionCommand(rb.getGroupingSpec().getFunctions()[0], req);
        } else {
            return base;
        }
        AllGroupHeadsCollector allGroupHeadsCollector = grouping.getCommands().get(0).createAllGroupCollector();
        searcher.search(base.getTopFilter(), allGroupHeadsCollector);
        return new BitDocSet(allGroupHeadsCollector.retrieveGroupHeads(searcher.maxDoc()));
    } else {
        return base;
    }
}
Also used : Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) Grouping(org.apache.solr.search.Grouping) AllGroupHeadsCollector(org.apache.lucene.search.grouping.AllGroupHeadsCollector) BitDocSet(org.apache.solr.search.BitDocSet) QParser(org.apache.solr.search.QParser) Collection(java.util.Collection) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) HashDocSet(org.apache.solr.search.HashDocSet) DocSet(org.apache.solr.search.DocSet) SortedIntDocSet(org.apache.solr.search.SortedIntDocSet) BitDocSet(org.apache.solr.search.BitDocSet)

Aggregations

DocSet (org.apache.solr.search.DocSet)24 BitDocSet (org.apache.solr.search.BitDocSet)12 Query (org.apache.lucene.search.Query)9 HashDocSet (org.apache.solr.search.HashDocSet)6 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)6 SortedIntDocSet (org.apache.solr.search.SortedIntDocSet)6 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)5 FieldType (org.apache.solr.schema.FieldType)5 ArrayList (java.util.ArrayList)4 BytesRef (org.apache.lucene.util.BytesRef)4 NamedList (org.apache.solr.common.util.NamedList)4 SchemaField (org.apache.solr.schema.SchemaField)4 IdentityHashMap (java.util.IdentityHashMap)3 Map (java.util.Map)3 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)3 Term (org.apache.lucene.index.Term)3 SolrException (org.apache.solr.common.SolrException)3 SolrParams (org.apache.solr.common.params.SolrParams)3 QParser (org.apache.solr.search.QParser)3 SyntaxError (org.apache.solr.search.SyntaxError)3