本文整理汇总了C#中Lucene.Net.Search.Query.Where方法的典型用法代码示例。如果您正苦于以下问题:C# Query.Where方法的具体用法?C# Query.Where怎么用?C# Query.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.Query
的用法示例。
在下文中一共展示了Query.Where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildGeneralQuery
private static Query BuildGeneralQuery(
bool doExactId,
string originalSearchText,
Analyzer analyzer,
IEnumerable<NuGetSearchTerm> generalTerms,
IEnumerable<Query> generalQueries)
{
// All terms in the multi-term query appear in at least one of the target fields.
var conjuctionQuery = new BooleanQuery();
conjuctionQuery.Boost = 2.0f;
// Some terms in the multi-term query appear in at least one of the target fields.
var disjunctionQuery = new BooleanQuery();
disjunctionQuery.Boost = 0.1f;
// Suffix wildcard search e.g. jquer*
var wildCardQuery = new BooleanQuery();
wildCardQuery.Boost = 0.5f;
string escapedExactId = originalSearchText.ToLowerInvariant();
Query exactIdQuery = null;
Query wildCardIdQuery = null;
if (doExactId)
{
exactIdQuery = new TermQuery(new Term("Id-Exact", escapedExactId));
exactIdQuery.Boost = 7.5f;
wildCardIdQuery = new WildcardQuery(new Term("Id-Exact", "*" + escapedExactId + "*"));
}
Query nearlyExactIdQuery = null;
if (generalTerms.Any())
{
string escapedApproximateId = string.Join(" ", generalTerms.Select(c => c.TermOrPhrase));
nearlyExactIdQuery = AnalysisHelper.GetFieldQuery(analyzer, "Id", escapedApproximateId);
nearlyExactIdQuery.Boost = 2.0f;
}
foreach (var termQuery in generalQueries)
{
conjuctionQuery.Add(termQuery, Occur.MUST);
disjunctionQuery.Add(termQuery, Occur.SHOULD);
}
var sanitizedTerms = generalTerms.Select(c => c.TermOrPhrase.ToLowerInvariant());
foreach (var sanitizedTerm in sanitizedTerms)
{
foreach (var field in Fields)
{
var wildCardTermQuery = new WildcardQuery(new Term(field, sanitizedTerm + "*"));
wildCardTermQuery.Boost = 0.7f;
wildCardQuery.Add(wildCardTermQuery, Occur.SHOULD);
}
}
// OR of all the applicable queries
var queries = new Query[]
{
exactIdQuery, wildCardIdQuery, nearlyExactIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery
};
var queriesToCombine = queries.Where(q => !IsDegenerateQuery(q));
var query = conjuctionQuery.Combine(queriesToCombine.ToArray());
return query;
}