Lucene.Net.Search.QueryUtils.WrapUnderlyingReader C# (CSharp) Method

WrapUnderlyingReader() public static method

Given an IndexSearcher, returns a new IndexSearcher whose IndexReader is a MultiReader containing the Reader of the original IndexSearcher, as well as several "empty" IndexReaders -- some of which will have deleted documents in them. this new IndexSearcher should behave exactly the same as the original IndexSearcher.
public static WrapUnderlyingReader ( Random random, IndexSearcher s, int edge, Similarity similarity ) : IndexSearcher
random System.Random
s IndexSearcher the searcher to wrap
edge int if negative, s will be the first sub; if 0, s will be in the middle, if positive s will be the last sub
similarity Similarity /// LUCENENET specific /// Removes dependency on ///
return IndexSearcher
        public static IndexSearcher WrapUnderlyingReader(Random random, IndexSearcher s, int edge, Similarity similarity)
        {
            IndexReader r = s.IndexReader;

            // we can't put deleted docs before the nested reader, because
            // it will throw off the docIds
            IndexReader[] readers = new IndexReader[] { edge < 0 ? r : EmptyReaders[0], EmptyReaders[0], new FCInvisibleMultiReader(edge < 0 ? EmptyReaders[4] : EmptyReaders[0], EmptyReaders[0], 0 == edge ? r : EmptyReaders[0]), 0 < edge ? EmptyReaders[0] : EmptyReaders[7], EmptyReaders[0], new FCInvisibleMultiReader(0 < edge ? EmptyReaders[0] : EmptyReaders[5], EmptyReaders[0], 0 < edge ? r : EmptyReaders[0]) };

            IndexSearcher @out = LuceneTestCase.NewSearcher(new FCInvisibleMultiReader(readers), similarity);
            @out.Similarity = s.Similarity;
            return @out;
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// Tests that a query matches the an expected set of documents using a
        /// HitCollector.
        /// <para>
        /// Note that when using the HitCollector API, documents will be collected
        /// if they "match" regardless of what their score is.
        /// </para>
        /// </summary>
        /// <param name="luceneTestCase"> The current test instance. </param>
        /// <param name="query"> The query to test. </param>
        /// <param name="searcher"> The searcher to test the query against. </param>
        /// <param name="defaultFieldName"> Used for displaying the query in assertion messages. </param>
        /// <param name="results"> A list of documentIds that must match the query. </param>
        /// <seealso cref="DoCheckHits(LuceneTestCase, Random, Query, string, IndexSearcher, int[])"/>
        // LUCENENET specific
        // Removes dependency on <see cref="LuceneTestCase.ClassEnv.Similarity"/>
        public static void CheckHitCollector(LuceneTestCase luceneTestCase, Random random, Query query, string defaultFieldName, IndexSearcher searcher, int[] results)
#endif
        {
            QueryUtils.Check(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                luceneTestCase,
#endif
                random, query, searcher);

            Trace.TraceInformation("Checked");

            SortedSet <int?> correct = new SortedSet <int?>();
            for (int i = 0; i < results.Length; i++)
            {
                correct.Add(Convert.ToInt32(results[i], CultureInfo.InvariantCulture));
            }
            SortedSet <int?> actual = new SortedSet <int?>();
            ICollector       c      = new SetCollector(actual);

            searcher.Search(query, c);

            Assert.AreEqual(correct, actual, "Simple: " + query.ToString(defaultFieldName));

            for (int i = -1; i < 2; i++)
            {
                actual.Clear();
                IndexSearcher s = QueryUtils.WrapUnderlyingReader(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                    luceneTestCase,
#endif
                    random, searcher, i);
                s.Search(query, c);
                Assert.AreEqual(correct, actual, "Wrap Reader " + i + ": " + query.ToString(defaultFieldName));
            }
        }
All Usage Examples Of Lucene.Net.Search.QueryUtils::WrapUnderlyingReader