Marklogic 8 xml search

Suppose I have xml like 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 the name A and value as 1. So the relevant content would be:

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

      

I am trying to do this on a REST call , qbe GET , but am unable to do so. Can someone help me using:

/v1/qbe
or
/v1/search

      

+3


source to share


2 answers


With the / v 1 / search API, you will need to use special search parameters for this.

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

The search parameters will determine the limits for your search based on the indexes you create. Your search parameters 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 load 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

+3


source


Can you show the QBE you are sending?

You have to set the request parameter

<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

      

Due to a URL escaping issue, it is often easier to POST a QBE from an edited file.

By the way, if the goal is to return matching documents, there should be no reason to set range indices. Generic index matches documents.

Range indexes are useful for performing relational comparisons (such as <), sorting, or extracting lists of values ​​or tuples from a large number of documents.

+2


source







All Articles