本文整理汇总了C#中Lucene.Net.Search.BooleanQuery.Rewrite方法的典型用法代码示例。如果您正苦于以下问题:C# BooleanQuery.Rewrite方法的具体用法?C# BooleanQuery.Rewrite怎么用?C# BooleanQuery.Rewrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.BooleanQuery
的用法示例。
在下文中一共展示了BooleanQuery.Rewrite方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMethod
public virtual void TestMethod()
{
RAMDirectory directory = new RAMDirectory();
System.String[] categories = new System.String[]{"food", "foodanddrink", "foodanddrinkandgoodtimes", "food and drink"};
Query rw1 = null;
Query rw2 = null;
try
{
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
for (int i = 0; i < categories.Length; i++)
{
Document doc = new Document();
doc.Add(Field.Keyword("category", categories[i]));
writer.AddDocument(doc);
}
writer.Close();
IndexReader reader = IndexReader.Open(directory);
PrefixQuery query = new PrefixQuery(new Term("category", "foo"));
rw1 = query.Rewrite(reader);
BooleanQuery bq = new BooleanQuery();
bq.Add(query, true, false);
rw2 = bq.Rewrite(reader);
}
catch (System.IO.IOException e)
{
Assert.Fail(e.Message);
}
BooleanQuery bq1 = null;
if (rw1 is BooleanQuery)
{
bq1 = (BooleanQuery) rw1;
}
BooleanQuery bq2 = null;
if (rw2 is BooleanQuery)
{
bq2 = (BooleanQuery) rw2;
}
else
{
Assert.Fail("Rewrite");
}
Assert.AreEqual(bq1.GetClauses().Length, bq2.GetClauses().Length, "Number of Clauses Mismatch");
}
示例2: TestMethod
public virtual void TestMethod()
{
RAMDirectory directory = new RAMDirectory();
System.String[] categories = new System.String[]{"food", "foodanddrink", "foodanddrinkandgoodtimes", "food and drink"};
Query rw1 = null;
Query rw2 = null;
IndexReader reader = null;
try
{
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
for (int i = 0; i < categories.Length; i++)
{
Document doc = new Document();
doc.Add(new Field("category", categories[i], Field.Store.YES, Field.Index.NOT_ANALYZED));
writer.AddDocument(doc);
}
writer.Close();
reader = IndexReader.Open(directory);
PrefixQuery query = new PrefixQuery(new Term("category", "foo"));
rw1 = query.Rewrite(reader);
BooleanQuery bq = new BooleanQuery();
bq.Add(query, BooleanClause.Occur.MUST);
rw2 = bq.Rewrite(reader);
}
catch (System.IO.IOException e)
{
Assert.Fail(e.Message);
}
Assert.AreEqual(GetCount(reader, rw1), GetCount(reader, rw2), "Number of Clauses Mismatch");
}