<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.fieldWordQuery.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.fieldWordQuery</api:function-name><api:suggest>cts.fieldwordquery</api:suggest><api:suggest>cts</api:suggest><api:suggest>fieldwordquery</api:suggest><api:function-link mode="xquery" fullname="cts:field-word-query">/apidoc/8.0/cts:field-word-query.xml</api:function-link><api:function mode="javascript" name="fieldWordQuery" type="builtin" lib="cts" category="SearchBuiltins" subcategory="cts:query Constructors" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.fieldWordQuery"><api:summary>
  Returns a query matching text content containing a given phrase in the
  specified field.  If the specified field does not exist,
  <code xmlns="http://www.w3.org/1999/xhtml">cts:field-word-query</code> throws an exception.  A field
  is a named object that specified elements to include and exclude
  from a search, and can include score weights for any included elements.
  You create fields at the database level using the Admin Interface.  For
  details on fields, see the chapter on "Fields Database Settings" in the
  <em xmlns="http://www.w3.org/1999/xhtml">Administrator's Guide</em>.
</api:summary><api:params><api:param name="field-name" type="xs:string*"><api:param-description>
    One or more field names to search over. If multiple field names are
    supplied, the match can be in any of the specified fields (or-query
    semantics).
  </api:param-description><api:param-name>field-name</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="text" type="xs:string*"><api:param-description>
    The word or phrase to match. If multiple strings are specified,
    the query matches if any of the words or phrases match (or-query
    semantics).
  </api:param-description><api:param-name>text</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="options" type="xs:string*" optional="true"><api:param-description>
    Options to this query.  The default is ().
    <p xmlns="http://www.w3.org/1999/xhtml">
      Options include:</p>
      <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
        <dt>"case-sensitive"</dt>
        <dd>A case-sensitive query.</dd>
        <dt>"case-insensitive"</dt>
        <dd>A case-insensitive query.</dd>
        <dt>"diacritic-sensitive"</dt>
        <dd>A diacritic-sensitive query.</dd>
        <dt>"diacritic-insensitive"</dt>
        <dd>A diacritic-insensitive query.</dd>
        <dt>"punctuation-sensitive"</dt>
        <dd>A punctuation-sensitive query.</dd>
        <dt>"punctuation-insensitive"</dt>
        <dd>A punctuation-insensitive query.</dd>
        <dt>"whitespace-sensitive"</dt>
        <dd>A whitespace-sensitive query.</dd>
        <dt>"whitespace-insensitive"</dt>
        <dd>A whitespace-insensitive query.</dd>
        <dt>"stemmed"</dt>
        <dd>A stemmed query.</dd>
        <dt>"unstemmed"</dt>
        <dd>An unstemmed query.</dd>
        <dt>"wildcarded"</dt>
        <dd>A wildcarded query.</dd>
        <dt>"unwildcarded"</dt>
        <dd>An unwildcarded query.</dd>
        <dt>"exact"</dt>
        <dd>An exact match query. Shorthand for "case-sensitive",
        "diacritic-sensitive", "punctuation-sensitive",
        "whitespace-sensitive", "unstemmed", and "unwildcarded".
        </dd>
        <dt>"lang=<em>iso639code</em>"</dt>
        <dd>Specifies the language of the query. The <em>iso639code</em>
            code portion is case-insensitive, and uses the languages
            specified by
           <a href="http://www.loc.gov/standards/iso639-2/php/code_list.php" target="_blank">ISO 639</a>.
            The default is specified in the database configuration.</dd>
        <dt>"distance-weight=<em>number</em>"</dt>
        <dd>A weight applied based on the minimum distance between matches
        of this query.  Higher weights add to the importance of
        proximity (as opposed to term matches) when the relevance order is
        calculated.
        The default value is 0.0 (no impact of proximity). The
        weight should be between 64 and -16.
        Weights greater than 64 will have the same effect as a
        weight of 64.
        This parameter has no effect if the <code>word positions</code>
        index is not enabled.  This parameter has no effect on searches that
        use score-simple, score-random, or score-zero (because those scoring
        algorithms do not consider term frequency, proximity is irrelevant).
        </dd>
        <dt>"min-occurs=<em>number</em>"</dt>
        <dd>Specifies the minimum number of occurrences required. If
        fewer that this number of words occur, the fragment does not match.
        The default is 1.</dd>
        <dt>"max-occurs=<em>number</em>"</dt>
        <dd>Specifies the maximum number of occurrences required.  If
        more than this number of words occur, the fragment does not match.
        The default is unbounded.</dd>
        <dt>"synonym"</dt>
        <dd>Specifies that all of the terms in the $text parameter are
        considered synonyms for scoring purposes.  The result is that
        occurrences of more than one of the synonyms are scored as if
        there are more occurrences of the same term (as opposed to
        having a separate term that contributes to score). </dd>
	<dt>"lexicon-expand=<em>value</em>"</dt>
	<dd>The <em>value</em> is one of <code>full</code>,
	<code>prefix-postfix</code>, <code>off</code>, or
	<code>heuristic</code> (the default is <code>heuristic</code>).
	An option with a value of <code>lexicon-expand=full</code>
	specifies that wildcards are resolved by expanding the pattern to
	words in a lexicon (if there is one available), and turning into a
        series of <code>cts:word-queries</code>, even if this takes a long
	time to evaluate.
	An option with a value of <code>lexicon-expand=prefix-postfix</code>
	specifies that wildcards are resolved by expanding the pattern to the
	pre- and postfixes of the words in the word lexicon (if there is one),
	and turning the query into a series of character queries, even if it
	takes a long time to evaluate.
	An option with a value of <code>lexicon-expand=off</code>
	specifies that wildcards are only resolved by looking up character
	patterns in the search pattern index, not in the lexicon.
	A option with a value of <code>lexicon-expand=heuristic</code>,
	which is the default, specifies that wildcards are resolved by using
	a series of internal rules, such as estimating the number of lexicon
	entries that need to be scanned, seeing if the estimate crosses
	certain thresholds, and (if appropriate), using another way besides
	lexicon expansion to resolve the query.
       	</dd>
      </dl></blockquote>

  </api:param-description><api:param-name>options</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="weight" type="xs:double?" optional="true"><api:param-description>
    A weight for this query.
    Higher weights move search results up in the relevance
    order.  The default is 1.0. The
    weight should be between 64 and -16.
    Weights greater than 64 will have the same effect as a
    weight of 64.
    Weights less than the absolute value of 0.0625 (between -0.0625 and
    0.0625) are rounded to 0, which means that they do not contribute to the
    score.
  </api:param-description><api:param-name>weight</api:param-name><api:param-type>Number?</api:param-type></api:param></api:params><api:return>cts.fieldWordQuery</api:return><api:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">If you use <code>cts:near-query</code> with
  <code>cts:field-word-query</code>, the distance supplied in the near query
  applies to the whole document, not just to the field.  For example, if
  you specify a near query with a distance of 3, it will return matches
  when the words or phrases are within 3 words in the whole document,
  even if some of those words are not in the specified field.  For a code
  example illustrating this, see the 
  
  <a href="#fqex2j" class="javascript">second example</a>
  below. </p>
  <p xmlns="http://www.w3.org/1999/xhtml">Phrases are determined based on words being next to each other
  (word positions with a distance of 1) and words being in the same
  instance of the field.  Because field word positions
  are determined based on the fragment, not on the field, field phrases
  cannot span excluded elements (this is because MarkLogic Server breaks
  out of the field when it encounters the excluded element and start a new
  field when it encounters the next included element).  Similarly, field
  phrases will not span included sibling elements.  The
  
  <a href="#fqex2j" class="javascript">second code example below</a>
  illustrates this. </p>
  <p xmlns="http://www.w3.org/1999/xhtml">Field phrases will automatically phrase-through all child elements of
  an included element, until it encounters an explicitly excluded
  element. The 
  
  <a href="#fqex3j" class="javascript">third example</a>
  below illustrates this.
  An example of when this automatic phrase-through behavior might be
  convenient is if you create a field that includes only the element
  <code>ABSTRACT</code>.  Then all child elements of <code>ABSTRACT</code>
  are included in the field, and phrases would span all of the child
  elements (that is, phrases would "phrase-through" all the child elements).</p>
  <p xmlns="http://www.w3.org/1999/xhtml">
    Negative "min-occurs" or "max-occurs" values will be treated as 0 and
    non-integral values will be rounded down.  An error will be raised if
    the "min-occurs" value is greater than the "max-occurs" value.
  </p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
