예제 #1
0
		/// <summary> Constructor.</summary>
		/// <param name="innerSet">Underlying DocIdSet
		/// </param>
		protected FilteredDocIdSet(DocIdSet innerSet)
		{
			_innerSet = innerSet;
		}
        /// <summary>
        /// Calculates the result count.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="baseDocIdSet">The base doc id set.</param>
        /// <param name="facetGroup">The facet group.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="currency">The currency.</param>
        /// <returns></returns>
        private int CalculateResultCount(
            IndexReader reader, DocIdSet baseDocIdSet, FacetGroup facetGroup, ISearchFilter filter, string currency)
        {
            var count = 0;

            ISearchFilterValue[] values = null;
            var priceQuery = false;
            if (filter is s.AttributeFilter)
            {
                values = ((s.AttributeFilter)filter).Values;
            }
            else if (filter is s.RangeFilter)
            {
                values = ((s.RangeFilter)filter).Values;
            }
            else if (filter is s.PriceRangeFilter)
            {
                values = ((s.PriceRangeFilter)filter).Values;
                priceQuery = true;
            }

            if (values == null)
            {
                return 0;
            }

            foreach (var value in values)
            {
                Query q = null;
                if (priceQuery)
                {
                    q = LuceneQueryHelper.CreateQuery(
                        this.Results.SearchCriteria, filter.Key, value as s.RangeFilterValue);
                }
                else
                {
                    q = LuceneQueryHelper.CreateQuery(filter.Key, value);
                }

                if (q == null) continue;

                var queryFilter = new CachingWrapperFilter(new QueryWrapperFilter(q));
                var filterArray = queryFilter.GetDocIdSet(reader);
                var newCount = (int)this.CalculateFacetCount(baseDocIdSet, filterArray);
                if (newCount == 0) continue;

                var newFacet = new Facet(facetGroup, value.Id, this.GetDescription(value, this.Results.SearchCriteria.Locale), newCount);
                facetGroup.Facets.Add(newFacet);
                count += newCount;
            }

            return count;
        }
예제 #3
0
 public ValueSourceFilteredDocIdSet(ValueSourceFilter outerInstance, DocIdSet innerSet, FunctionValues values)
     : base(innerSet)
 {
     this.outerInstance = outerInstance;
     this.values        = values;
 }
예제 #4
0
        private void Count(ValueSource valueSource, IList <MatchingDocs> matchingDocs)
        {
            Int64Range[] ranges = (Int64Range[])this.m_ranges;

            Int64RangeCounter counter = new Int64RangeCounter(ranges);

            int missingCount = 0;

            foreach (MatchingDocs hits in matchingDocs)
            {
                FunctionValues fv = valueSource.GetValues(new Dictionary <string, object>(), hits.Context);

                m_totCount += hits.TotalHits;
                IBits bits;
                if (m_fastMatchFilter != null)
                {
                    DocIdSet dis = m_fastMatchFilter.GetDocIdSet(hits.Context, null);
                    if (dis == null)
                    {
                        // No documents match
                        continue;
                    }
                    bits = dis.Bits;
                    if (bits == null)
                    {
                        throw new System.ArgumentException("fastMatchFilter does not implement DocIdSet.bits");
                    }
                }
                else
                {
                    bits = null;
                }

                DocIdSetIterator docs = hits.Bits.GetIterator();
                int doc;
                while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
                {
                    if (bits != null && bits.Get(doc) == false)
                    {
                        doc++;
                        continue;
                    }
                    // Skip missing docs:
                    if (fv.Exists(doc))
                    {
                        counter.Add(fv.Int64Val(doc));
                    }
                    else
                    {
                        missingCount++;
                    }
                }
            }

            int x = counter.FillCounts(m_counts);

            missingCount += x;

            //System.out.println("totCount " + totCount + " missingCount " + counter.missingCount);
            m_totCount -= missingCount;
        }
