我想搜索所有具有「Sample」作爲元素「tagname」的屬性「attr」和值「attr」的值的MarkLogic文檔Java API想要搜索具有特定值的標記的所有marklogic文檔
<tagname attr="attr">Sample</tagname>
我想搜索所有具有「Sample」作爲元素「tagname」的屬性「attr」和值「attr」的值的MarkLogic文檔Java API想要搜索具有特定值的標記的所有marklogic文檔
<tagname attr="attr">Sample</tagname>
你在找什麼是cts:element-attribute-value-query
。
你會想把它包裝在cts:search
並限制它。取決於你想要什麼,如果你關心元素和屬性的值,你可能需要「和」元素值查詢。
如果你打算做在MarkLogic查詢了很多,你可能想看看在https://docs.marklogic.com/guide/search-dev
用Java API的搜索開發人員指南,你可以使用一個containerQuery()
匹配包含的元素中的子「標記名」,然後使用and()
,value()
約束條件爲ElementAttribute
,tagname/@attr="attr"
,另一個value()
約束條件爲Element
tagname
,值爲「Sample」。
// create the client
DatabaseClient client =
DatabaseClientFactory.newClient(host, port, user, password, authType);
// create a manager for searching
QueryManager queryMgr = client.newQueryManager();
// create a query builder
StructuredQueryBuilder qb = new StructuredQueryBuilder();
// build a search definition
StructuredQueryDefinition query =
qb.containerQuery(
qb.element("tagname"),
qb.and(
qb.value(
qb.elementAttribute(
qb.element("tagname"),
qb.attribute("attr")
),
"attr"),
qb.value(
qb.element("tagname"),
"Sample"
)
)
);
// run the search
queryMgr.search(query, resultsHandle);
'tag'是什麼?它是一個元素嗎?請給出您的內容的示例示例,以便全面瞭解問題。 –
@DavidEnnis添加了我正在談論的標籤 – CrazyNerd