本文整理汇总了C#中Lucene.Net.Search.PhraseQuery.SetBoost方法的典型用法代码示例。如果您正苦于以下问题:C# PhraseQuery.SetBoost方法的具体用法?C# PhraseQuery.SetBoost怎么用?C# PhraseQuery.SetBoost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.PhraseQuery
的用法示例。
在下文中一共展示了PhraseQuery.SetBoost方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BoostedCaseInsensitivePhrase
public void BoostedCaseInsensitivePhrase()
{
BooleanQuery originalQuery = new BooleanQuery();
Term term = new Term("_name", "value");
PhraseQuery phraseQuery = new PhraseQuery();
phraseQuery.SetSlop(2);
phraseQuery.Add(term);
phraseQuery.SetBoost(10);
originalQuery.Add(phraseQuery, BooleanClause.Occur.MUST);
string queryString = originalQuery.ToString();
QueryBuilder builder = new QueryBuilder();
builder.Setup(x => x.Phrase(2, 10).AddTerm("_name", "Value"));
Query replacementQuery = builder.Build();
string newQueryString = replacementQuery.ToString();
Assert.AreEqual(queryString, newQueryString);
Console.Write(queryString);
}
示例2: CheckOverlap
/*
* Check if src and dest have overlapped part and if it is, create PhraseQueries and add expandQueries.
*
* ex1) src="a b", dest="c d" => no overlap
* ex2) src="a b", dest="a b c" => no overlap
* ex3) src="a b", dest="b c" => overlap; expandQueries={"a b c"}
* ex4) src="a b c", dest="b c d" => overlap; expandQueries={"a b c d"}
* ex5) src="a b c", dest="b c" => no overlap
* ex6) src="a b c", dest="b" => no overlap
* ex7) src="a a a a", dest="a a a" => overlap;
* expandQueries={"a a a a a","a a a a a a"}
* ex8) src="a b c d", dest="b c" => no overlap
*/
private void CheckOverlap(Dictionary<Query,Query> expandQueries, Term[] src, Term[] dest, int slop, float boost)
{
// beginning from 1 (not 0) is safe because that the PhraseQuery has multiple terms
// is guaranteed in flatten() method (if PhraseQuery has only one term, flatten()
// converts PhraseQuery to TermQuery)
for (int i = 1; i < src.Length; i++)
{
bool overlap = true;
for (int j = i; j < src.Length; j++)
{
if ((j - i) < dest.Length && !src[j].Text().Equals(dest[j - i].Text()))
{
overlap = false;
break;
}
}
if (overlap && src.Length - i < dest.Length)
{
PhraseQuery pq = new PhraseQuery();
foreach (Term srcTerm in src)
pq.Add(srcTerm);
for (int k = src.Length - i; k < dest.Length; k++)
{
pq.Add(new Term(src[0].Field(), dest[k].Text()));
}
pq.SetSlop(slop);
pq.SetBoost(boost);
if (!expandQueries.ContainsKey(pq))
expandQueries.Add(pq,pq);
}
}
}
示例3: Pq
protected Query Pq(float boost, int slop, String field, params String[] texts)
{
PhraseQuery query = new PhraseQuery();
foreach (String text in texts)
{
query.Add(new Term(field, text));
}
query.SetBoost(boost);
query.SetSlop(slop);
return query;
}