Couchbase精确值匹配 [英] Couchbase exact value match

查看:81
本文介绍了Couchbase精确值匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Couchbase 5 Go Lang 1.11 ,试图根据确切值查询结果。



下面的代码正在查找状态为可用和不可用的行。我如何才能使其仅返回可用行?

  qp.And(cbft.NewConjunctionQuery(cbft.NewMatchQuery( Available ).Field( status)))


解决方案

这将取决于您如何分析输入字段,这将有助于了解您使用的是哪种分析仪,但现在我假设使用默认的标准分析仪。



在这种情况下,请不要使用默认的分析器。正如Matt在评论中所问的那样,您正在尝试对短语中的确切文本进行直接匹配,这与大多数文本搜索用户略有不同。因此,您实际上并不希望将文本标记为更小的片段。



使用Couchbase搜索GUI创建一个使用单个


I am using Couchbase 5 and Go Lang 1.11, trying to query results based on an exact value.

The code below is finding rows with a status of "Available" and "Not Available". How can I make it only return "Available" rows?

qp.And(cbft.NewConjunctionQuery( cbft.NewMatchQuery("Available").Field("status") ))

解决方案

It will depend on how you analyze the input field, it would help to know what analyzer you are using, but I'll assume the default, "standard", analyzer for now.

Don't use the default analyzer for this case. As Matt asked in his comment, you are trying to do a direct match of exact text in a phrase, which is a little different than most text search users. So you don't really want the text to be tokenized into smaller pieces.

Create a custom analyzer with the Couchbase search GUI that uses the "single" tokenizer so that all the text in the field will be kept together. Or you could just use the "keyword" analyzer which is probably close enough for you. Set that as your default analyzer and your query should work as expected.

If you are looking for another approach, then a term or term phrase query may be more what you are after, but you'll still have to be conscious of how analyzers are working.

这篇关于Couchbase精确值匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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