当前位置: 首页>>代码示例>>C#>>正文


C# IndexSearcher.Rewrite方法代码示例

本文整理汇总了C#中Lucene.Net.Search.IndexSearcher.Rewrite方法的典型用法代码示例。如果您正苦于以下问题:C# IndexSearcher.Rewrite方法的具体用法?C# IndexSearcher.Rewrite怎么用?C# IndexSearcher.Rewrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Search.IndexSearcher的用法示例。


在下文中一共展示了IndexSearcher.Rewrite方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestTermWithoutWildcard

        public virtual void TestTermWithoutWildcard()
		{
		    RAMDirectory indexStore = GetIndexStore("field", new System.String[] {"nowildcard", "nowildcardx"});
		    IndexSearcher searcher = new IndexSearcher(indexStore, true);

		    MultiTermQuery wq = new WildcardQuery(new Term("field", "nowildcard"));
		    AssertMatches(searcher, wq, 1);

		    wq.RewriteMethod = MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE;
		    wq.Boost = 0.1f;
		    Query q = searcher.Rewrite(wq);
		    Assert.IsTrue(q is TermQuery);
		    Assert.AreEqual(q.Boost, wq.Boost);

		    wq.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE;
		    wq.Boost = 0.2f;
		    q = searcher.Rewrite(wq);
		    Assert.True(q is ConstantScoreQuery);
		    Assert.AreEqual(q.Boost, wq.Boost);

		    wq.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
		    wq.Boost = 0.3F;
		    q = searcher.Rewrite(wq);
		    Assert.True(q is ConstantScoreQuery);
		    Assert.AreEqual(q.Boost, wq.Boost);

		    wq.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE;
		    wq.Boost = 0.4F;
		    q = searcher.Rewrite(wq);
		    Assert.True(q is ConstantScoreQuery);
		    Assert.AreEqual(q.Boost, wq.Boost);
		}
开发者ID:raol,项目名称:lucene.net,代码行数:32,代码来源:TestWildcard.cs

示例2: TestTermWithoutWildcard

		public virtual void  TestTermWithoutWildcard()
		{
			RAMDirectory indexStore = GetIndexStore("field", new System.String[]{"nowildcard", "nowildcardx"});
			IndexSearcher searcher = new IndexSearcher(indexStore);
			
			Query wq = new WildcardQuery(new Term("field", "nowildcard"));
			AssertMatches(searcher, wq, 1);
			
			wq = searcher.Rewrite(wq);
			Assert.IsTrue(wq is TermQuery);
		}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:11,代码来源:TestWildcard.cs

示例3: TestPrefixTerm

        public void TestPrefixTerm()
        {
            RAMDirectory indexStore = GetIndexStore("field", new String[] { "prefix", "prefixx" });
            IndexSearcher searcher = new IndexSearcher(indexStore, true);

            MultiTermQuery wq = new WildcardQuery(new Term("field", "prefix*"));
            AssertMatches(searcher, wq, 2);

            MultiTermQuery expected = new PrefixQuery(new Term("field", "prefix"));
            wq.RewriteMethod = MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE;
            wq.Boost = 0.1F;
            expected.RewriteMethod = wq.RewriteMethod;
            expected.Boost = wq.Boost;
            Assert.AreEqual(searcher.Rewrite(expected), searcher.Rewrite(wq));

            wq.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE;
            wq.Boost = 0.2F;
            expected.RewriteMethod = wq.RewriteMethod;
            expected.Boost = wq.Boost;
            Assert.AreEqual(searcher.Rewrite(expected), searcher.Rewrite(wq));

            wq.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
            wq.Boost = 0.3F;
            expected.RewriteMethod = wq.RewriteMethod;
            expected.Boost = wq.Boost;
            Assert.AreEqual(searcher.Rewrite(expected), searcher.Rewrite(wq));

            wq.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE;
            wq.Boost = 0.4F;
            expected.RewriteMethod = wq.RewriteMethod;
            expected.Boost = wq.Boost;
            Assert.AreEqual(searcher.Rewrite(expected), searcher.Rewrite(wq));
        }
开发者ID:raol,项目名称:lucene.net,代码行数:33,代码来源:TestWildcard.cs