cts.search(cts.fieldWordQuery("myField", "my phrase"));

=&gt; a list of documents that contain the phrase
   "my phrase" in the field "myField". The field
   must exist in the database against which this query
   is evaluated.
</pre></api:example><api:example class="javascript">
<a id="fqex2j" xmlns="http://www.w3.org/1999/xhtml"></a><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
//   Assume the database has a field named
//   "buzz" with the element "buzz"
//   included and the element "baz" excluded.

var x = xdmp.unquote(
'&lt;hello&gt;word1 word2 word3\n\
  &lt;buzz&gt;word4 word5&lt;/buzz&gt;\n\
  &lt;baz&gt;word6 word7 word8&lt;/baz&gt;\n\
  &lt;buzz&gt;word9 word10&lt;/buzz&gt;\n\
&lt;/hello&gt;').next().value;
var res = new Array();
res.push(cts.contains(x, cts.nearQuery(
  [cts.fieldWordQuery("buzz", "word5"),
   cts.fieldWordQuery("buzz", "word9")], 3)));
res.push(cts.contains(x, cts.nearQuery(
  [cts.fieldWordQuery("buzz", "word5"),
   cts.fieldWordQuery("buzz", "word9")], 4)));
res.push(cts.contains(x,
  cts.fieldWordQuery("buzz", "word5 word9")));
res;

//   Returns the array [false, true, false].
//   The first part does not match because
//   the distance between "word5" and "word9"
//   is 4.  This is because the distance is
//   calculated based on the whole node (if the
//   document was in a database, based on the
//   fragment), not based on the field. The
//   second part specifies a distance of 4, and
//   therefore matches and returns true. The third
//   part does not match because the phrase is
//   based on the entire node, not on the field,
//   and there are words between "word5" and "word9"
//   in the node (even though not in the field).


</pre></api:example><api:example class="javascript">
<a id="fqex3j" xmlns="http://www.w3.org/1999/xhtml"></a><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
//   Assume the database has a field named
//   "buzz" with the element "buzz"
//   included and the element "baz" excluded.

var x = xdmp.unquote(
'&lt;hello&gt;\n\
  &lt;buzz&gt;word1 word2\n\
    &lt;gads&gt;word3 word4 word5&lt;/gads&gt;\n\
    &lt;zukes&gt;word6 word7 word8&lt;/zukes&gt;\n\
  word9 word10\n\
  &lt;/buzz&gt;\n\
&lt;/hello&gt;').next().value;
cts.contains(x,
  cts.fieldWordQuery("buzz", "word2 word3"));

//   Returns "true" because the children of
//   "buzz" are not excluded, and are therefore
//   automatically phrased through.


</pre></api:example></api:function></api:function-page>