Search in sources :

Example 6 with BitDocSet

use of org.apache.solr.search.BitDocSet in project SearchServices by Alfresco.

the class SolrOwnerScorer method createOwnerScorer.

public static SolrOwnerScorer createOwnerScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authority) throws IOException {
    if (AuthorityType.getAuthorityType(authority) == AuthorityType.USER) {
        DocSet ownedDocs = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_OWNERLOOKUP_CACHE, authority);
        if (ownedDocs == null) {
            // Cache miss: query the index for docs where the owner matches the authority.
            ownedDocs = searcher.getDocSet(new TermQuery(new Term(QueryConstants.FIELD_OWNER, authority)));
            searcher.cacheInsert(CacheConstants.ALFRESCO_OWNERLOOKUP_CACHE, authority, ownedDocs);
        }
        return new SolrOwnerScorer(weight, ownedDocs, context, searcher);
    }
    // Return an empty doc set, as the authority isn't a user.
    return new SolrOwnerScorer(weight, new BitDocSet(new FixedBitSet(0)), context, searcher);
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) BitDocSet(org.apache.solr.search.BitDocSet) FixedBitSet(org.apache.lucene.util.FixedBitSet) Term(org.apache.lucene.index.Term) BitDocSet(org.apache.solr.search.BitDocSet) DocSet(org.apache.solr.search.DocSet)

Example 7 with BitDocSet

use of org.apache.solr.search.BitDocSet 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)

Example 8 with BitDocSet

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

the class SolrRangeQuery method createDocSet.

private DocSet createDocSet(SolrIndexSearcher searcher, long cost) throws IOException {
    int maxDoc = searcher.maxDoc();
    BitDocSet liveDocs = searcher.getLiveDocs();
    FixedBitSet liveBits = liveDocs.size() == maxDoc ? null : liveDocs.getBits();
    DocSetBuilder builder = new DocSetBuilder(maxDoc, cost);
    List<LeafReaderContext> leaves = searcher.getTopReaderContext().leaves();
    int maxTermsPerSegment = 0;
    for (LeafReaderContext ctx : leaves) {
        TermsEnum te = getTermsEnum(ctx);
        int termsVisited = builder.add(te, ctx.docBase);
        maxTermsPerSegment = Math.max(maxTermsPerSegment, termsVisited);
    }
    DocSet set = maxTermsPerSegment <= 1 ? builder.buildUniqueInOrder(liveBits) : builder.build(liveBits);
    return DocSetUtil.getDocSet(set, searcher);
}
Also used : BitDocSet(org.apache.solr.search.BitDocSet) FixedBitSet(org.apache.lucene.util.FixedBitSet) DocSetBuilder(org.apache.solr.search.DocSetBuilder) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) BitDocSet(org.apache.solr.search.BitDocSet) DocSet(org.apache.solr.search.DocSet) TermsEnum(org.apache.lucene.index.TermsEnum)

Example 9 with BitDocSet

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

the class CommandHandler method computeGroupedDocSet.

private DocSet computeGroupedDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException {
    Command firstCommand = commands.get(0);
    String field = firstCommand.getKey();
    SchemaField sf = searcher.getSchema().getField(field);
    FieldType fieldType = sf.getType();
    final AllGroupHeadsCollector allGroupHeadsCollector;
    if (fieldType.getNumberType() != null) {
        ValueSource vs = fieldType.getValueSource(sf, null);
        allGroupHeadsCollector = AllGroupHeadsCollector.newCollector(new ValueSourceGroupSelector(vs, new HashMap<>()), firstCommand.getWithinGroupSort());
    } else {
        allGroupHeadsCollector = AllGroupHeadsCollector.newCollector(new TermGroupSelector(firstCommand.getKey()), firstCommand.getWithinGroupSort());
    }
    if (collectors.isEmpty()) {
        searchWithTimeLimiter(query, filter, allGroupHeadsCollector);
    } else {
        collectors.add(allGroupHeadsCollector);
        searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[collectors.size()])));
    }
    return new BitDocSet(allGroupHeadsCollector.retrieveGroupHeads(searcher.maxDoc()));
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) BitDocSet(org.apache.solr.search.BitDocSet) QueryCommand(org.apache.solr.search.QueryCommand) ValueSource(org.apache.lucene.queries.function.ValueSource) ValueSourceGroupSelector(org.apache.lucene.search.grouping.ValueSourceGroupSelector) TermGroupSelector(org.apache.lucene.search.grouping.TermGroupSelector) AllGroupHeadsCollector(org.apache.lucene.search.grouping.AllGroupHeadsCollector) FieldType(org.apache.solr.schema.FieldType)

