3
votes

I'm using MarkLogic v8.

I am trying to apply a container constraint on a structured query to return only documents with value x in element c (nested within elements a and b).

queryBuilder.containerConstraint() takes a parameter for an option name and a StructuredQueryDefinition. My option looks like this:

<options xmlns='http://marklogic.com/appservices/search'>
    <constraint name='language'>
        <element name=\"name\" ns=\"\"/>
    </constraint>
</options>
  1. "name" is the name of the innermost element (c) containing the value I want to reference against. Is this how the option should be constructed, or should 'name' instead be the name of the outermost element?

  2. How should the StructuredQueryDefinition (that is accepted as a parameter by containerConstraint()) be constructed? Should I be writing raw XML, or are there contruction methods to be passed in?

  3. Is there a better way to do this? I already have a working Term search, I just need to be able to filter by a property set inside the document.

1

1 Answers

3
votes

I think I found an answer:

Option was as follows:

<search:options 
        xmlns:search='http://marklogic.com/appservices/search'>
    <search:constraint name='language'>
        <search:word>
            <search:element name='name' ns=''/>
        </search:word>
    </search:constraint>
</search:options>

Then called the option in a Word Constraint:

queryBuilder.wordConstraint("language", MY_LANGUAGE)

This appears to do what I wanted it to.