Azure搜索:如何获取完全包含搜索词的文档 [英] Azure-search: How to get documents which exactly contain search term

查看:97
本文介绍了Azure搜索:如何获取完全包含搜索词的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题/答案涉及一个非常相似的主题,但是我找不到正在寻找的解决方案. 如何在天蓝色搜索中实际使用关键字分析器?

This question/answer dealt with a pretty similar topic, but I couldn't find the solution I was searching for. How to practially use a keywordanalyzer in azure-search?

开始情况:

我创建了具有多个索引的资源.这些索引之一包含一个Collection(Edm.String)字段. 从此字段中,我只想获取完全包含搜索词的文档.例如,该字段包含以下文件:气垫船零",气垫船一",气垫船二".

I created a resource with multiple indexes. One of these indexes contains a Collection(Edm.String) field. From this field i only want to get documents which exactly contain the search term. For example the field contains documents like these: "Hovercraft zero", "Hovercraft one", "Hovercraft two".

如果搜索词为悬停",则应返回所有三个文档.如果搜索词为"craft zer",则仅返回文档气垫船零".该文档不应获得更高的分数,理想的行为是我只得到气垫船零"文档.

If the search term is "Hover" all three documents should be returned. If the search term is "craft zer" only the document "Hovercraft zero" should be returned. The document shouldn't get a higher score, the desired behaviour is that I only get the "Hovercraft zero" document as result.

更多信息:

不可能将搜索模式设置为全部(就像在上面的问题中建议的那样),因为我只想为此特定字段而不是所有搜索查询设置此行为.也不应该让用户负责输入带引号的搜索字词.

It is not possible to set the searchmode to all (like it was recommended in the question on the top) because I just want to set this behaviour for this specific field and not for all search queries. It also is not possible to let the responsibility on the user to enter the search term with quotes.

到目前为止我尝试过的事情:

What I have tried so far:

  • 使用类似问题中所述的关键字分析器 页首:没有成功
  • 使用带有特定令牌过滤器(ngram, 小写)和一个搜索分析器作为关键字分析器:没有成功
  • 使用Charfilters操纵搜索词并手动设置 第一个和最后一个位置的引号(craft zer->"craft zer"). 就像Yahnoosh在上面的问题中解释的那样,查询解析器 在应用分析器之前处理查询字符串.所以: 没有成功
  • Use the keyword analyzer like it was described in the question on top: no success
  • Use an indexanalyzer with specific token filters (ngram, lowercase) and a searchanalyzer as a keyword analyzer: no success
  • Use Charfilters to manipulate the search term and manually set the quotes on the first and last position (craft zer -> "craft zer"). Like Yahnoosh explained in the question on top, the query parser processes the query string before the analyzers are applied. So: no success

这个问题有解决方案吗? 还是有其他方法可以实现所需的行为?

Is there any solution for this issue? Or is there a other approach to achieve the desired behaviour?

希望有人可以提供帮助.

Hopefully someone can help.

提前谢谢!

推荐答案

感谢@Yahnoosh的回答,我找到了一个对我有用的解决方案.

Thanks @Yahnoosh for your answer, I found a solution that worked for me.

简短示例: 我有一个包含三个字段(field1,field2,field3)的索引.从field3,我想要一个结果,其中文档正好包含搜索词.我想从field1和field2获得标准"结果.

Short example: I have an index including three fields (field1, field2, field3). From field3 I want a result where documents exactly contain the search term. From field1 and field2 I want do get a "standard" result.

解决方案: 我将searchquery操纵为->

Solution: I manipulated the searchquery to ->

field1:{searchterm} || field2:{searchterm} || field3:"{searchterm}"& queryType = full

field1:{searchterm} || field2:{searchterm} || field3:"{searchterm}" &queryType=full

使用此搜索查询以标准"方式查询field1和field2,并以我正在搜索的行为查询field3.当然,有更有效,更优雅的方法可以解决此问题,但这对我有用.

Using this searchquery field1 and field2 are queried in the "standard" way and field3 is queried with the behaviour i was searching for. Of course there are more efficient and elegant ways out there to solve this issue, but it worked for me.

如果有人有更好的解决方案,请告诉我;)

If anybody has a better solution let me know ;)

这篇关于Azure搜索:如何获取完全包含搜索词的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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