Example 10 with BitDocSet

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

the class BlockJoinDocSetFacetComponent method process.

@Override
public void process(ResponseBuilder rb) throws IOException {
    final BlockJoinParentQParser.AllParentsAware bjq = (BlockJoinParentQParser.AllParentsAware) rb.req.getContext().get(bjqKey);
    if (bjq != null) {
        final DocSet parentResult = rb.getResults().docSet;
        final BitDocSet allParentsBitsDocSet = rb.req.getSearcher().getDocSetBits(bjq.getParentQuery());
        final DocSet allChildren = BlockJoin.toChildren(parentResult, allParentsBitsDocSet, rb.req.getSearcher().getDocSetBits(new MatchAllDocsQuery()), QueryContext.newContext(rb.req.getSearcher()));
        final DocSet childQueryDocSet = rb.req.getSearcher().getDocSet(bjq.getChildQuery());
        final DocSet selectedChildren = allChildren.intersection(childQueryDocSet);
        // don't include parent into facet counts
        //childResult = childResult.union(parentResult);// just to mimic the current logic
        final List<LeafReaderContext> leaves = rb.req.getSearcher().getIndexReader().leaves();
        Filter filter = selectedChildren.getTopFilter();
        final BlockJoinFacetAccsHolder facetCounter = new BlockJoinFacetAccsHolder(rb.req);
        for (int subIdx = 0; subIdx < leaves.size(); subIdx++) {
            LeafReaderContext subCtx = leaves.get(subIdx);
            // solr docsets already exclude any deleted docs
            DocIdSet dis = filter.getDocIdSet(subCtx, null);
            AggregatableDocIter iter = new SegmentChildren(subCtx, dis, allParentsBitsDocSet);
            if (iter.hasNext()) {
                facetCounter.doSetNextReader(subCtx);
                facetCounter.countFacets(iter);
            }
        }
        facetCounter.finish();
        rb.req.getContext().put(COLLECTOR_CONTEXT_PARAM, facetCounter);
        super.process(rb);
    }
}
Also used : AggregatableDocIter(org.apache.solr.search.join.BlockJoinFieldFacetAccumulator.AggregatableDocIter) DocIdSet(org.apache.lucene.search.DocIdSet) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) BitDocSet(org.apache.solr.search.BitDocSet) Filter(org.apache.solr.search.Filter) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) BitDocSet(org.apache.solr.search.BitDocSet) DocSet(org.apache.solr.search.DocSet)

Aggregations

BitDocSet (org.apache.solr.search.BitDocSet)13 DocSet (org.apache.solr.search.DocSet)12 FixedBitSet (org.apache.lucene.util.FixedBitSet)9 Term (org.apache.lucene.index.Term)7 TermQuery (org.apache.lucene.search.TermQuery)7 DocIterator (org.apache.solr.search.DocIterator)7 BooleanQuery (org.apache.lucene.search.BooleanQuery)6 Query (org.apache.lucene.search.Query)6 SchemaField (org.apache.solr.schema.SchemaField)5 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)4 HashSet (java.util.HashSet)2 NumericDocValues (org.apache.lucene.index.NumericDocValues)2 AllGroupHeadsCollector (org.apache.lucene.search.grouping.AllGroupHeadsCollector)2 QParser (org.apache.solr.search.QParser)2 WrappedQuery (org.apache.solr.search.WrappedQuery)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1