本文整理汇总了C#中Lucene.Net.Search.Query.Rewrite方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Search.Query.Rewrite方法的具体用法?C# Lucene.Net.Search.Query.Rewrite怎么用?C# Lucene.Net.Search.Query.Rewrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.Query
的用法示例。
在下文中一共展示了Lucene.Net.Search.Query.Rewrite方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoSearching
public virtual void DoSearching(Query unReWrittenQuery)
{
searcher = new IndexSearcher(ramDir);
//for any multi-term queries to work (prefix, wildcard, range,fuzzy etc) you must use a rewritten query!
query = unReWrittenQuery.Rewrite(reader);
System.Console.Out.WriteLine("Searching for: " + query.ToString(FIELD_NAME));
hits = searcher.Search(query);
}
示例2: TestMultiSearcher
public virtual void TestMultiSearcher()
{
//setup index 1
RAMDirectory ramDir1 = new RAMDirectory();
IndexWriter writer1 = new IndexWriter(ramDir1, new StandardAnalyzer(), true);
Document d = new Document();
Field f = new Field(FIELD_NAME, "multiOne", Field.Store.YES, Field.Index.TOKENIZED);
d.Add(f);
writer1.AddDocument(d);
writer1.Optimize();
writer1.Close();
IndexReader reader1 = IndexReader.Open(ramDir1);
//setup index 2
RAMDirectory ramDir2 = new RAMDirectory();
IndexWriter writer2 = new IndexWriter(ramDir2, new StandardAnalyzer(), true);
d = new Document();
f = new Field(FIELD_NAME, "multiTwo", Field.Store.YES, Field.Index.TOKENIZED);
d.Add(f);
writer2.AddDocument(d);
writer2.Optimize();
writer2.Close();
IndexReader reader2 = IndexReader.Open(ramDir2);
IndexSearcher[] searchers = new IndexSearcher[2];
searchers[0] = new IndexSearcher(ramDir1);
searchers[1] = new IndexSearcher(ramDir2);
MultiSearcher multiSearcher = new MultiSearcher(searchers);
QueryParser parser = new QueryParser(FIELD_NAME, new StandardAnalyzer());
parser.SetMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
query = parser.Parse("multi*");
System.Console.Out.WriteLine("Searching for: " + query.ToString(FIELD_NAME));
//at this point the multisearcher calls combine(query[])
hits = multiSearcher.Search(query);
//query = QueryParser.parse("multi*", FIELD_NAME, new StandardAnalyzer());
Query[] expandedQueries = new Query[2];
expandedQueries[0] = query.Rewrite(reader1);
expandedQueries[1] = query.Rewrite(reader2);
query = query.Combine(expandedQueries);
//create an instance of the highlighter with the tags used to surround highlighted text
Highlighter highlighter = new Highlighter(this, new QueryScorer(query));
for (int i = 0; i < hits.Length(); i++)
{
System.String text = hits.Doc(i).Get(FIELD_NAME);
TokenStream tokenStream = analyzer.TokenStream(FIELD_NAME, new System.IO.StringReader(text));
System.String highlightedText = highlighter.GetBestFragment(tokenStream, text);
System.Console.Out.WriteLine(highlightedText);
}
Assert.IsTrue(numHighlights == 2, "Failed to find correct number of highlights " + numHighlights + " found");
}