本文整理汇总了C#中Lucene.Net.Search.BooleanQuery.Combine方法的典型用法代码示例。如果您正苦于以下问题:C# BooleanQuery.Combine方法的具体用法?C# BooleanQuery.Combine怎么用?C# BooleanQuery.Combine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.BooleanQuery
的用法示例。
在下文中一共展示了BooleanQuery.Combine方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseQuery
private static Query ParseQuery(SearchFilter searchFilter)
{
var fields = new[] { "Id", "Title", "Tags", "Description", "Author" };
var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields, analyzer);
// All terms in the multi-term query appear in at least one of the fields.
var conjuctionQuery = new BooleanQuery();
conjuctionQuery.SetBoost(2.0f);
// Some terms in the multi-term query appear in at least one of the fields.
var disjunctionQuery = new BooleanQuery();
disjunctionQuery.SetBoost(0.1f);
// Suffix wildcard search e.g. jquer*
var wildCardQuery = new BooleanQuery();
wildCardQuery.SetBoost(0.5f);
// Escape the entire term we use for exact searches.
var escapedSearchTerm = Escape(searchFilter.SearchTerm);
var exactIdQuery = new TermQuery(new Term("Id-Exact", escapedSearchTerm));
exactIdQuery.SetBoost(2.5f);
var wildCardIdQuery = new WildcardQuery(new Term("Id-Exact", "*" + escapedSearchTerm + "*"));
foreach (var term in GetSearchTerms(searchFilter.SearchTerm))
{
var termQuery = queryParser.Parse(term);
conjuctionQuery.Add(termQuery, BooleanClause.Occur.MUST);
disjunctionQuery.Add(termQuery, BooleanClause.Occur.SHOULD);
foreach (var field in fields)
{
var wildCardTermQuery = new WildcardQuery(new Term(field, term + "*"));
wildCardTermQuery.SetBoost(0.7f);
wildCardQuery.Add(wildCardTermQuery, BooleanClause.Occur.SHOULD);
}
}
// Create an OR of all the queries that we have
var combinedQuery = conjuctionQuery.Combine(new Query[] { exactIdQuery, wildCardIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery });
if (searchFilter.SortProperty == SortProperty.Relevance)
{
// If searching by relevance, boost scores by download count.
var downloadCountBooster = new FieldScoreQuery("DownloadCount", FieldScoreQuery.Type.INT);
return new CustomScoreQuery(combinedQuery, downloadCountBooster);
}
return combinedQuery;
}
示例2: ParseQuery
private static Query ParseQuery(string searchTerm)
{
var fields = new Dictionary<string, float> { { "Id", 1.2f }, { "Title", 1.0f }, { "Tags", 0.8f }, { "Description", 0.1f },
{ "Author", 1.0f } };
var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields.Keys.ToArray(), analyzer, fields);
var conjuctionQuery = new BooleanQuery();
conjuctionQuery.SetBoost(2.0f);
var disjunctionQuery = new BooleanQuery();
disjunctionQuery.SetBoost(0.1f);
var wildCardQuery = new BooleanQuery();
wildCardQuery.SetBoost(0.5f);
// Escape the entire term we use for exact searches.
var escapedSearchTerm = Escape(searchTerm);
var exactIdQuery = new TermQuery(new Term("Id-Exact", escapedSearchTerm));
exactIdQuery.SetBoost(2.5f);
var wildCardIdQuery = new WildcardQuery(new Term("Id-Exact", "*" + escapedSearchTerm + "*"));
foreach(var term in GetSearchTerms(searchTerm))
{
var termQuery = queryParser.Parse(term);
conjuctionQuery.Add(termQuery, BooleanClause.Occur.MUST);
disjunctionQuery.Add(termQuery, BooleanClause.Occur.SHOULD);
foreach (var field in fields)
{
var wildCardTermQuery = new WildcardQuery(new Term(field.Key, term + "*"));
wildCardTermQuery.SetBoost(0.7f * field.Value);
wildCardQuery.Add(wildCardTermQuery, BooleanClause.Occur.SHOULD);
}
}
var downloadCountBooster = new FieldScoreQuery("DownloadCount", FieldScoreQuery.Type.INT);
return new CustomScoreQuery(conjuctionQuery.Combine(new Query[] { exactIdQuery, wildCardIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery }),
downloadCountBooster);
}
示例3: ParseQuery
private static Query ParseQuery(string searchTerm)
{
var fields = new Dictionary<string, float> { { "Id", 1.2f }, { "Title", 1.0f }, { "Tags", 1.0f}, { "Description", 0.8f }, { "Author", 0.6f } };
var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
searchTerm = QueryParser.Escape(searchTerm).ToLowerInvariant();
var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields.Keys.ToArray(), analyzer, fields);
var conjuctionQuery = new BooleanQuery();
conjuctionQuery.SetBoost(1.5f);
var disjunctionQuery = new BooleanQuery();
var wildCardQuery = new BooleanQuery();
wildCardQuery.SetBoost(0.7f);
var exactIdQuery = new TermQuery(new Term("Id-Exact", searchTerm));
exactIdQuery.SetBoost(2.5f);
foreach(var term in searchTerm.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
{
conjuctionQuery.Add(queryParser.Parse(term), BooleanClause.Occur.MUST);
disjunctionQuery.Add(queryParser.Parse(term), BooleanClause.Occur.SHOULD);
foreach (var field in fields)
{
var wildCardTermQuery = new WildcardQuery(new Term(field.Key, term + "*"));
wildCardTermQuery.SetBoost(0.7f * field.Value);
wildCardQuery.Add(wildCardTermQuery, BooleanClause.Occur.SHOULD);
}
}
return conjuctionQuery.Combine(new Query[] { exactIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery });
}
示例4: 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;
}
示例5: ParseQuery
private static Query ParseQuery(SearchFilter searchFilter)
{
if (String.IsNullOrWhiteSpace(searchFilter.SearchTerm))
{
return new MatchAllDocsQuery();
}
var fields = new[] { "Id", "Title", "Tags", "Description", "Author" };
var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields, analyzer);
// All terms in the multi-term query appear in at least one of the fields.
var conjuctionQuery = new BooleanQuery();
conjuctionQuery.Boost = 2.0f;
// Some terms in the multi-term query appear in at least one of the fields.
var disjunctionQuery = new BooleanQuery();
disjunctionQuery.Boost = 0.1f;
// Suffix wildcard search e.g. jquer*
var wildCardQuery = new BooleanQuery();
wildCardQuery.Boost = 0.5f;
// Escape the entire term we use for exact searches.
var escapedSearchTerm = Escape(searchFilter.SearchTerm).Replace("id\\:", string.Empty).Replace("author\\:", string.Empty).Replace("tag\\:", string.Empty);
bool searchLimiter = false;
bool onlySearchById = false;
bool onlySearchByAuthor = false;
bool onlySearchByTag = false;
var exactIdQuery = new TermQuery(new Term("Id-Exact", escapedSearchTerm));
exactIdQuery.Boost = 2.5f;
var wildCardIdQuery = new WildcardQuery(new Term("Id-Exact", "*" + escapedSearchTerm + "*"));
foreach (var term in GetSearchTerms(searchFilter.SearchTerm))
{
var localTerm = term.to_lower_invariant();
onlySearchById = localTerm.StartsWith("id\\:");
onlySearchByAuthor = localTerm.StartsWith("author\\:");
onlySearchByTag = localTerm.StartsWith("tag\\:");
if (onlySearchById || onlySearchByAuthor || onlySearchByTag) searchLimiter = true;
localTerm = term.Replace("id\\:", string.Empty).Replace("author\\:", string.Empty).Replace("tag\\:", string.Empty);
var termQuery = queryParser.Parse(localTerm);
conjuctionQuery.Add(termQuery, Occur.MUST);
disjunctionQuery.Add(termQuery, Occur.SHOULD);
foreach (var field in fields)
{
if (onlySearchById && field != "Id") continue;
if (onlySearchByAuthor && field != "Author") continue;
if (onlySearchByTag && field != "Tags") continue;
var wildCardTermQuery = new WildcardQuery(new Term(field, localTerm + "*"));
wildCardTermQuery.Boost = searchLimiter ? 2.5f : 0.7f;
wildCardQuery.Add(wildCardTermQuery, Occur.SHOULD);
}
}
// Create an OR of all the queries that we have
var combinedQuery = conjuctionQuery.Combine(new Query[] { exactIdQuery, wildCardIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery });
if (onlySearchById)
{
combinedQuery = conjuctionQuery.Combine(new Query[] { exactIdQuery, wildCardIdQuery, wildCardQuery });
} else if (onlySearchByAuthor || onlySearchByTag)
{
combinedQuery = conjuctionQuery.Combine(new Query[] { wildCardQuery });
}
if (searchFilter.SortProperty == SortProperty.Relevance)
{
// If searching by relevance, boost scores by download count.
var downloadCountBooster = new FieldScoreQuery("DownloadCount", FieldScoreQuery.Type.INT);
return new CustomScoreQuery(combinedQuery, downloadCountBooster);
}
return combinedQuery;
}
示例6: ParseQuery
private static Query ParseQuery(QueryTerm queryTerm, SearchFilter searchFilter)
{
var combineQuery = new BooleanQuery();
#region 关键字查询构建
if (!String.IsNullOrWhiteSpace(searchFilter.SearchTerm))
{
var fields = new[] {
OutDoorIndexFields.Title,
OutDoorIndexFields.Description,
OutDoorIndexFields.AreaCate,
OutDoorIndexFields.IndustryCate,
OutDoorIndexFields.CrowdCate,
OutDoorIndexFields.PurposeCate,
OutDoorIndexFields.MediaCateName,
OutDoorIndexFields.CityCateName,
OutDoorIndexFields.FormatName,
OutDoorIndexFields.PeriodName,
OutDoorIndexFields.OwnerName
};
var analyzer = new PanGuAnalyzer();
//var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields, analyzer);
var query = queryParser.Parse(searchFilter.SearchTerm);
//conjuction 一起选择
var conjuctionQuery = new BooleanQuery();
conjuctionQuery.Boost = 2.0f;
//disjunction 分离
var disjunctionQuery = new BooleanQuery();
disjunctionQuery.Boost = 0.1f;
//wildCard 通配符
var wildCardQuery = new BooleanQuery();
wildCardQuery.Boost = 0.5f;
var escapedSearchTerm = Escape(searchFilter.SearchTerm);
var exactIdQuery = new TermQuery(new Term(OutDoorIndexFields.Title, escapedSearchTerm));
exactIdQuery.Boost = 2.5f;
var wildCardIdQuery = new WildcardQuery(new Term(OutDoorIndexFields.Title, "*" + escapedSearchTerm + "*"));
foreach (var term in GetSearchTerms(searchFilter.SearchTerm))
{
var termQuery = queryParser.Parse(term);
conjuctionQuery.Add(termQuery, Occur.MUST);
disjunctionQuery.Add(termQuery, Occur.SHOULD);
foreach (var field in fields)
{
var wildCardTermQuery = new WildcardQuery(new Term(field, term + "*"));
wildCardTermQuery.Boost = 0.7f;
wildCardQuery.Add(wildCardTermQuery, Occur.SHOULD);
}
}
//关键查询
var keywordsQuery =
conjuctionQuery.Combine(new Query[] { exactIdQuery, wildCardIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery });
combineQuery.Add(keywordsQuery, Occur.MUST);
}
#endregion
#region 指定媒体ID查询
if (queryTerm.MediaID != 0)
{
var mediaIdQuery = new TermQuery(new Term(OutDoorIndexFields.ID, queryTerm.MediaID.ToString()));
combineQuery.Add(mediaIdQuery, Occur.MUST);
}
#endregion
#region 用户状态
var memberStatusQuery = NumericRangeQuery.NewIntRange(OutDoorIndexFields.MemberStatus, (int)MemberStatus.CompanyAuth, 99, true, true);
combineQuery.Add(memberStatusQuery, Occur.MUST);
#endregion
#region 审核状态查询构建
var verifyStatus = NumericRangeQuery.NewIntRange(OutDoorIndexFields.Status, (int)OutDoorStatus.ShowOnline, 99, true, true);
combineQuery.Add(verifyStatus, Occur.MUST);
#endregion
#region 指定用户ID查询
if (queryTerm.MemberID != 0)
{
var memberIdQuery = NumericRangeQuery.NewIntRange(OutDoorIndexFields.MemberID, queryTerm.MemberID, queryTerm.MemberID, true, true);
combineQuery.Add(memberIdQuery, Occur.MUST);
}
#endregion
#region 城市查询
if (queryTerm.City != 0)
{
var cityQuery = NumericRangeQuery.NewLongRange(OutDoorIndexFields.CityCateCode, queryTerm.CityCateCode, queryTerm.CityMaxCode, true, true);
combineQuery.Add(cityQuery, Occur.MUST);
}
#endregion
//.........这里部分代码省略.........
示例7: Search
public List<LinkItem> Search(GenerateSchemeViewModel model, out int totalHits)
{
if (!Directory.Exists(LuceneCommon.IndexOutDoorDirectory))
{
totalHits = 0;
return new List<LinkItem>();
}
var combineQuery = new BooleanQuery();
SortField sortField = GetSortField(model.generateType);
#region 用户状态
var memberStatusQuery = NumericRangeQuery.NewIntRange(OutDoorIndexFields.MemberStatus, (int)MemberStatus.CompanyAuth, 99, true, true);
combineQuery.Add(memberStatusQuery, Occur.MUST);
#endregion
#region 审核状态查询构建
var verifyStatus = NumericRangeQuery.NewIntRange(OutDoorIndexFields.Status, (int)OutDoorStatus.ShowOnline, 99, true, true);
combineQuery.Add(verifyStatus, Occur.MUST);
#endregion
#region 媒体类别查询
if (!string.IsNullOrEmpty(model.mediaCode))
{
var mediaCodes = model.mediaCode.Split(',').Select(x => Convert.ToInt32(x));
var mediaCodeCombineQuery = new BooleanQuery();
foreach (var code in mediaCodes)
{
var maxCode = Utilities.GetMaxCode(code);
var mediaCodeQuery = NumericRangeQuery.NewLongRange(OutDoorIndexFields.MediaCateCode,
code, maxCode, true, true);
mediaCodeCombineQuery.Add(mediaCodeQuery, Occur.SHOULD);
}
combineQuery.Add(mediaCodeCombineQuery, Occur.MUST);
}
#endregion
#region 媒体档期查询
if (!string.IsNullOrEmpty(model.dq))
{
var minValue = (DateTime.Now.AddYears(-10)).Ticks;
var maxValue = Convert.ToDateTime(model.dq).Ticks;
var DeadLineQuery = NumericRangeQuery.NewLongRange(OutDoorIndexFields.DeadLine,
Convert.ToInt64(minValue), Convert.ToInt64(maxValue), true, true);
combineQuery.Add(DeadLineQuery, Occur.MUST);
}
#endregion
#region 地区查询
if (!string.IsNullOrEmpty(model.cityCode))
{
var cityCodes = model.cityCode.Split(',').Select(x => Convert.ToInt32(x));
var cityCodeCombineQuery = new BooleanQuery();
foreach (var code in cityCodes)
{
var maxCode = Utilities.GetMaxCode(code);
var cityCodeQuery = NumericRangeQuery.NewLongRange(OutDoorIndexFields.CityCateCode,
code, maxCode, true, true);
cityCodeCombineQuery.Add(cityCodeQuery, Occur.SHOULD);
}
combineQuery.Add(cityCodeCombineQuery, Occur.MUST);
}
#endregion
#region 关键字查询
if (!string.IsNullOrEmpty(model.formatCate) || !string.IsNullOrEmpty(model.crowdCate) || !string.IsNullOrEmpty(model.industryCate) || !string.IsNullOrEmpty(model.purposeCate))
{
var fields = new[] {
OutDoorIndexFields.IndustryCate,
OutDoorIndexFields.CrowdCate,
OutDoorIndexFields.PurposeCate,
OutDoorIndexFields.FormatName
};
var keywords = (string.IsNullOrEmpty(model.formatCate) ? string.Empty : model.formatCate + ",")
+ (string.IsNullOrEmpty(model.crowdCate) ? string.Empty : model.crowdCate + ",")
+ (string.IsNullOrEmpty(model.industryCate) ? string.Empty : model.industryCate + ",")
+ (string.IsNullOrEmpty(model.purposeCate) ? string.Empty : model.purposeCate);
var analyzer = new PanGuAnalyzer();
//var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields, analyzer);
//conjuction 一起选择
var conjuctionQuery = new BooleanQuery();
conjuctionQuery.Boost = 2.0f;
//disjunction 分离
var disjunctionQuery = new BooleanQuery();
disjunctionQuery.Boost = 0.1f;
//wildCard 通配符
var wildCardQuery = new BooleanQuery();
wildCardQuery.Boost = 0.5f;
var escapedSearchTerm = Escape(keywords);
foreach (var term in GetSearchTerms(keywords))
{
var termQuery = queryParser.Parse(term);
conjuctionQuery.Add(termQuery, Occur.MUST);
disjunctionQuery.Add(termQuery, Occur.SHOULD);
//.........这里部分代码省略.........
示例8: ParseQuery
private static Query ParseQuery(SearchFilter searchFilter)
{
if (String.IsNullOrWhiteSpace(searchFilter.SearchTerm))
{
return new MatchAllDocsQuery();
}
var fields = new[] { "Title", "Description", "MediaCateName", "CityName" };
var analyzer = new ChineseAnalyzer();
//var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields, analyzer);
var query = queryParser.Parse(searchFilter.SearchTerm);
// All terms in the multi-term query appear in at least one of the fields.
var conjuctionQuery = new BooleanQuery();
conjuctionQuery.Boost = 2.0f;
// Some terms in the multi-term query appear in at least one of the fields.
var disjunctionQuery = new BooleanQuery();
disjunctionQuery.Boost = 0.1f;
// Suffix wildcard search e.g. jquer*
var wildCardQuery = new BooleanQuery();
wildCardQuery.Boost = 0.5f;
//// Escape the entire term we use for exact searches.
var escapedSearchTerm = Escape(searchFilter.SearchTerm);
var exactIdQuery = new TermQuery(new Term("Title", escapedSearchTerm));
exactIdQuery.Boost = 2.5f;
var wildCardIdQuery = new WildcardQuery(new Term("Title", "*" + escapedSearchTerm + "*"));
foreach (var term in GetSearchTerms(searchFilter.SearchTerm))
{
var termQuery = queryParser.Parse(term);
conjuctionQuery.Add(termQuery, Occur.MUST);
disjunctionQuery.Add(termQuery, Occur.SHOULD);
foreach (var field in fields)
{
var wildCardTermQuery = new WildcardQuery(new Term(field, term + "*"));
wildCardTermQuery.Boost = 0.7f;
wildCardQuery.Add(wildCardTermQuery, Occur.SHOULD);
}
}
//var combinedQuery =
// conjuctionQuery.Combine(new Query[] { exactIdQuery, conjuctionQuery });
//// Create an OR of all the queries that we have
var combinedQuery =
conjuctionQuery.Combine(new Query[] { exactIdQuery, wildCardIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery });
if (searchFilter.SortProperty == SortProperty.Hit)
{
// If searching by relevance, boost scores by download count.
var downloadCountBooster = new FieldScoreQuery("Hit", FieldScoreQuery.Type.INT);
return new CustomScoreQuery(combinedQuery, downloadCountBooster);
}
return combinedQuery;
}
示例9: ParseQuery
private static Query ParseQuery(ListSearchItemViewModel queryParams, SearchFilter searchFilter)
{
var combineQuery = new BooleanQuery();
#region 关键字查询构建
if (!String.IsNullOrWhiteSpace(searchFilter.SearchTerm))
{
var fields = new[] {
OutDoorIndexFields.Title,
OutDoorIndexFields.Description,
OutDoorIndexFields.AreaAtt,
OutDoorIndexFields.MediaCateName,
OutDoorIndexFields.CityName,
OutDoorIndexFields.ProvinceName,
OutDoorIndexFields.PMediaCateName,
OutDoorIndexFields.FormatName,
OutDoorIndexFields.PeriodName,
OutDoorIndexFields.OwnerCateName
};
var analyzer = new PanGuAnalyzer();
//var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields, analyzer);
var query = queryParser.Parse(searchFilter.SearchTerm);
var conjuctionQuery = new BooleanQuery();
conjuctionQuery.Boost = 2.0f;
var disjunctionQuery = new BooleanQuery();
disjunctionQuery.Boost = 0.1f;
var wildCardQuery = new BooleanQuery();
wildCardQuery.Boost = 0.5f;
var escapedSearchTerm = Escape(searchFilter.SearchTerm);
var exactIdQuery = new TermQuery(new Term(OutDoorIndexFields.Title, escapedSearchTerm));
exactIdQuery.Boost = 2.5f;
var wildCardIdQuery = new WildcardQuery(new Term(OutDoorIndexFields.Title, "*" + escapedSearchTerm + "*"));
foreach (var term in GetSearchTerms(searchFilter.SearchTerm))
{
var termQuery = queryParser.Parse(term);
conjuctionQuery.Add(termQuery, Occur.MUST);
disjunctionQuery.Add(termQuery, Occur.SHOULD);
foreach (var field in fields)
{
var wildCardTermQuery = new WildcardQuery(new Term(field, term + "*"));
wildCardTermQuery.Boost = 0.7f;
wildCardQuery.Add(wildCardTermQuery, Occur.SHOULD);
}
}
//关键查询
var keywordsQuery =
conjuctionQuery.Combine(new Query[] { exactIdQuery, wildCardIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery });
combineQuery.Add(keywordsQuery, Occur.MUST);
}
#endregion
#region 审核状态查询构建
var verifyStatus = NumericRangeQuery.NewIntRange(OutDoorIndexFields.Status, (int)OutDoorStatus.ShowOnline, 99, true, true);
combineQuery.Add(verifyStatus, Occur.MUST);
#endregion
#region 省份查询
if (!String.IsNullOrEmpty(queryParams.Province) && queryParams.Province != "quanguo")
{
int ProvinceValue = EnumHelper.GetProvinceValue(queryParams.Province);
var provinceQuery = NumericRangeQuery.NewIntRange(OutDoorIndexFields.Province, ProvinceValue, ProvinceValue, true, true);
combineQuery.Add(provinceQuery, Occur.MUST);
}
#endregion
#region 城市查询
if (queryParams.City != 0)
{
var cityQuery = NumericRangeQuery.NewIntRange(OutDoorIndexFields.City, queryParams.City, queryParams.City, true, true);
combineQuery.Add(cityQuery, Occur.MUST);
}
#endregion
#region 认证状态
if (queryParams.AuthStatus != 0)
{
var authStatusQuery = NumericRangeQuery.NewIntRange(OutDoorIndexFields.AuthStatus, queryParams.AuthStatus, queryParams.AuthStatus, true, true);
combineQuery.Add(authStatusQuery, Occur.MUST);
}
#endregion
#region 经纬度搜索
if (queryParams.MinX != 0)
{
var latQuery = NumericRangeQuery.NewDoubleRange(OutDoorIndexFields.Lat, queryParams.MinX, queryParams.MaxX, true, true);
var lngQuery = NumericRangeQuery.NewDoubleRange(OutDoorIndexFields.Lng, queryParams.MinY, queryParams.MaxY, true, true);
combineQuery.Add(latQuery, Occur.MUST);
combineQuery.Add(lngQuery, Occur.MUST);
//.........这里部分代码省略.........