Couchbase exact value match

限于喜欢 提交于 2019-12-08 10:19:09

问题


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") ))

回答1:


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.



来源:https://stackoverflow.com/questions/52610544/couchbase-exact-value-match

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!