示例4: TestEmptyTerm

        public void TestEmptyTerm()
        {
            RAMDirectory indexStore = GetIndexStore("field", new String[] { "nowildcard", "nowildcardx" });
            IndexSearcher searcher = new IndexSearcher(indexStore, true);

            MultiTermQuery wq = new WildcardQuery(new Term("field", ""));
            wq.RewriteMethod = MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE;
            AssertMatches(searcher, wq, 0);
            BooleanQuery expected = new BooleanQuery(true);
            Assert.AreEqual(searcher.Rewrite(expected), searcher.Rewrite(wq));
        }
开发者ID:raol,项目名称:lucene.net,代码行数:11,代码来源:TestWildcard.cs

示例5: Check

        public static void Check(Random random, Query q1, IndexSearcher s, bool wrap)
        {
            try
            {
                Check(q1);
                if (s != null)
                {
                    CheckFirstSkipTo(q1, s);
                    CheckSkipTo(q1, s);
                    if (wrap)
                    {
                        Check(random, q1, WrapUnderlyingReader(random, s, -1), false);
                        Check(random, q1, WrapUnderlyingReader(random, s, 0), false);
                        Check(random, q1, WrapUnderlyingReader(random, s, +1), false);
                    }
                    CheckExplanations(q1, s);

                    Query q2 = (Query)q1.Clone();
                    CheckEqual(s.Rewrite(q1), s.Rewrite(q2));
                }
            }
            catch (IOException e)
            {
                throw new Exception(e.Message, e);
            }
        }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:26,代码来源:QueryUtils.cs

示例6: CheckBooleanTerms

 private void CheckBooleanTerms(IndexSearcher searcher, TermRangeQuery query, params string[] terms)
 {
     query.SetRewriteMethod(new MultiTermQuery.TopTermsScoringBooleanQueryRewrite(50));
     BooleanQuery bq = (BooleanQuery)searcher.Rewrite(query);
     var allowedTerms = AsSet(terms);
     Assert.AreEqual(allowedTerms.Count, bq.Clauses.Length);
     foreach (BooleanClause c in bq.Clauses)
     {
         Assert.IsTrue(c.Query is TermQuery);
         TermQuery tq = (TermQuery)c.Query;
         string term = tq.Term.Text();
         Assert.IsTrue(allowedTerms.Contains(term), "invalid term: " + term);
         allowedTerms.Remove(term); // remove to fail on double terms
     }
     Assert.AreEqual(0, allowedTerms.Count);
 }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:16,代码来源:TestTermRangeQuery.cs

示例7: TestDeMorgan

        public virtual void TestDeMorgan()
        {
            Directory dir1 = NewDirectory();
            RandomIndexWriter iw1 = new RandomIndexWriter(Random(), dir1, Similarity, TimeZone);
            Document doc1 = new Document();
            doc1.Add(NewTextField("field", "foo bar", Field.Store.NO));
            iw1.AddDocument(doc1);
            IndexReader reader1 = iw1.Reader;
            iw1.Dispose();

            Directory dir2 = NewDirectory();
            RandomIndexWriter iw2 = new RandomIndexWriter(Random(), dir2, Similarity, TimeZone);
            Document doc2 = new Document();
            doc2.Add(NewTextField("field", "foo baz", Field.Store.NO));
            iw2.AddDocument(doc2);
            IndexReader reader2 = iw2.Reader;
            iw2.Dispose();

            BooleanQuery query = new BooleanQuery(); // Query: +foo -ba*
            query.Add(new TermQuery(new Term("field", "foo")), BooleanClause.Occur.MUST);
            WildcardQuery wildcardQuery = new WildcardQuery(new Term("field", "ba*"));
            wildcardQuery.SetRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
            query.Add(wildcardQuery, BooleanClause.Occur.MUST_NOT);

            MultiReader multireader = new MultiReader(reader1, reader2);
            IndexSearcher searcher = NewSearcher(multireader);
            Assert.AreEqual(0, searcher.Search(query, 10).TotalHits);


            Task foo = new Task(TestDeMorgan);

            TaskScheduler es = TaskScheduler.Default;
            searcher = new IndexSearcher(multireader, es);
            if (VERBOSE)
            {
                Console.WriteLine("rewritten form: " + searcher.Rewrite(query));
            }
            Assert.AreEqual(0, searcher.Search(query, 10).TotalHits);

            multireader.Dispose();
            reader1.Dispose();
            reader2.Dispose();
            dir1.Dispose();
            dir2.Dispose();
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:45,代码来源:TestBooleanQuery.cs


注:本文中的Lucene.Net.Search.IndexSearcher.Rewrite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。