Query Structure

Each term has a field called occurs. How this is set determines the structure of the query - whether all the search terms must exist, only one, or some other combination. The possible values for occurs are MUST, SHOULD, MUST_NOT, and MUST_FIELD.

If MUST is specified for the occurs attribute for set of terms then a result will be returned only if all of the terms are found. If SHOULD is specified for a set of terms then a result will be returned if one or more of the terms are found. However, mixing these in a single query will give an undefined result and should be avoided. If you need to construct complex queries with AND and OR sub-queries then you must use the text query attribute described in Text.

If MUST_NOT is specified for the occurs attribute then only documents that do not match the term will be returned. Terms specifying this value may be mixed with terms specifying other values for the occurs attribute.

Using the MUST_FIELD option allows you to construct a subquery testing a particular index field for one of a set of values, i.e. an OR subquery within your main query. You should set this as the occurs value for all the terms dealing with that field and add a term for each acceptable value. Terms using MUST_FIELD can be part of an overall query using either the MUST or SHOULD term options.