Marklogic 8 xml search

核能气质少年 提交于 2019-12-23 20:57:12

问题


Suppose I have a xml as below:

<xx>
    <yy>
        <name>A</name>
        <value>1</value>
    </yy>

    <yy>
        <name>A</name>
        <value>2</value>
    </yy>

    <yy>
        <name>B</name>
        <value>1</value>
    </yy>
</xx>

Now I want to find if any 'yy' is present with name as A and value as 1. So here the matching content would be:

<yy>
    <name>A</name>
    <value>1</value>
</yy>

I am trying to do this by REST call,qbe GET request but not able to do it. Can some one help me out using:

/v1/qbe
or
/v1/search

回答1:


With the /v1/search API you'll need to use custom search options to achieve this.

To upload custom search options to MarkLogic: http://developer.marklogic.com/learn/rest/custom-search#search-using-an-element-value-constraint

Your search options will define constraints for your search based on the indexes you created. Your search options should look like this:

<options xmlns="http://marklogic.com/appservices/search">
  <constraint name="yy">
    <element-query name="yy" ns="" />
  </constraint>
  <constraint name="name">
    <value>
      <element ns="" name="name"/>
    </value>
  </constraint>
  <constraint name="value">
    <value>
      <element ns="" name="value"/>
    </value>
  </constraint>
</options>

Let's say you upload these options as "mySearchOptions".

Finally, you can make this GET request to get the search results you want:

http://localhost:REST_SERVER_PORT/v1/search?q=yy%3A(name%3Aa%20AND%20value%3A1)&options=mySearchOptions




回答2:


Can you show the QBE you're sending?

You should be able to set the query parameter to

<yy><name>A</name><value>1</value></yy> 

with appropriate escaping, as in:

.../v1/qbe?query=%3Cyy%3E%3Cname%3EA%3C/name%3E%3Cvalue%3E1%3C/value%3E%3C/yy%3E

Because of the URL escaping issue, it's often easier to POST a QBE from an edited file.

By the way, if the goal is to bring back matching documents, there shouldn't be any reason to set up range indexes. The universal index matches documents.

Range indexes are useful for doing relational comparisons (such as <), sorting, or extracting value lists or tuples from large numbers of documents.



来源:https://stackoverflow.com/questions/30729537/marklogic-8-xml-search

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