我正在使用 Couchbase 5 </ strong>和 Go Lang 1.11 </ strong>, </ p>

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

  qp.And(cbft.NewConjunctionQuery(cbft.NewMatchQuery(“ Available”)。Field(“ status”)))  )
</ code> </ pre>
</ div>



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

dpy83214 一个简单的示例是:SELECTd。*FROMmyDocumentsdWHEREstatus='Available'
接近 2 年之前 回复
dongxie8856 有什么例子吗?
接近 2 年之前 回复
doujiang1939 如果您要进行完全匹配,为什么不使用N1QL查询呢?
接近 2 年之前 回复


这取决于您对输入字段的分析方式,这将有助于您了解所使用的分析器,但是我假设 默认为“标准”分析器。</ p>

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

使用Couchbase搜索GUI创建一个使用“单个” tokenizer ,以便将字段中的所有文本保存在一起。 或者,您可以使用可能足够接近您的“关键字”分析器</ strong>。 将其设置为默认分析器,并且查询应能按预期工作。</ p>

如果您正在寻找其他方法,请使用字词或字词短语查询可能更多,但您仍然可以 意识到分析仪的工作方式。</ p>

“将Couchbase全文搜索分析器的默认分析器设置为使用“关键字”' </ p>
< / DIV>



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.

Set default analyzer for Couchbase full-text search analyzer to use "keyword"

Csdn user default icon