我正在尝试使用check fluent api编写脚本。
我有条件需要履行
我只能匹配以此字符串开头的单词。
当我执行下面的代码时,我只会得到以searchTerm
开头的单词 public IEnumerable<SearchResultItem> Search(string searchTerm)
{
//Create search Criteria
var sc = ExamineManager.Instance.CreateSearchCriteria();
//define query
var query = sc.NodeName(searchTerm.MultipleCharacterWildcard())
.Or()
.Field("content", searchTerm.MultipleCharacterWildcard())
.Compile();
var results = ExamineManager.Instance.SearchProviderCollection["ContentSearcher"].Search(query);
return results.OrderBy(x => x.Score).Select(MapSearchResults);
}
如何针对所有条件更新搜索脚本?
答案 0 :(得分:1)
原始查询解决方案。 这应该悬停 搜索必须找到以searchTerm开头的节点 搜索必须找到包含searchTerm的节点 搜索必须找到以searchTerm结尾的节点 搜索必须支持多个单词
var searchTerm = Request["term"].Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
var searchCriteria = searcher.CreateSearchCriteria();
var luceneString = new System.Text.StringBuilder();
luceneString.Append("nodeTypeAlias:");
luceneString.Append("*");
for (int i = 0; i < searchTerm.Length; i++)
{
luceneString.Append(" AND ");
luceneString.Append("title:");
luceneString.Append("*");
luceneString.Append(searchTerm[i]);
luceneString.Append("*");
}
var query = searchCriteria.RawQuery(luceneString.ToString());
var searchResults = searcher.Search(query);
这篇文章帮助了我http://www.lucenetutorial.com/lucene-query-syntax.html