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

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Scorer = ConstantScorer(1.0f);
            collector.Collect(1);
            collector.Scorer = ConstantScorer(2.0f);
            collector.Collect(2);

            // then
            IndexHits <Document> indexHits = collector.GetIndexHits(Sort.RELEVANCE);

            assertEquals(2, indexHits.Size());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("2", indexHits.next().get("id"));
            assertEquals(2.0f, indexHits.CurrentScore(), 0.001f);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("1", indexHits.next().get("id"));
            assertEquals(1.0f, indexHits.CurrentScore(), 0.001f);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(indexHits.hasNext());
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnIndexHitsInGivenSortOrder() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldReturnIndexHitsInGivenSortOrder()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(false);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(43);

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Collect(1);
            collector.Collect(3);
            collector.Collect(37);
            collector.Collect(42);

            // then
            Sort byIdDescending            = new Sort(new SortField("id", SortField.Type.LONG, true));
            IndexHits <Document> indexHits = collector.GetIndexHits(byIdDescending);

            assertEquals(4, indexHits.Size());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("42", indexHits.next().get("id"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("37", indexHits.next().get("id"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("3", indexHits.next().get("id"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("1", indexHits.next().get("id"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(indexHits.hasNext());
        }
コード例 #3
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());
        }
コード例 #4
0
        private static IndexReaderStub IndexReaderWithMaxDocs(int maxDocs)
        {
            NumericDocValues identityValues = new NumericDocValuesAnonymousInnerClass();
            IndexReaderStub  stub           = new IndexReaderStub(identityValues);

            stub.Elements = new string[maxDocs];
            return(stub);
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void nonUniqueIndexSampling() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void NonUniqueIndexSampling()
        {
            Terms aTerms  = GetTerms("a", 1);
            Terms idTerms = GetTerms("id", 2);
            Terms bTerms  = GetTerms("b", 3);
            IDictionary <string, Terms> fieldTermsMap = MapUtil.genericMap("0string", aTerms, "id", idTerms, "0array", bTerms);
            IndexReaderStub             indexReader   = new IndexReaderStub(new SamplingFields(fieldTermsMap));

            indexReader.Elements = new string[4];
            when(_indexSearcher.IndexReader).thenReturn(indexReader);

            assertEquals(new IndexSample(4, 2, 4), CreateSampler().sampleIndex());
        }
コード例 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnEmptyIteratorWhenNoDocValues()
        internal void ShouldReturnEmptyIteratorWhenNoDocValues()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(false);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);

            // then
            DocValuesCollector.LongValuesIterator valuesIterator = collector.GetValuesIterator("id");
            assertEquals(0, valuesIterator.Remaining());
            assertFalse(valuesIterator.HasNext());
        }
コード例 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnEmptyIteratorWhenNoDocValuesInOrder() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldReturnEmptyIteratorWhenNoDocValuesInOrder()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(false);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);

            // then
            LongIterator valuesIterator = collector.GetSortedValuesIterator("id", Sort.RELEVANCE);

            assertFalse(valuesIterator.hasNext());
        }
コード例 #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNotSaveScoresWhenNotRequired() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldNotSaveScoresWhenNotRequired()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(false);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

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

            // then
            DocValuesCollector.MatchingDocs matchingDocs = collector.GetMatchingDocs()[0];
            assertNull(matchingDocs.Scores);
        }
コード例 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void nonUniqueSamplingCancel() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void NonUniqueSamplingCancel()
        {
            Terms terms = GetTerms("test", 1);
            IDictionary <string, Terms> fieldTermsMap = MapUtil.genericMap("0string", terms, "id", terms, "0string", terms);
            IndexReaderStub             indexReader   = new IndexReaderStub(new SamplingFields(fieldTermsMap));

            when(_indexSearcher.IndexReader).thenReturn(indexReader);

            NonUniqueLuceneIndexSampler luceneIndexSampler = CreateSampler();

            _taskControl.cancel();
            IndexNotFoundKernelException notFoundKernelException = assertThrows(typeof(IndexNotFoundKernelException), luceneIndexSampler.sampleIndex);

            assertEquals(notFoundKernelException.Message, "Index dropped while sampling.");
        }
コード例 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSaveScoresWhenRequired() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldSaveScoresWhenRequired()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(true);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Scorer = ConstantScorer(13.42f);
            collector.Collect(1);

            // then
            DocValuesCollector.MatchingDocs matchingDocs = collector.GetMatchingDocs()[0];
            assertArrayEquals(new float[] { 13.42f }, matchingDocs.Scores, 0.001f);
        }
