The QueryRequest object has several properties that point to components of class atg.search.routing.command.search.DocumentSetConstraint (or one of its subclasses). These components represent query constraints, which are encoded as XML in the search request. The XML can be quite complex , often with many levels of nested tags.

For example, suppose you want to specify the following constraint through the QueryRequest.documentSetConstraints property:

<and>
  <strprop op="equal" name="childSKU.color">
    rose
  </strprop>
  <numprop op="lesseq" name="childSKU.price">
    30.00
  </numprop>
</and>

This constraint limits search results to products whose childSKU.color property has a value of rose and whose childSKU.price property has a value less than or equal to 30.00. (These properties may have multiple values, since products can have multiple SKUs, but as long as one of the values of childSKU.color is rose and one of the values of childSKU.price is less than or equal to 30.00, the constraint is satisfied.)

To specify this constraint, you could create a component of class atg.search.routing.command.search.XmlDocumentSetConstraint and set its xmlConstraint property to:

<and>\
  <strprop op="equal" name="childSKU.color">\
     rose\
  </strprop>\
  <numprop op="lesseq" name="childSKU.price">\
     30.00\
  </numprop>\
</and>

Then set QueryRequest.documentSetConstraints to this component. For example.:

documentSetConstraints=/MyStuff/MyConstraints
Assembling the Constraint using Components

Specifying the XML directly is useful for initializing constraints, but it is not very flexible, because it doesn’t allow you to modify the XML dynamically in JSPs. Therefore, the Oracle ATG Web Commerce platform also includes a number of subclasses of DocumentSetConstraint that allow you to specify elements of the XML as individual properties. When a query is issued, these constraint classes take care of constructing the XML and including it in the input sent to Oracle ATG Web Commerce Search.

To construct the constraint shown above, you’d create components of the DocumentSetConstraint subclasses StringConstraint, NumericConstraint, and ConstraintsGroup, from the atg.search.routing.command.search package.

To specify the first part of the constraint, create a StringConstraint component named /MyStuff/MyStringConstraint and set these properties:

property=childSKU.color
operation=equal
value=rose

To specify the second part, create a NumericConstraint component named /MyStuff/MyNumericConstraint and set these properties:

property=childSKU.price
operation=lesseq
value1=30

Now combine the two parts by creating a ConstraintsGroup component named MyConstraintsGroup and setting these properties:

operation=and
constraints=/MyStuff/MyStringConstraint,/MyStuff/MyNumericConstraint

Set the QueryRequest.documentSetConstraints property to MyConstraintsGroup:

documentSetConstraints=/MyStuff/MyConstraintsGroup

This approach makes it possible to modify the constraints dynamically in JSPs. For example:

<dsp:select bean="/MyStuff/MyStringConstraint.value">
  <dsp:option value="rose">rose</dsp:option>
  <dsp:option value="mauve">mauve</dsp:option>
  <dsp:option value="gray">gray</dsp:option>
  <dsp:option value="purple">purple</dsp:option>
  <dsp:option value="cobalt">cobalt</dsp:option>
</dsp:select>