MarkLogic Java:在StringQueryDefinition中将查询类型设置为Value [英] MarkLogic Java: Set Query Type to Value in StringQueryDefinition

查看:81
本文介绍了MarkLogic Java:在StringQueryDefinition中将查询类型设置为Value的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MarkLogic Java API.我正在寻找一种设置StringQueryDefinition的查询类型的方法.类型应为值",如以下所述: https://docs. marklogic.com/guide/search-dev/searchdev#id_34905 .

I'm using the MarkLogic Java API. I'm looking for a way to set the Query Type of a StringQueryDefinition. The type should be "Value", as described in: https://docs.marklogic.com/guide/search-dev/searchdev#id_34905.

值:匹配特定JSON属性或XML元素中的整个文字值,例如字符串或数字.默认情况下,值查询使用完全匹配语义.例如,搜索标记"将不匹配标记吐温".

Value: Match an entire literal value, such as a string or number, in a specific JSON property or XML element. By default, value queries use exact match semantics. For example, a search for 'mark' will not match 'Mark Twain'.

我需要这个,因为我希望我的文本搜索只匹配确切的搜索词.

I need this because I want my text searches to match only the exact search terms.

示例:对标记"的搜索应仅与在某些键上包含恰好包含标记"一词的文档相匹配.因此,{"anExample1": {"key1": "mark", "key2":"someotheralue"}}是有效的匹配项.但是{"anExample2": {"key1": "mark twain", "key2":"someotheralue"}}不是有效的匹配项.

Example: the search for 'mark' should ONLY match with documents containing exactly the term 'mark' attached to some key. So, {"anExample1": {"key1": "mark", "key2":"someotheralue"}} is a valid match. But {"anExample2": {"key1": "mark twain", "key2":"someotheralue"}} is not a valid match.

对于这两个示例,我想获取返回的文档中的URI和位置.因此,对"mark"的搜索应返回uri/anExample1anExample1/key1.

For both examples, I'd like to get the URI and location within the document returned. Hence, the search for "mark" should return uri/anExample1 and anExample1/key1.

推荐答案

要搜索"key1" ="mark",您需要执行以下操作:

To search for "key1" = "mark" you'd do the following:

StructuredQueryBuilder sqb = new StructuredQueryBuilder();
QueryDefinition query = sqb.value(sqb.element("key1"), "mark");
SearchHandle results = queryMgr.search(query, new SearchHandle());

从结果中您可以获取uri:

From the results you can get the uri:

results.getMatchResults()[i].getUri()

以及比赛地点:

results.getMatchResults()[i].getMatchLocations()[j].getPath()

这篇关于MarkLogic Java:在StringQueryDefinition中将查询类型设置为Value的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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