コード例 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnEmptyIteratorWhenNoHits() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldReturnEmptyIteratorWhenNoHits()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(false);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);

            // then
            IndexHits <Document> indexHits = collector.GetIndexHits(null);

            assertEquals(0, indexHits.Size());
            assertEquals(Float.NaN, indexHits.CurrentScore(), 0.001f);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(indexHits.hasNext());
        }
コード例 #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnDocValuesInIndexOrderWhenNoSortIsGiven() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldReturnDocValuesInIndexOrderWhenNoSortIsGiven()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(false);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Collect(1);
            collector.Collect(2);

            // then
            LongIterator valuesIterator = collector.GetSortedValuesIterator("id", null);

            assertEquals(1, valuesIterator.next());
            assertEquals(2, valuesIterator.next());
            assertFalse(valuesIterator.hasNext());
        }
コード例 #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReadDocValuesInIndexOrder() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldReadDocValuesInIndexOrder()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(false);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Collect(1);
            collector.Collect(2);

            // then
            DocValuesCollector.LongValuesIterator valuesIterator = collector.GetValuesIterator("id");
            assertEquals(2, valuesIterator.Remaining());
            assertEquals(1, valuesIterator.Next());
            assertEquals(2, valuesIterator.Next());
            assertFalse(valuesIterator.HasNext());
        }
コード例 #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnDocValuesInGivenOrder() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldReturnDocValuesInGivenOrder()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(false);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Collect(1);
            collector.Collect(2);

            // then
            Sort         byIdDescending = new Sort(new SortField("id", SortField.Type.LONG, true));
            LongIterator valuesIterator = collector.GetSortedValuesIterator("id", byIdDescending);

            assertEquals(2, valuesIterator.next());
            assertEquals(1, valuesIterator.next());
            assertFalse(valuesIterator.hasNext());
        }
コード例 #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnDocValuesInRelevanceOrder() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldReturnDocValuesInRelevanceOrder()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(true);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Scorer = ConstantScorer(1.0f);
            collector.Collect(1);
            collector.Scorer = ConstantScorer(2.0f);
            collector.Collect(2);

            // then
            LongIterator valuesIterator = collector.GetSortedValuesIterator("id", Sort.RELEVANCE);

            assertEquals(2, valuesIterator.next());
            assertEquals(1, valuesIterator.next());
            assertFalse(valuesIterator.hasNext());
        }
コード例 #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldDynamicallyResizeScoresArray() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldDynamicallyResizeScoresArray()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(true);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Scorer = ConstantScorer(1.0f);
            // scores starts with array size of 32, adding 42 docs forces resize
            for (int i = 0; i < 42; i++)
            {
                collector.Collect(i);
            }

            // then
            DocValuesCollector.MatchingDocs matchingDocs = collector.GetMatchingDocs()[0];
            float[] scores = new float[42];
            Arrays.fill(scores, 1.0f);
            assertArrayEquals(scores, matchingDocs.Scores, 0.001f);
        }
コード例 #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnIndexHitsInIndexOrderWhenNoSortIsGiven() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldReturnIndexHitsInIndexOrderWhenNoSortIsGiven()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector();
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Collect(1);
            collector.Collect(2);

            // then
            IndexHits <Document> indexHits = collector.GetIndexHits(null);

            assertEquals(2, indexHits.Size());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("1", indexHits.next().get("id"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("2", indexHits.next().get("id"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(indexHits.hasNext());
        }