Exemplo n.º 1
0
        /// <summary>
        /// <seealso cref="Filter.GetDocIdSet"/>.
        /// </summary>
        public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs)
        {
            int[] index = new int[1]; // use array as reference to modifiable int;
            index[0] = 0;             // an object attribute would not be thread safe.
            if (logic != -1)
            {
                return(BitsFilteredDocIdSet.Wrap(GetDocIdSet(context, logic, index), acceptDocs));
            }
            else if (logicArray != null)
            {
                return(BitsFilteredDocIdSet.Wrap(GetDocIdSet(context, logicArray, index), acceptDocs));
            }

            return(BitsFilteredDocIdSet.Wrap(GetDocIdSet(context, DEFAULT, index), acceptDocs));
        }
Exemplo n.º 2
0
        /// <exception cref="System.IO.IOException"></exception>
        public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs
                                             )
        {
            IBits docsWithField;

            if (field == null)
            {
                docsWithField = null;
            }
            else
            {
                //all docs
                //NOTE By using the FieldCache we re-use a cache
                // which is nice but loading it in this way might be slower than say using an
                // intersects filter against the world bounds. So do we add a method to the
                // strategy, perhaps?  But the strategy can't cache it.
                docsWithField = FieldCache.DEFAULT.GetDocsWithField((context.AtomicReader), field);
                int maxDoc = context.AtomicReader.MaxDoc;
                if (docsWithField.Length != maxDoc)
                {
                    throw new InvalidOperationException("Bits length should be maxDoc (" + maxDoc + ") but wasn't: "
                                                        + docsWithField);
                }
                if (docsWithField is Bits.MatchNoBits)
                {
                    return(null);
                }
                else
                {
                    //match nothing
                    if (docsWithField is Bits.MatchAllBits)
                    {
                        docsWithField = null;
                    }
                }
            }
            //all docs
            //not so much a chain but a way to conveniently invert the Filter
            DocIdSet docIdSet = new ChainedFilter(new[] { intersectsFilter }, ChainedFilter.ANDNOT).GetDocIdSet(context,
                                                                                                                acceptDocs);

            return(BitsFilteredDocIdSet.Wrap(docIdSet, docsWithField));
        }
Exemplo n.º 3
0
        /// <exception cref="IOException"></exception>
        public override DocIdSet?GetDocIdSet(AtomicReaderContext context, IBits?acceptDocs)
        {
            // LUCENENET specific - added guard clause
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            IBits?docsWithField;

            if (field is null)
            {
                docsWithField = null;
            }
            else
            {
                //NOTE By using the FieldCache we re-use a cache
                // which is nice but loading it in this way might be slower than say using an
                // intersects filter against the world bounds. So do we add a method to the
                // strategy, perhaps?  But the strategy can't cache it.
                docsWithField = FieldCache.DEFAULT.GetDocsWithField(context.AtomicReader, field);

                int maxDoc = context.AtomicReader.MaxDoc;
                if (docsWithField.Length != maxDoc)
                {
                    throw IllegalStateException.Create("Bits length should be maxDoc (" + maxDoc + ") but wasn't: " + docsWithField);
                }

                if (docsWithField is Bits.MatchNoBits)
                {
                    return(null);//match nothing
                }
                else if (docsWithField is Bits.MatchAllBits)
                {
                    docsWithField = null;//all docs
                }
            }

            //not so much a chain but a way to conveniently invert the Filter
            DocIdSet docIdSet = new ChainedFilter(new Filter[] { intersectsFilter }, ChainedFilter.ANDNOT).GetDocIdSet(context, acceptDocs);

            return(BitsFilteredDocIdSet.Wrap(docIdSet, docsWithField));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the a <see cref="DocIdSetIterator"/> representing the Boolean composition
        /// of the filters that have been added.
        /// </summary>
        public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs)
        {
            FixedBitSet  res    = null;
            AtomicReader reader = context.AtomicReader;

            bool hasShouldClauses = false;

            foreach (FilterClause fc in clauses)
            {
                if (fc.Occur == Occur.SHOULD)
                {
                    hasShouldClauses = true;
                    DocIdSetIterator disi = GetDISI(fc.Filter, context);
                    if (disi == null)
                    {
                        continue;
                    }
                    if (res == null)
                    {
                        res = new FixedBitSet(reader.MaxDoc);
                    }
                    res.Or(disi);
                }
            }
            if (hasShouldClauses && res == null)
            {
                return(null);
            }

            foreach (FilterClause fc in clauses)
            {
                if (fc.Occur == Occur.MUST_NOT)
                {
                    if (res == null)
                    {
                        Debug.Assert(!hasShouldClauses);
                        res = new FixedBitSet(reader.MaxDoc);
                        res.Set(0, reader.MaxDoc); // NOTE: may set bits on deleted docs
                    }

                    DocIdSetIterator disi = GetDISI(fc.Filter, context);
                    if (disi != null)
                    {
                        res.AndNot(disi);
                    }
                }
            }

            foreach (FilterClause fc in clauses)
            {
                if (fc.Occur == Occur.MUST)
                {
                    DocIdSetIterator disi = GetDISI(fc.Filter, context);
                    if (disi == null)
                    {
                        return(null); // no documents can match
                    }
                    if (res == null)
                    {
                        res = new FixedBitSet(reader.MaxDoc);
                        res.Or(disi);
                    }
                    else
                    {
                        res.And(disi);
                    }
                }
            }

            return(BitsFilteredDocIdSet.Wrap(res, acceptDocs));
        }