Wrap() public static method

Wrap a query if necessary.
public static Wrap ( Random random, Query query ) : Query
random System.Random
query Query
return Query
Ejemplo n.º 1
0
        public virtual void TestQueryWrapperFilter()
        {
            Directory         d   = NewDirectory();
            RandomIndexWriter w   = new RandomIndexWriter(Random, d, Similarity, TimeZone);
            Document          doc = new Document();

            doc.Add(NewStringField("field", "a", Field.Store.NO));
            w.AddDocument(doc);
            IndexReader r = w.GetReader();

            w.Dispose();

            Filter        filter = new QueryWrapperFilter(AssertingQuery.Wrap(Random, new TermQuery(new Term("field", "a"))));
            IndexSearcher s      = NewSearcher(r);

            Debug.Assert(s is AssertingIndexSearcher);
            // this used to fail
            s.Search(new ConstantScoreQuery(filter), new TotalHitCountCollector());

            // check the rewrite
            Query rewritten = (new ConstantScoreQuery(filter)).Rewrite(r);

            Assert.IsTrue(rewritten is ConstantScoreQuery);
            Assert.IsTrue(((ConstantScoreQuery)rewritten).Query is AssertingQuery);

            r.Dispose();
            d.Dispose();
        }
Ejemplo n.º 2
0
        public virtual void TestQueryWrapperFilter()
        {
            Directory         d = NewDirectory();
            RandomIndexWriter w = new RandomIndexWriter(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                this,
#endif
                Random, d);
            Document doc = new Document();

            doc.Add(NewStringField("field", "a", Field.Store.NO));
            w.AddDocument(doc);
            IndexReader r = w.GetReader();

            w.Dispose();

            Filter        filter = new QueryWrapperFilter(AssertingQuery.Wrap(Random, new TermQuery(new Term("field", "a"))));
            IndexSearcher s      = NewSearcher(r);

            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(s is AssertingIndexSearcher);
            }
            // this used to fail
            s.Search(new ConstantScoreQuery(filter), new TotalHitCountCollector());

            // check the rewrite
            Query rewritten = (new ConstantScoreQuery(filter)).Rewrite(r);

            Assert.IsTrue(rewritten is ConstantScoreQuery);
            Assert.IsTrue(((ConstantScoreQuery)rewritten).Query is AssertingQuery);

            r.Dispose();
            d.Dispose();
        }