【发布时间】:2017-11-10 04:13:16
【问题描述】:
我正在尝试使用通配符表达式构建 lucene 全文搜索以表示“包含”/*.<Keyword>/*,但在 Azure 搜索库提供的 Buildparameter 模型中没有搜索属性。
我正在使用
Documents.Search<T>(searchTerm, searchParam);
//where SearchTerm is the <typed key search> for ex "Nurs" and the result
//should be where all or any text contains "Nurs"
我用来构建的 Azure.Search.Models SearchParameter 是我扩展以创建新类以包含搜索字段的位置。
return new ExtentedSearchParameter
{
IncludeTotalResultCount = true,
SearchFields = new List<string>() {"FilterableTitle", "FilterableAlternativeTitle"},
Skip = (properties.Page - 1) * properties.Count,
Top = properties.Count,
Search=properties.SearchQuery,
QueryType = QueryType.Full ,
Select=new List<string>(){"FilterableTitle", "FilterableAlternativeTitle"},
OrderBy = properties.OrderByFields,
};
在我的应用程序中,我正在构建这样的查询
if (string.IsNullOrWhiteSpace(returnProperties.FilterBy))
{
returnProperties.SearchQuery =$"FilterableTitle: /.*'{cleanSearchTerm.TrimStart('\"').TrimEnd('\"')}.*/' and FilterableAlternativeTitle:/.*'{cleanSearchTerm.TrimStart('\"').TrimEnd('\"')}.*/'";
}
当我传递搜索参数和搜索词时,它不返回结果并引发异常。
【问题讨论】:
-
为什么要扩展 SearchParameters 类?这不应该是必要的。
-
我想用任何 / 包含关键字进行全文搜索。我想用 * .*/> 创建一个搜索查询
-
尝试将 Lucene 查询作为 searchText 参数传递给 Search 方法,而不是扩展 SearchParameters 类。如果这不起作用,请编辑您的问题以提供更多详细信息,例如您收到的具体错误消息。如果它确实有效,请告诉我,我会写下这条评论作为答案。
-
嗨布鲁斯,谢谢。有效。我删除了过滤器并在搜索方法中传递了 lucene 搜索查询。干杯队友:)
-
乐于助人。 :) 请接受下面的答案。
标签: azure azure-cognitive-search