2
votes

I'm looking for an example on how to do a Path Range Index Query using the MarkLogic Java API.

/doc1.xml

<a>
  <b>
    <c>1234</c>
      <d>
        <c>abcd</c>
      </d>
  </b>
</a>

/doc2.xml

<a>
  <b>
    <c>abcd</c>
      <d>
        <c>abcd</c>
      </d>
  </b>
</a>

A path range index was created having this path expression with no path namespace:

/a/b/c

Is this the proper way to invoke a path range index query using the MarkLogic Java API?

QueryManager queryMgr = client.newQueryManager();

StructuredQueryBuilder qb = new StructuredQueryBuilder(OPTIONS_NAME);

StructuredQueryDefinition querydef = qb.PathIndex("/a/b/c", "abcd")

SearchHandle results = queryMgr.search(querydef, new SearchHandle());
1

1 Answers

3
votes

You're very close. Just change your second to last line to this:

StructuredQueryDefinition querydef =
    qb.range(qb.pathIndex("/a/b/c"), "string", Operator.EQ, "abcd");

You don't yet need any options from anything you've described, so you could remove OPTIONS_NAME until you have a reason to specify search options. Also, make sure your path range index has the default collation or else specify the correct collation to your range method call.