search:search( $qtext as xs:string+, [$options as element(search:options)?], [$start as xs:unsignedLong?], [$page-length as xs:unsignedLong?] ) 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.
xquery version "1.0-ml"; import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; search:search("Vannevar Bush", <options xmlns="http://marklogic.com/appservices/search"> <return-results>false</return-results> <return-facets>true</return-facets> </options>) => <search:response total="1234" start="1" page-length="10" xmlns="" xmlns:search="http://marklogic.com/appservices/search"> <search:facet name="date"> <search:facet-value value="today" count="1000"> Today</search:facet-value> <search:facet-value value="yesterday" count="234"> Yesterday</search:facet-value> <search:facet-value value="thismonth" count="1234"> This Month</search:facet-value> <search:/facet> ... </search:response>
(: properties constraint example :) xquery version "1.0-ml"; (: create a document with some properties to test with :) xdmp:document-insert("/foo.xml", <foo>hello</foo>); xdmp:document-set-properties("/foo.xml", <blah>boo</blah>); (: do a properties constraint search :) import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; search:search("hello sample-property-constraint:boo", <options xmlns="http://marklogic.com/appservices/search"> <constraint name="sample-property-constraint"> <properties /> </constraint> <debug>true</debug> </options>) => <search:response total="1" start="1" page-length="10" xmlns="" xmlns:search="http://marklogic.com/appservices/search"> <search:result index="1" uri="/foo.xml" path="fn:doc("/foo.xml")" score="328" confidence="0.807121" fitness="0.901397"> <search:snippet> <search:match path="fn:doc("/foo.xml")/foo"> <search:highlight>hello</search:highlight></search:match> </search:snippet> </search:result> <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-query(cts:word-query("boo", ("lang=en"), 1))), ()), ("score-logtfidf"), 1))[1 to 10] </search:report> <search:metrics> <search:query-resolution-time>PT0.647S</search:query-resolution-time> <search:facet-resolution-time>PT0S</search:facet-resolution-time> <search:snippet-resolution-time>PT0.002S</search:snippet-resolution-time> <search:total-time>PT0.651S</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.