예제 #5
0
            public override BulkScorer GetBulkScorer(AtomicReaderContext context, bool scoreDocsInOrder, IBits acceptDocs)
            {
                // TODO: it could be better if we take acceptDocs
                // into account instead of baseScorer?
                Scorer baseScorer = baseWeight.GetScorer(context, acceptDocs);

                DrillSidewaysScorer.DocsAndCost[] dims = new DrillSidewaysScorer.DocsAndCost[drillDowns.Length];
                int nullCount = 0;

                for (int dim = 0; dim < dims.Length; dim++)
                {
                    dims[dim] = new DrillSidewaysScorer.DocsAndCost();
                    dims[dim].sidewaysCollector = outerInstance.drillSidewaysCollectors[dim];
                    if (drillDowns[dim] is Filter)
                    {
                        // Pass null for acceptDocs because we already
                        // passed it to baseScorer and baseScorer is
                        // MUST'd here
                        DocIdSet dis = ((Filter)drillDowns[dim]).GetDocIdSet(context, null);

                        if (dis == null)
                        {
                            continue;
                        }

                        IBits bits = dis.Bits;

                        if (bits != null)
                        {
                            // TODO: this logic is too naive: the
                            // existence of bits() in DIS today means
                            // either "I'm a cheap FixedBitSet so apply me down
                            // low as you decode the postings" or "I'm so
                            // horribly expensive so apply me after all
                            // other Query/Filter clauses pass"

                            // Filter supports random access; use that to
                            // prevent .advance() on costly filters:
                            dims[dim].bits = bits;

                            // TODO: Filter needs to express its expected
                            // cost somehow, before pulling the iterator;
                            // we should use that here to set the order to
                            // check the filters:
                        }
                        else
                        {
                            DocIdSetIterator disi = dis.GetIterator();
                            if (disi == null)
                            {
                                nullCount++;
                                continue;
                            }
                            dims[dim].disi = disi;
                        }
                    }
                    else
                    {
                        DocIdSetIterator disi = ((Weight)drillDowns[dim]).GetScorer(context, null);
                        if (disi == null)
                        {
                            nullCount++;
                            continue;
                        }
                        dims[dim].disi = disi;
                    }
                }

                // If more than one dim has no matches, then there
                // are no hits nor drill-sideways counts.  Or, if we
                // have only one dim and that dim has no matches,
                // same thing.
                //if (nullCount > 1 || (nullCount == 1 && dims.length == 1)) {
                if (nullCount > 1)
                {
                    return(null);
                }

                // Sort drill-downs by most restrictive first:
                Array.Sort(dims);

                if (baseScorer == null)
                {
                    return(null);
                }

                return(new DrillSidewaysScorer(context, baseScorer, outerInstance.drillDownCollector, dims, outerInstance.scoreSubDocsAtOnce));
            }
예제 #6
0
        private void DoChain(OpenBitSetDISI result, Logic logic, DocIdSet dis)
        {
            if (dis is OpenBitSet)
            {
                // optimized case for OpenBitSets
                switch (logic)
                {
                case Logic.OR:
                    result.Or((OpenBitSet)dis);
                    break;

                case Logic.AND:
                    result.And((OpenBitSet)dis);
                    break;

                case Logic.ANDNOT:
                    result.AndNot((OpenBitSet)dis);
                    break;

                case Logic.XOR:
                    result.Xor((OpenBitSet)dis);
                    break;

                default:
                    DoChain(result, DEFAULT, dis);
                    break;
                }
            }
            else
            {
                DocIdSetIterator disi;
                if (dis == null)
                {
                    disi = DocIdSet.EMPTY_DOCIDSET.Iterator();
                }
                else
                {
                    disi = dis.Iterator();
                    if (disi == null)
                    {
                        disi = DocIdSet.EMPTY_DOCIDSET.Iterator();
                    }
                }

                switch (logic)
                {
                case Logic.OR:
                    result.InPlaceOr(disi);
                    break;

                case Logic.AND:
                    result.InPlaceAnd(disi);
                    break;

                case Logic.ANDNOT:
                    result.InPlaceNot(disi);
                    break;

                case Logic.XOR:
                    result.InPlaceXor(disi);
                    break;

                default:
                    DoChain(result, DEFAULT, dis);
                    break;
                }
            }
        }
예제 #7
0
 internal NotDocIdSetIterator(DocIdSet innerSet, Func <int> getMax)
 {
     this.innerSet = innerSet;
     this.getMax   = getMax;
     Initialize();
 }
