本文整理汇总了C#中Lucene.Net.QueryParsers.QueryParser.SetEnablePositionIncrements方法的典型用法代码示例。如果您正苦于以下问题:C# QueryParser.SetEnablePositionIncrements方法的具体用法?C# QueryParser.SetEnablePositionIncrements怎么用?C# QueryParser.SetEnablePositionIncrements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.QueryParsers.QueryParser
的用法示例。
在下文中一共展示了QueryParser.SetEnablePositionIncrements方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSingleCharTokenAnalyzer
public void TestSingleCharTokenAnalyzer()
{
Analyzer analyzer = new SingleCharTokenAnalyzer();
IndexSearcher src = CreateIndex("[email protected] 1234567890 abcdefgh", analyzer);
QueryParser p = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "field", analyzer);
p.SetDefaultOperator(QueryParser.Operator.AND);
p.SetEnablePositionIncrements(true);
TopDocs td = null;
td = src.Search(p.Parse("usergmail"), 10);
Assert.AreEqual(0, td.totalHits);
td = src.Search(p.Parse("gmailcom"), 10);
Assert.AreEqual(0, td.totalHits);
td = src.Search(p.Parse("678"), 10);
Assert.AreEqual(1, td.totalHits);
td = src.Search(p.Parse("someuser"), 10);
Assert.AreEqual(1, td.totalHits);
td = src.Search(p.Parse("omeuse"), 10);
Assert.AreEqual(1, td.totalHits);
td = src.Search(p.Parse("omeuse 6789"), 10);
Assert.AreEqual(1, td.totalHits);
td = src.Search(p.Parse("user gmail"), 10);
Assert.AreEqual(1, td.totalHits);
td = src.Search(p.Parse("\"user gmail\""), 10);
Assert.AreEqual(1, td.totalHits);
td = src.Search(p.Parse("[email protected]"), 10);
Assert.AreEqual(1, td.totalHits);
td = src.Search(p.Parse("gmail.com"), 10);
Assert.AreEqual(1, td.totalHits);
td = src.Search(p.Parse("\"gmail.com 1234\""), 10);
Assert.AreEqual(1, td.totalHits);
td = src.Search(p.Parse("\"gmail.com defg\""), 10);
Assert.AreEqual(0, td.totalHits);
td = src.Search(p.Parse("gmail.com defg"), 10);
Assert.AreEqual(1, td.totalHits);
}
示例2: TestPositionIncrement
public virtual void TestPositionIncrement()
{
bool dflt = StopFilter.GetEnablePositionIncrementsDefault();
StopFilter.SetEnablePositionIncrementsDefault(true);
try
{
QueryParser qp = new QueryParser("a", new StopAnalyzer(new System.String[]{"the", "in", "are", "this"}));
qp.SetEnablePositionIncrements(true);
System.String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\"";
// 0 2 5 7 8
int[] expectedPositions = new int[]{1, 3, 4, 6, 9};
PhraseQuery pq = (PhraseQuery) qp.Parse(qtxt);
//System.out.println("Query text: "+qtxt);
//System.out.println("Result: "+pq);
Term[] t = pq.GetTerms();
int[] pos = pq.GetPositions();
for (int i = 0; i < t.Length; i++)
{
//System.out.println(i+". "+t[i]+" pos: "+pos[i]);
Assert.AreEqual(expectedPositions[i], pos[i], "term " + i + " = " + t[i] + " has wrong term-position!");
}
}
finally
{
StopFilter.SetEnablePositionIncrementsDefault(dflt);
}
}