Azure搜索和短划线 [英] Azure Search and Dashes

查看:71
本文介绍了Azure搜索和短划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Azure搜索并尝试对文档执行搜索:

I am using Azure Search and trying to perform a search against documents:

似乎正在这样做:/indexes/blah/docs?api-version=2015-02-28&search=abc\-1003

返回与此相同的结果:/indexes/blah/docs?api-version=2015-02-28&search=abc-1003

returns the same results as this: /indexes/blah/docs?api-version=2015-02-28&search=abc-1003

由于转义了反斜杠,第一个返回的结果应该与第二个返回的结果不同吗?据我了解,反斜杠应该允许对整个字符串"abc-1003"进行精确搜索,而不是执行"not"运算符.

Shouldn't the first one return different results than the second due to the escaping backwards slash? From what I understand the backwards slash should allow for an exact search on the whole string of "abc-1003" instead of doing a "not" operator.

(此处提供更多信息: https://msdn.microsoft.com/en-us/library/azure/dn798920.aspx )

(more info here: https://msdn.microsoft.com/en-us/library/azure/dn798920.aspx)

我要使其正常工作的唯一方法是执行此操作(请注意双引号):/indexes/blah/docs?api-version=2015-02-28&search="abc-1003"

The only way I can get it to work is by doing this (note the double quotes): /indexes/blah/docs?api-version=2015-02-28&search="abc-1003"

我不想这样做,因为那将意味着让用户输入引号,而他们不知道该怎么做.

I would rather not do that because that would mean making the user enter in the quotes, which they will not know how to do.

我是否应该避免某些事情,或者它可能是Azure搜索的错误?

Am I expecting something I shouldn't or is it possibly a bug with Azure Search?

推荐答案

首先,没有空格开头的破折号的作用就像破折号,而不是取反运算符.

First, a dash not prefaced by a whitespace acts like a dash, not a negation operator.

按照MSDN文档中的简单查询语法

As per the MSDN docs for simple query syntax

- Only needs to be escaped if it's the first character after whitespace, not if it's in the middle of a term. For example, "wi-fi" is a single term


第二,除非您使用的是自定义分析器对于您的索引,破折号将被分析器对待,就像空白一样,并且会将abc-1003分解为两个记号abc1003.


Second, unless you are using a custom analyzer for your index, the dash will be treated by the analyzer almost like white-space and will break abc-1003 into two tokens, abc and 1003.

然后,将其放在引号中"abc-1003",将被视为对短语abc 1003的搜索,从而返回您期望的结果.

Then when you put it in quotes"abc-1003" it will be treated as a search for the phrase abc 1003, thus returning what you expect.

如果要精确匹配abc-1003,请考虑使用过滤器.它速度更快,可以匹配guid或带有破折号的文本

If you want to exact match on abc-1003 consider using a filter instead. It is faster and can matching things like guids or text with dashes

这篇关于Azure搜索和短划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