Loading TOC...

cts.query

cts.query(
   $query as Node
) as cts.query

Summary

Creates a query.

Parameters
$query A query.

Example

cts.query(fn.head(xdmp.unquote(
  '<cts:word-query xmlns:cts="http://marklogic.com/cts">'
  +'  <cts:text>word</cts:text>'
  +'</cts:word-query>')).root)
=>
cts.wordQuery("word", ["lang=en"], 1)

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.

Comments

  • In your example below, the underlying queries are the same: a word query looking for the word "something" present anywhere in the matching document. However please be aware of what will get returned. When using the client REST API search endpoint you are returned a summary of search results in either XML or JSON format. This lets you easily build a search results page using that summary data. In that summary data that is returned you will find the matching document URI, so you can return the whole document if needed in your application. When you use cts:search() you are not returning this summary of results but rather you are returning the actual documents that match your query.
    • One other difference, though it wouldn't show up in Udhayha's sample query: REST API queries are unfiltered by default; cts:search is filtered by default. See <a href="http://docs.marklogic.com/guide/performance/unfiltered#id_89797">Understanding Unfiltered Searches</a>.
  • Is there a difference between doing a rest api v1/search?q=something and cts.search(cts.wordQuery('something')). Or will they give the same result?
    • Using the /search service with a string query (the text in the "q" parameter) is equivalent to using search:search, rather than cts:search (or cts.search - it's the same). The search:search library is an abstraction on top of cts:search, so it shares most of the same behaviors, but it is not identical. The string query grammars used by search:search and cts:search are, again, the same in most respects, but differ in a few of the details. You should refer to the following for detalis on the grammar accepted by /search: http://docs.marklogic.com/guide/search-dev/string-query. Also, the difference in whether the search is filtered or not, mentioned here previously by Dave Cassel, makes an important difference in both the results and (potentially) the performance. You will not find much in the way of JavaScript discussion for search:search because the jsearch library (http://docs.marklogic.com/guide/search-dev/javascript) provides the same kind of abstraction in a JS-specific way. There is a high level overview of how the various search APIs fit together in MarkLogic here: http://docs.marklogic.com/guide/search-dev/searchdev#id_36053.