예제 #8
0
        public virtual void Search(Weight weight, Filter filter, ICollector collector, int start, IBoboMapFunctionWrapper mapReduceWrapper)
        {
            FacetValidator validator = CreateFacetValidator();
            int            target    = 0;

            IndexReader        reader             = this.IndexReader;
            IndexReaderContext indexReaderContext = reader.Context;

            if (filter == null)
            {
                for (int i = 0; i < m_subReaders.Length; i++)
                {
                    AtomicReaderContext atomicContext = indexReaderContext.Children == null
                        ? (AtomicReaderContext)indexReaderContext
                        : (AtomicReaderContext)(indexReaderContext.Children.Get(i));
                    int docStart = start;

                    // NOTE: This code calls an internal constructor. Apparently, this was in the same namespace as Lucene,
                    // but was added to this project, which presumably allows you to call internal constructors in Java.
                    // In .NET, we can just use Activator.CreateInstance. Not great, but this code will be removed
                    // when applying commit https://github.com/senseidb/bobo/commit/924c8579d90dbb5d56103976d39b47daa2242ef3
                    // which includes several major changes after the 4.0.2 release.

                    // atomicContext = AtomicReaderContextUtil.UpdateDocBase(atomicContext, docStart);
                    object[] args = new object[] { (CompositeReaderContext)null, atomicContext.AtomicReader, 0, 0, 0, docStart };
                    Type[]   constructorSignature = { typeof(CompositeReaderContext), typeof(AtomicReader), typeof(int), typeof(int), typeof(int), typeof(int) };
                    var      constr = typeof(AtomicReaderContext).GetTypeInfo().DeclaredConstructors
                                      .Single(constructor =>
                                              constructor.GetParameters()
                                              .Select(parameter => parameter.ParameterType)
                                              .SequenceEqual(constructorSignature));
                    atomicContext = (AtomicReaderContext)constr.Invoke(args);

                    if (reader is BoboMultiReader)
                    {
                        docStart = start + ((BoboMultiReader)reader).SubReaderBase(i);
                    }
                    collector.SetNextReader(atomicContext);
                    validator.SetNextReader(m_subReaders[i], docStart);

                    // NOTE: The Weight.Scorer method lost the scoreDocsInOrder and topScorer parameters between
                    // Lucene 4.3.0 and 4.8.0. They are not used by BoboBrowse anyway, so the code here diverges
                    // from the original Java source to remove these two parameters.

                    // Scorer scorer = weight.Scorer(atomicContext, true, true, _subReaders[i].LiveDocs);
                    Scorer scorer = weight.GetScorer(atomicContext, m_subReaders[i].LiveDocs);
                    if (scorer != null)
                    {
                        collector.SetScorer(scorer);
                        target = scorer.NextDoc();
                        while (target != DocIdSetIterator.NO_MORE_DOCS)
                        {
                            if (validator.Validate(target))
                            {
                                collector.Collect(target);
                                target = scorer.NextDoc();
                            }
                            else
                            {
                                target = validator.m_nextTarget;
                                target = scorer.Advance(target);
                            }
                        }
                    }
                    if (mapReduceWrapper != null)
                    {
                        mapReduceWrapper.MapFullIndexReader(m_subReaders[i], validator.GetCountCollectors());
                    }
                }
                return;
            }

            for (int i = 0; i < m_subReaders.Length; i++)
            {
                AtomicReaderContext atomicContext = indexReaderContext.Children == null
                        ? (AtomicReaderContext)indexReaderContext
                        : (AtomicReaderContext)(indexReaderContext.Children.Get(i));

                DocIdSet filterDocIdSet = filter.GetDocIdSet(atomicContext, m_subReaders[i].LiveDocs);
                if (filterDocIdSet == null)
                {
                    return;                          //shall we use return or continue here ??
                }
                int docStart = start;
                if (reader is BoboMultiReader)
                {
                    docStart = start + ((BoboMultiReader)reader).SubReaderBase(i);
                }
                collector.SetNextReader(atomicContext);
                validator.SetNextReader(m_subReaders[i], docStart);

                // NOTE: The Weight.Scorer method lost the scoreDocsInOrder and topScorer parameters between
                // Lucene 4.3.0 and 4.8.0. They are not used by BoboBrowse anyway, so the code here diverges
                // from the original Java source to remove these two parameters.

                // Scorer scorer = weight.Scorer(atomicContext, true, false, _subReaders[i].LiveDocs);
                Scorer scorer = weight.GetScorer(atomicContext, m_subReaders[i].LiveDocs);
                if (scorer != null)
                {
                    collector.SetScorer(scorer);
                    DocIdSetIterator filterDocIdIterator = filterDocIdSet.GetIterator(); // CHECKME: use ConjunctionScorer here?

                    if (filterDocIdIterator == null)
                    {
                        continue;
                    }

                    int doc = -1;
                    target = filterDocIdIterator.NextDoc();
                    if (mapReduceWrapper == null)
                    {
                        while (target < DocIdSetIterator.NO_MORE_DOCS)
                        {
                            if (doc < target)
                            {
                                doc = scorer.Advance(target);
                            }

                            if (doc == target) // permitted by filter
                            {
                                if (validator.Validate(doc))
                                {
                                    collector.Collect(doc);

                                    target = filterDocIdIterator.NextDoc();
                                }
                                else
                                {
                                    // skip to the next possible docid
                                    target = filterDocIdIterator.Advance(validator.m_nextTarget);
                                }
                            }
                            else // doc > target
                            {
                                if (doc == DocIdSetIterator.NO_MORE_DOCS)
                                {
                                    break;
                                }
                                target = filterDocIdIterator.Advance(doc);
                            }
                        }
                    }
                    else
                    {
                        //MapReduce wrapper is not null
                        while (target < DocIdSetIterator.NO_MORE_DOCS)
                        {
                            if (doc < target)
                            {
                                doc = scorer.Advance(target);
                            }

                            if (doc == target) // permitted by filter
                            {
                                if (validator.Validate(doc))
                                {
                                    mapReduceWrapper.MapSingleDocument(doc, m_subReaders[i]);
                                    collector.Collect(doc);

                                    target = filterDocIdIterator.NextDoc();
                                }
                                else
                                {
                                    // skip to the next possible docid
                                    target = filterDocIdIterator.Advance(validator.m_nextTarget);
                                }
                            }
                            else // doc > target
                            {
                                if (doc == DocIdSetIterator.NO_MORE_DOCS)
                                {
                                    break;
                                }
                                target = filterDocIdIterator.Advance(doc);
                            }
                        }
                        mapReduceWrapper.FinalizeSegment(m_subReaders[i], validator.GetCountCollectors());
                    }
                }
            }
        }
