MarkLogic Server 11.0 Product Documentation
cts:not-in-query

cts:not-in-query(
   $positive-query as cts:query,
   $negative-query as cts:query
) as cts:not-in-query

Summary

Returns a query matching the first sub-query, where those matches do not occur within 0 distance of the other query.

Parameters
positive-query A positive query, specifying the search results filtered in.
negative-query A negative query, specifying the search results to filter out.

Usage Notes

Positions are required to accurately resolve this query from the indexes. If you do not enable position indexes appropriate to the type of the sub-queries, then you may get surprising results in unfiltered searches. For example, if the sub queries are cts:word-query, then you should enable word positions in the database.

False positives can occur if there are no positions available, such as when positions are not enabled. Filtered searches always have access to positions, but unfiltered searches do not.

Some query types are intrinsically positionless, such as cts:collection-query or cts:directory-query. Matches to such a query are considered to occur at every position and causes the overall query to behave like cst:and-not-query. If no position can be determined, such as when positions are not enabled, then every match to $positive-query is a match for the whole query.

Example

cts:search(//PLAY,
  cts:not-in-query(
    cts:word-query("nettles"),
    cts:word-query("stinging nettles")))
=> A sequence of 'PLAY' elements containing some text node
   with the word 'nettles' where that occurrence is not in the
   phrase 'stinging nettles'.This sequence may be (in fact is) non-empty,
   but certainly does not contain the PLAY element with:

    PLAY/TITLE =
      "The Tragedy of King Richard the Second"

   since, while this play does contain 'nettles', it is only in the
   phrase 'stinging nettles'. On the other hand, this play
   will match the query:

     cts:search(//PLAY,
       cts:not-in-query(
         cts:word-query("summer"),
         cts:word-query("summer corn")))

   since, while the play does contain 'summer corn', it also contains 'summer'
   in other contexts as well.

   If word positions are not enabled, then an unfiltered search returns
   all documents containing "nettles".

Example

cts:search(//PLAY,
  cts:not-in-query(
    cts:word-query("nettles"),
    cts:collection-query("TRAGEDY")))
=> A sequence of 'PLAY' elements containing some text node with
   the word "nettles", excluding occurrences in documents in the
   "TRAGEDY" collection. The collection query is intrinsically,
   positionless, so the negative query matches overlap with every
   match of the positive query.
Powered by MarkLogic Server | Terms of Use | Privacy Policy