Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCollectAllHitsPerSegment() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldCollectAllHitsPerSegment()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector();
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Collect(1);
            collector.Collect(3);
            collector.Collect(5);
            collector.Collect(9);

            // then
            assertEquals(4, collector.TotalHits);
            IList <DocValuesCollector.MatchingDocs> allMatchingDocs = collector.GetMatchingDocs();

            assertEquals(1, allMatchingDocs.Count);
            DocValuesCollector.MatchingDocs matchingDocs = allMatchingDocs[0];
            assertSame(readerStub.Context, matchingDocs.Context);
            assertEquals(4, matchingDocs.TotalHits);
            DocIdSetIterator idIterator = matchingDocs.DocIdSet.GetEnumerator();

            assertEquals(1, idIterator.nextDoc());
            assertEquals(3, idIterator.nextDoc());
            assertEquals(5, idIterator.nextDoc());
            assertEquals(9, idIterator.nextDoc());
            assertEquals(DocIdSetIterator.NO_MORE_DOCS, idIterator.nextDoc());
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public DocumentFilteredAtomicIndexReader(AtomicReaderContext context, org.apache.lucene.search.Filter preserveFilter, boolean negateFilter) throws java.io.IOException
            public DocumentFilteredAtomicIndexReader(AtomicReaderContext context, Filter preserveFilter, bool negateFilter) : base(context.reader())
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int maxDoc = in.maxDoc();
                int maxDoc = @in.maxDoc();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.lucene.util.FixedBitSet bits = new org.apache.lucene.util.FixedBitSet(maxDoc);
                FixedBitSet bits = new FixedBitSet(maxDoc);
                // ignore livedocs here, as we filter them later:
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.lucene.search.DocIdSet docs = preserveFilter.getDocIdSet(context, null);
                DocIdSet docs = preserveFilter.getDocIdSet(context, null);

                if (docs != null)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.lucene.search.DocIdSetIterator it = docs.iterator();
                    DocIdSetIterator it = docs.GetEnumerator();
                    if (it != null)
                    {
                        bits.or(it);
                    }
                }
                if (negateFilter)
                {
                    bits.flip(0, maxDoc);
                }

                if (@in.hasDeletions())
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.lucene.util.Bits oldLiveDocs = in.getLiveDocs();
                    Bits oldLiveDocs = @in.LiveDocs;
                    Debug.Assert(oldLiveDocs != null);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.lucene.search.DocIdSetIterator it = bits.iterator();
                    DocIdSetIterator it = bits.GetEnumerator();
                    for (int i = it.nextDoc(); i < maxDoc; i = it.nextDoc())
                    {
                        if (!oldLiveDocs.get(i))
                        {
                            // we can safely modify the current bit, as the iterator already stepped over it:
                            bits.clear(i);
                        }
                    }
                }

                this.liveDocs        = bits;
                this.numDocs_Renamed = bits.cardinality();
            }
Esempio n. 3
0
 protected internal override Document FetchNextOrNull()
 {
     if (EnsureValidDisi())
     {
         try
         {
             int doc = CurrentIdIterator.nextDoc();
             if (doc == DocIdSetIterator.NO_MORE_DOCS)
             {
                 CurrentIdIterator = null;
                 CurrentScorer     = null;
                 CurrentReader     = null;
                 return(FetchNextOrNull());
             }
             return(CurrentReader.document(doc));
         }
         catch (IOException e)
         {
             throw new Exception(e);
         }
     }
     else
     {
         return(null);
     }
 }
Esempio n. 4
0
            internal virtual bool FetchNextEntityId()
            {
                try
                {
                    if (EnsureValidDisi())
                    {
                        int nextDoc = CurrentIdIterator.nextDoc();
                        if (nextDoc != DocIdSetIterator.NO_MORE_DOCS)
                        {
                            Index++;
                            Next = CurrentDocValues.get(nextDoc);
                            return(true);
                        }
                        else
                        {
                            CurrentIdIterator = null;
                            return(FetchNextEntityId());
                        }
                    }
                }
                catch (IOException e)
                {
                    throw new Exception(e);
                }

                return(false);
            }
Esempio n. 5
0
 protected internal override Document fetchNextOrNull()
 {
     try
     {
         int doc = idIterator.nextDoc();
         if (doc == DocIdSetIterator.NO_MORE_DOCS)
         {
             return(null);
         }
         return(outerInstance.getDocument(doc));
     }
     catch (IOException e)
     {
         throw new LuceneDocumentRetrievalException("Can't fetch document id from lucene index.", e);
     }
 }
Esempio n. 6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void replayTo(org.apache.lucene.search.Collector collector) throws java.io.IOException
        private void ReplayTo(Collector collector)
        {
            foreach (MatchingDocs docs in GetMatchingDocs())
            {
                LeafCollector    leafCollector = collector.getLeafCollector(docs.Context);
                Scorer           scorer;
                DocIdSetIterator idIterator = docs.DocIdSet.GetEnumerator();
                if (KeepScores)
                {
                    scorer = new ReplayingScorer(docs.Scores);
                }
                else
                {
                    scorer = new ConstantScoreScorer(null, Float.NaN, idIterator);
                }
                leafCollector.Scorer = scorer;
                int doc;
                while ((doc = idIterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
                {
                    leafCollector.collect(doc);
                }
            }
        }