[ You are here: XTF -> Tag Reference -> crossQuery -> Query Parser Output Tags -> Phrase Search Tag ]

Phrase Search Tag

This tag specifies a phrase for which to search. This tag has the form:
<phrase {field       = "FieldName"}
        {maxSnippets = "SnippetsToOutput"}
        {boost       = "BoostValue"}>
 
    Term | Clause
    Term | Clause
      …
 
    {OptionalSectionTypeQuery}
 
</phrase>
where
field="FieldName" is an optional attribute that identifies which field in the index to search. Often this attribute is set to text to indicate that the main text of the document should be searched. It can also be set to the name of a meta field such as author or subject. It should be mentioned that the field name specified by a <phrase> tag must match the field name set by any tags that contain it. Otherwise, an error will be generated. If no parent tags specify a field name, any field name can be used by the <phrase> tag. Similarly, any tags within a <phrase> tag must either specify the same field name as the phrase, or specify no field name at all. Otherwise, an error will be generated. (Note: Allowing nested copies of the field attribute doesn't serve a purpose other than to make it easier to write docReqParser.xsl stylesheets in a uniform way. Effectively, the outermost field value is always used.)
maxSnippets="SnippetsToOutput" identifies the number of snippets to pass on to the Result Formatter stylesheet for display. A snippet is defined as the matching text found in a document for a particular query, along with some additional text around it for context. The amount of context displayed for each match is defined by the maxContext attribute. If not specified this attribute defaults to 3, meaning snippets for the top three matches for a document are returned. Also, this attribute can be set to -1, meaning all the snippets for a document are returned. As with the field attribute, any maxSnippets value set by the <phrase> tag must match the value set by any tags that contain it. Otherwise, an error will be generated. If no parent tags set a maxSnippets value, then any value may be specified by the <phrase> tag. Similarly, any tags within a <phrase> tag must either specify the same field name as the phrase, or specify no field name at all. Otherwise, an error will be generated. (Note: Allowing nested copies of the maxSnippets attribute doesn't serve a purpose other than to make it easier to write docReqParser.xsl stylesheets in a uniform way. Effectively, the outermost maxSnippets value is always used.)
boost="BoostValue" is an optional attribute that specifies a relevance boost multiplier for this phrase in the query. Boost values higher than 1.0 increase the relevance of a phrase, while boost values between 0.0 and 1.0 decrease the relevance of a phrase. Boost values less than zero will generate an error. Note that boost values multiply. That is, if tags within a <phrase> tag have boost attributes, their individual boost values will be multiplied by the boost set for the containing <phrase> tag.

Within the phrase tag, Term is a term tag, and Clause is a phrase, and, or, orNear, near, range, resultData, or not tag.

Note that text will only match a phrase query if all the terms in the phrase tag appear in the document in same order, with no other intervening words. Note that it does not matter whether the phrase appears at the beginning, middle, or end of a field; it will match in any position. To match the exact contents of an entire field, use the exact tag.

If the field is "text", a Section Type sub-query may optionally appear, restricting this phrase query to particular sections of a document based on section types added by the Pre-Filter stylesheet at index time.