4

Is there any way to create a custom constraint where the right part can include complex logic? i.e.

name:(phil OR tom)

In my function, when I get the $right side, the whole value has been reduced to a simple concatenated string of all of the text, i.e.

<cts:word-query xmlns:cts="http://marklogic.com/cts">
  <cts:text>phil tom</cts:text>
</cts:word-query>

What I am looking to do is to take a parsed query and then add my own additions to the parsed query. So I was hoping that there was some way to get the $right parameter to be something like

<cts:or-query xmlns:cts="http://marklogic.com/cts">
  <cts:word-query>
    <cts:text>phil</cts:text>
  </cts:word-query>
  <cts:word-query>
    <cts:text>tom</cts:text>
  </cts:word-query>
</cts:or-query>

I want to take the output results of the query and expand with another query to get the real results. i.e. I have a name constraint which restricts search to various name fields. After finding the matching people, I want to turn the results into a hierarchy of people from the matching people, maybe 2 levels down. This does not seem to make sense as a transform result or a custom constraint. Would this just be a custom REST endpoint? I was hoping to make use of the paging already built into the standard search endpoint.

TJ Tang
  • 921
  • 6
  • 17

1 Answers1

5

A few thoughts come to mind.At present you best write that as:

name:phil OR name:tom

Apart from that, the cts:parse function provides more complex support, than the search:parse with which the REST api is running now.

When using custom constraints, and you have control over how it is being sent to the REST api, consider sending it as a custom-constraint-query in a structuredQuery. That allows you sending it unparsed, and doing parsing inside your constraint.

HTH!

grtjn
  • 20,254
  • 1
  • 24
  • 35
  • Thanks. I ended up creating a custom resource REST endpoint, and that allowed me to do what I needed to do. – TJ Tang Jun 10 '16 at 02:03