예제 #9
0
        private void Count(ValueSource valueSource, IEnumerable <MatchingDocs> matchingDocs)
        {
            DoubleRange[] ranges = (DoubleRange[])this.ranges;

            LongRange[] longRanges = new LongRange[ranges.Length];
            for (int i = 0; i < ranges.Length; i++)
            {
                DoubleRange range = ranges[i];
                longRanges[i] = new LongRange(range.Label, NumericUtils.DoubleToSortableLong(range.minIncl), true, NumericUtils.DoubleToSortableLong(range.maxIncl), true);
            }

            LongRangeCounter counter = new LongRangeCounter(longRanges);

            int missingCount = 0;

            foreach (MatchingDocs hits in matchingDocs)
            {
                FunctionValues fv = valueSource.GetValues(new Dictionary <string, object>(), hits.Context);

                totCount += hits.TotalHits;
                Bits bits;
                if (fastMatchFilter != null)
                {
                    DocIdSet dis = fastMatchFilter.GetDocIdSet(hits.Context, null);
                    if (dis == null)
                    {
                        // No documents match
                        continue;
                    }
                    bits = dis.GetBits();
                    if (bits == null)
                    {
                        throw new System.ArgumentException("fastMatchFilter does not implement DocIdSet.bits");
                    }
                }
                else
                {
                    bits = null;
                }

                DocIdSetIterator docs = hits.Bits.GetIterator();

                int doc;
                while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
                {
                    if (bits != null && bits.Get(doc) == false)
                    {
                        doc++;
                        continue;
                    }
                    // Skip missing docs:
                    if (fv.Exists(doc))
                    {
                        counter.Add(NumericUtils.DoubleToSortableLong(fv.DoubleVal(doc)));
                    }
                    else
                    {
                        missingCount++;
                    }
                }
            }

            missingCount += counter.FillCounts(counts);
            totCount     -= missingCount;
        }
예제 #10
0
 public NotDocIdSet(DocIdSet docSet, int maxVal)
 {
     m_innerSet = docSet;
     m_max      = maxVal;
 }
 public ValueSourceFilteredDocIdSet(DocIdSet innerSet, DocValues values, ValueSourceFilter caller)
     : base(innerSet)
 {
     this.enclosingFilter = caller;
     this.values          = values;
 }
