Set() public method

public Set ( int index ) : void
index int
return void
Esempio n. 1
0
 internal RandomBits(int maxDoc, double pctLive, Random random)
 {
     bits = new FixedBitSet(maxDoc);
     for (int i = 0; i < maxDoc; i++)
     {
         if (random.NextDouble() <= pctLive)
         {
             bits.Set(i);
         }
     }
 }
 protected virtual void CollectDocs(FixedBitSet bitSet)
 {
     //WARN: keep this specialization in sync
     Debug.Assert(termsEnum != null);
     docsEnum = termsEnum.Docs(acceptDocs, docsEnum, DocsEnum.FLAG_NONE);
     int docid;
     while ((docid = docsEnum.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
     {
         bitSet.Set(docid);
     }
 }
Esempio n. 3
0
 public override DocIdSet GetDocIdSet(AtomicReaderContext context, Bits acceptDocs)
 {
     AtomicReader reader = context.AtomicReader;
     FixedBitSet result = null; // lazy init if needed - no need to create a big bitset ahead of time
     Fields fields = reader.Fields;
     BytesRef spare = new BytesRef(this.termsBytes);
     if (fields == null)
     {
         return result;
     }
     Terms terms = null;
     TermsEnum termsEnum = null;
     DocsEnum docs = null;
     foreach (TermsAndField termsAndField in this.termsAndFields)
     {
         if ((terms = fields.Terms(termsAndField.field)) != null)
         {
             termsEnum = terms.Iterator(termsEnum); // this won't return null
             for (int i = termsAndField.start; i < termsAndField.end; i++)
             {
                 spare.Offset = offsets[i];
                 spare.Length = offsets[i + 1] - offsets[i];
                 if (termsEnum.SeekExact(spare))
                 {
                     docs = termsEnum.Docs(acceptDocs, docs, DocsEnum.FLAG_NONE); // no freq since we don't need them
                     if (result == null)
                     {
                         if (docs.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
                         {
                             result = new FixedBitSet(reader.MaxDoc);
                             // lazy init but don't do it in the hot loop since we could read many docs
                             result.Set(docs.DocID());
                         }
                     }
                     while (docs.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
                     {
                         result.Set(docs.DocID());
                     }
                 }
             }
         }
     }
     return result;
 }
Esempio n. 4
0
        private FixedBitSet CorrectBits(AtomicReader reader, Bits acceptDocs)
        {
            FixedBitSet bits = new FixedBitSet(reader.MaxDoc); //assume all are INvalid
            Terms terms = reader.Fields.Terms(fieldName);

            if (terms == null)
            {
                return bits;
            }

            TermsEnum termsEnum = terms.Iterator(null);
            DocsEnum docs = null;
            while (true)
            {
                BytesRef currTerm = termsEnum.Next();
                if (currTerm == null)
                {
                    break;
                }
                else
                {
                    docs = termsEnum.Docs(acceptDocs, docs, DocsEnum.FLAG_NONE);
                    int doc = docs.NextDoc();
                    if (doc != DocIdSetIterator.NO_MORE_DOCS)
                    {
                        if (keepMode == KeepMode.KM_USE_FIRST_OCCURRENCE)
                        {
                            bits.Set(doc);
                        }
                        else
                        {
                            int lastDoc = doc;
                            while (true)
                            {
                                lastDoc = doc;
                                doc = docs.NextDoc();
                                if (doc == DocIdSetIterator.NO_MORE_DOCS)
                                {
                                    break;
                                }
                            }
                            bits.Set(lastDoc);
                        }
                    }
                }
            }
            return bits;
        }
Esempio n. 5
0
        private FixedBitSet FastBits(AtomicReader reader, Bits acceptDocs)
        {
            FixedBitSet bits = new FixedBitSet(reader.MaxDoc);
            bits.Set(0, reader.MaxDoc); //assume all are valid
            Terms terms = reader.Fields.Terms(fieldName);

            if (terms == null)
            {
                return bits;
            }

            TermsEnum termsEnum = terms.Iterator(null);
            DocsEnum docs = null;
            while (true)
            {
                BytesRef currTerm = termsEnum.Next();
                if (currTerm == null)
                {
                    break;
                }
                else
                {
                    if (termsEnum.DocFreq() > 1)
                    {
                        // unset potential duplicates
                        docs = termsEnum.Docs(acceptDocs, docs, DocsEnum.FLAG_NONE);
                        int doc = docs.NextDoc();
                        if (doc != DocIdSetIterator.NO_MORE_DOCS)
                        {
                            if (keepMode == KeepMode.KM_USE_FIRST_OCCURRENCE)
                            {
                                doc = docs.NextDoc();
                            }
                        }

                        int lastDoc = -1;
                        while (true)
                        {
                            lastDoc = doc;
                            bits.Clear(lastDoc);
                            doc = docs.NextDoc();
                            if (doc == DocIdSetIterator.NO_MORE_DOCS)
                            {
                                break;
                            }
                        }

                        if (keepMode == KeepMode.KM_USE_LAST_OCCURRENCE)
                        {
                            // restore the last bit
                            bits.Set(lastDoc);
                        }
                    }
                }
            }

            return bits;
        }
 protected virtual void FillDocsAndScores(FixedBitSet matchingDocs, Bits acceptDocs,
     TermsEnum termsEnum)
 {
     BytesRef spare = new BytesRef();
     DocsEnum docsEnum = null;
     for (int i = 0; i < outerInstance._terms.Size(); i++)
     {
         if (termsEnum.SeekExact(outerInstance._terms.Get(outerInstance._ords[i], spare)))
         {
             docsEnum = termsEnum.Docs(acceptDocs, docsEnum, FLAG_NONE);
             float score = outerInstance._scores[outerInstance._ords[i]];
             for (int doc = docsEnum.NextDoc();
                 doc != NO_MORE_DOCS;
                 doc = docsEnum.NextDoc())
             {
                 matchingDocs.Set(doc);
                 // In the case the same doc is also related to a another doc, a score might be overwritten. I think this
                 // can only happen in a many-to-many relation
                 scores[doc] = score;
             }
         }
     }
 }
 protected override void FillDocsAndScores(FixedBitSet matchingDocs, Bits acceptDocs,
     TermsEnum termsEnum)
 {
     BytesRef spare = new BytesRef();
     DocsEnum docsEnum = null;
     for (int i = 0; i < outerInstance._terms.Size(); i++)
     {
         if (termsEnum.SeekExact(outerInstance._terms.Get(outerInstance._ords[i], spare)))
         {
             docsEnum = termsEnum.Docs(acceptDocs, docsEnum, FLAG_NONE);
             float score = outerInstance._scores[outerInstance._ords[i]];
             for (int doc = docsEnum.NextDoc();
                 doc != NO_MORE_DOCS;
                 doc = docsEnum.NextDoc())
             {
                 // I prefer this:
                 /*if (scores[doc] < score) {
                   scores[doc] = score;
                   matchingDocs.set(doc);
                 }*/
                 // But this behaves the same as MVInnerScorer and only then the tests will pass:
                 if (!matchingDocs.Get(doc))
                 {
                     scores[doc] = score;
                     matchingDocs.Set(doc);
                 }
             }
         }
     }
 }
 internal Bits RandomLiveDocs(int maxDoc)
 {
     if (Rarely())
     {
         if (Random().nextBoolean())
         {
             return null;
         }
         else
         {
             return new Bits_MatchNoBits(maxDoc);
         }
     }
     FixedBitSet bits = new FixedBitSet(maxDoc);
     int bitsSet = TestUtil.NextInt(Random(), 1, maxDoc - 1);
     for (int i = 0; i < bitsSet; ++i)
     {
         while (true)
         {
             int index = Random().nextInt(maxDoc);
             if (!bits.Get(index))
             {
                 bits.Set(index);
                 break;
             }
         }
     }
     return bits;
 }