简体   繁体   English

从天蓝色搜索返回仅与确切搜索词匹配的记录

[英]Return records from azure search that match the exact search term only

So I'm new to Azure search and I'm only starting to figure it out. 因此,我是Azure搜索的新手,我才刚刚开始了解它。 I have a search index that queries a pretty simple sql view for matching records. 我有一个搜索索引,用于查询一个非常简单的sql视图以查找匹配的记录。 I'm having major trouble getting an exact match for the word I search for. 我很难找到与我搜索的单词完全匹配的单词。

Whenever I search I get records with the exact word only.. however I also get records that contain the searched for word eg I search for "Type" and I get "New Type" and "My Type". 每当我搜索时,我都会得到仅包含确切单词的记录。.但是,我也会获得包含所搜索单词的记录,例如,我搜索“类型”,然后得到“新类型”和“我的类型”。 I'm enclosing "Type" in double quotes when I search. 我在搜索时将“类型”括在双引号中。

I'm using the C# SDK, and it also happens when I execute a search via Postman: 我使用的是C#SDK,通过Postman执行搜索时也会发生这种情况:

https://myapp.search.windows.net/indexes/myindex/docs?$select=AlertDate,DocumentName,City,DocumentType&search=(DocumentType:"Type")&$count=true&queryType=full&searchMode=any&api-version=2016-09-01

Any idea what might cause this and how I can get exact matches only? 知道是什么原因会导致这种情况,以及如何仅获得完全匹配? I've read a fair bit on it and several posts and web pages say that wrapping the search term in double quotes will get the exact term only, but this doesn't seem to be correct at least not for me. 我已经阅读了相当多的文章,一些帖子和网页都说,将搜索词用双引号引起来只会得到确切的词,但这似乎并不正确,至少对我来说不是。

Edit: 编辑:

For completeness I should add the call that I'm using in C# to retrieve the results: 为了完整起见,我应该添加在C#中使用的调用以检索结果:

var result = await indexClient.Documents.SearchAsync(query, new SearchParameters()   
{ Facets = parameters.Facets, QueryType = QueryType.Full, SearchMode = SearchMode.Any,   
Top = request.Top, Skip = request.Skip, IncludeTotalResultCount = true });

Sometimes the search would be just a single word or multiple words, other times it could be filters that a user would select from drop downs such as Country and City, or a combination of both. 有时,搜索可能只是一个单词或多个单词,而有时可能是用户从下拉菜单中选择的过滤器,例如“国家/地区”和“城市”,或两者结合。 I then form the query string like this: 然后,我形成如下查询字符串:

(Country:"France" OR "Germany") AND (City:"Paris")

If it also includes a search term the query would look like this: 如果它还包含搜索词,则查询将如下所示:

"Type" AND (Country:"Italy" OR "France") AND (City:"Paris" OR "Rome")

Enclosing a query in double quotes turns it into a phrase query. 用双引号引起来的查询会将其转换为短语查询。 This is only meaningful if there is more than one term between the quotes, separated by whitespace, punctuation etc. For example, if your search string is Hello world , it will match documents that contain "hello" or "world" (if you're using the default searchMode of any and assuming you don't use any other operators explicitly), but if your search string is "Hello world" , then documents only match if the two terms are adjacent to each other. 仅当引号之间包含多个术语,并用空格,标点符号等隔开时,这才有意义。例如,如果您的搜索字符串是Hello world ,它将匹配包含“ hello”或“ world”的文档(如果您使用重新使用默认的searchModeany假设你不使用任何其他运营商明确),但如果你的搜索字符串是"Hello world" ,然后文件只有在两个条件是彼此相邻的匹配。

Looking at your query, I'm guessing you want to filter by categorical data. 查看您的查询,我猜您想按分类数据进行过滤。 If you truly want an exact match (case-sensitive), then you should use $filter instead of search: 如果您确实需要完全匹配(区分大小写),则应使用$ filter而不是search:

https://myapp.search.windows.net/indexes/myindex/docs?$select=AlertDate,DocumentName,City,DocumentType&$filter=DocumentType eq 'Type'&$count=true&queryType=full&searchMode=any&api-version=2016-09-01

Here are a few useful links for constructing filter and search queries in Azure Search: 以下是在Azure搜索中构造过滤器和搜索查询的一些有用链接:

https://docs.microsoft.com/rest/api/searchservice/lucene-query-syntax-in-azure-search https://docs.microsoft.com/rest/api/searchservice/odata-expression-syntax-for-azure-search https://docs.microsoft.com/rest/api/searchservice/lucene-query-syntax-in-azure-search https://docs.microsoft.com/rest/api/searchservice/odata-expression-syntax-for -azure搜索

why dont you try the OData filter if you want to perform exact match? 如果要执行完全匹配,为什么不尝试OData过滤器? In this case your query will become $filter=DocumentType eq 'Type' 在这种情况下,您的查询将变为$ filter = DocumentType eq'Type'

Note that if you you the preview version of azure search, api-version=2015-02-28-Preview, they have added new filters for partial matching. 请注意,如果您是Azure搜索的预览版本api-version = 2015-02-28-Preview,则它们已添加了用于部分匹配的新过滤器。

search.ismatch("filedvalue", "fieddname") and saerch.ismatchscoring() search.ismatch(“ filedvalue”,“ fieddname”)和saerch.ismatchscoring()

Also, did you checked the Custom Analyzer? 另外,您是否检查了自定义分析器? If you know that you will be always performing exact match on few fields then use "keyword" analyzer with lowercase tokeniser 如果您知道您将始终在少数几个字段上执行完全匹配,请使用带有小写标记符的“关键字”分析器

https://docs.microsoft.com/en-us/rest/api/searchservice/custom-analyzers-in-azure-search https://docs.microsoft.com/en-us/rest/api/searchservice/custom-analyzers-in-azure-search

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM