search.search( qtext as String[], [options as element(search.options)?], [start as (Number|String)?], [page-length as (Number|String)?] ) as element(search.response)
This function parses and invokes a query according to specified options, returning up to $page-length result nodes starting from $start.
Parameters | |
---|---|
qtext | The query text to parse. This may be a sequence, to accommodate more complex search UI. Multiple query texts are combined with an AND operator. |
options | Options to define
the search grammar and control the search.
The following is a list of the options that
apply to document searches. The options node can contain other
options, such as a
|
start | The index of the first hit to return. If 0, treated as 1. If greater than the number of results, no results will be returned. The default is 1. |
page-length | The maximum number of hits to return. The default is 10. If the value is 0, no results are returned. |
The output of search:search
returns a
<response>
element, which in turn
contains a total
attribute. The value of the
total
attribute is an estimate, based
on the index resolution of the query, and it is not
filtered for accuracy. The accuracy of the index resolution
depends on the index configuration of the database, on the
query, and on the data being searched.
const search = require('/MarkLogic/appservices/search/search'); search.search('Vannevar Bush', fn.head(xdmp.unquote('<options xmlns="http://marklogic.com/appservices/search">' + '<return-results>false</return-results>' + '<return-facets>true</return-facets>' + '</options>')).root);
// Properties constraint example const search = require('/MarkLogic/appservices/search/search'); declareUpdate(); // Create a document with some properties to test with xdmp.documentInsert("/foo.xml", xdmp.unquote('<foo>hello</foo>')); xdmp.documentSetProperties("/foo.xml", xdmp.unquote('<blah>boo</blah>').root); // Do a properties constraint search search.search("hello sample-property-constraint:boo", fn.head(xdmp.unquote('<options xmlns="http://marklogic.com/appservices/search">' + '<constraint name="sample-property-constraint">' + '<properties />' + '</constraint>' + '<debug>true</debug>' + '</options>')).root); // ==> // <search:response snippet-format="snippet" total="0" start="1" page-length="10" xmlns:search="http://marklogic.com/appservices/search"> // <search:qtext>hello sample-property-constraint:boo</search:qtext> // <search:report id="SEARCH-FLWOR">(cts:search(fn:collection(), cts:and-query((cts:word-query("hello", ("lang=en"), 1), cts:properties-fragment-query(cts:word-query("boo", ("lang=en"), 1))), ()), ("score-logtfidf",cts:score-order("descending")), 1))[1 to 10]</search:report> // <search:metrics> // <search:query-resolution-time>PT0.002853S</search:query-resolution-time> // <search:total-time>PT0.01372S</search:total-time> // </search:metrics> // </search:response>
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.