예제 #12
0
 public static string ToString(DocIdSet docIdSet)
 {
     return(docIdSet.AsString());
 }
예제 #13
0
 /// <summary> Constructor.</summary>
 /// <param name="innerSet">Underlying DocIdSet
 /// </param>
 public FilteredDocIdSet(DocIdSet innerSet)
 {
     _innerSet = innerSet;
 }
 /// <summary>
 ///     Calculates number of facets found in the filter doc set.
 /// </summary>
 /// <param name="baseBitSet">The base bit set.</param>
 /// <param name="filterDocSet">The filter bit set.</param>
 /// <returns></returns>
 private long CalculateFacetCount(DocIdSet baseBitSet, DocIdSet filterDocSet)
 {
     var baseDISI = new OpenBitSetDISI(baseBitSet.Iterator(), 25000);
     var filterIterator = filterDocSet.Iterator();
     baseDISI.InPlaceAnd(filterIterator);
     var total = baseDISI.Cardinality();
     return total;
 }
예제 #15
0
        /// <exception cref="System.IO.IOException"/>
        private void DoChain(FixedBitSet result, int logic, DocIdSet dis)
        {
            if (dis is FixedBitSet)
            {
                // optimized case for FixedBitSets
                switch (logic)
                {
                case OR:
                    result.Or((FixedBitSet)dis);
                    break;

                case AND:
                    result.And((FixedBitSet)dis);
                    break;

                case ANDNOT:
                    result.AndNot((FixedBitSet)dis);
                    break;

                case XOR:
                    result.Xor((FixedBitSet)dis);
                    break;

                default:
                    DoChain(result, DEFAULT, dis);
                    break;
                }
            }
            else
            {
                DocIdSetIterator disi;
                if (dis == null)
                {
                    disi = DocIdSetIterator.GetEmpty();
                }
                else
                {
                    disi = dis.GetIterator() ?? DocIdSetIterator.GetEmpty();
                }

                switch (logic)
                {
                case OR:
                    result.Or(disi);
                    break;

                case AND:
                    result.And(disi);
                    break;

                case ANDNOT:
                    result.AndNot(disi);
                    break;

                case XOR:
                    result.Xor(disi);
                    break;

                default:
                    DoChain(result, DEFAULT, dis);
                    break;
                }
            }
        }
        /// <summary>
        /// Calculates the result count.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="baseDocIdSet">The base doc id set.</param>
        /// <param name="facetGroup">The facet group.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        private int CalculateResultCount(IndexReader reader, DocIdSet baseDocIdSet, FacetGroup facetGroup, ISearchFilter filter, ISearchCriteria criteria)
        {
            var count = 0;

            var values = LuceneQueryHelper.GetFilterValues(filter);

            if (values == null)
            {
                return 0;
            }

            BooleanFilter ffilter = null;
            foreach (var f in criteria.CurrentFilters)
            {
                if (!f.Key.Equals(facetGroup.FieldName))
                {
                    if (ffilter == null) ffilter = new BooleanFilter();

                    var q = LuceneQueryHelper.CreateQuery(criteria, f, Occur.SHOULD);
                    ffilter.Add(new FilterClause(q, Occur.MUST));
                }
            }

            foreach (var value in values)
            {
                var queryFilter = new BooleanFilter();
                    
                var valueFilter = LuceneQueryHelper.CreateQueryForValue(Results.SearchCriteria, filter, value);

                if (valueFilter == null) continue;

                queryFilter.Add(new FilterClause(valueFilter, Occur.MUST));
                if(ffilter!=null)
                    queryFilter.Add(new FilterClause(ffilter, Occur.MUST));

                var filterArray = queryFilter.GetDocIdSet(reader);
                var newCount = (int)CalculateFacetCount(baseDocIdSet, filterArray);
                if (newCount == 0) continue;

                var newFacet = new Facet(facetGroup, value.Id, GetDescription(value, Results.SearchCriteria.Locale), newCount);
                facetGroup.Facets.Add(newFacet);
                count += newCount;
            }

            return count;
        }
예제 #17
0
 private static bool IsEmpty(DocIdSet set)
 {
     return(set is null);
 }