2017-04-15 55 views
1

我想搜索所有具有「Sample」作爲元素「tagname」的屬性「attr」和值「attr」的值的MarkLogic文檔Java API想要搜索具有特定值的標記的所有marklogic文檔

<tagname attr="attr">Sample</tagname> 
+0

'tag'是什麼?它是一個元素嗎?請給出您的內容的示例示例,以便全面瞭解問題。 –

+0

@DavidEnnis添加了我正在談論的標籤 – CrazyNerd

回答

3

用Java API的搜索開發人員指南,你可以使用一個containerQuery()匹配包含的元素中的子「標記名」,然後使用and()value()約束條件爲ElementAttributetagname/@attr="attr",另一個value()約束條件爲Elementtagname,值爲「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); 
相關問題