Loading TOC...

search:search

search:search(
   $qtext as xs:string+,
   [$options as element(search:options)?],
   [$start as xs:unsignedLong?],
   [$page-length as xs:unsignedLong?]
) as element(search:response)

Summary

This function parses and invokes a query according to specified options, returning up to $page-length result nodes starting from $start.

Parameters
$qtextThe query text to parse. This may be a sequence, to accommodate more complex search UI. Multiple query texts are combined with an AND operator.
$optionsOptions 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 values specification, but such options are not used in this context. For details, see Appendix: Query Options Reference in the Search Developer's Guide.

  • additional-query - Additional query(s) to apply to the search. For details, see additional-query in the Search Developer's Guide
  • concurrency-level - The maximum number of threads to use when resolving facets. For details, see concurrency-level in the Search Developer's Guide
  • constraint - Limit the scope of a search and define facets. For details, see constraint in the Search Developer's Guide
  • debug - Enable or disable inclusion of debugging data in the search results. For details, see debug in the Search Developer's Guide
  • default-suggestion-source - Define a source for generating suggestions for naked terms. For details, see default-suggestion-source in the Search Developer's Guide
  • extract-document-data - Select elements, attributes, and JSON properties to include in the search results. For details, see extract-document-data in the Search Developer's Guide
  • extract-metadata: This option is deprecated. Use extract-document-data instead. For details, see extract-document-data in the Search Developer's Guide.
  • forest - Limit a search or lexicon query to specific forests. For details, see forest in the Search Developer's Guide
  • fragment-scope - Control the global fragment scope (properties or documents) over which to search. For details, see fragment-scope in the Search Developer's Guide
  • grammar - Define a custom search grammar. For details, see grammar in the Search Developer's Guide
  • operator - For details, see operator in the Search Developer's Guide
  • page-length - The number of results to return in each page of results. For details, see page-length in the Search Developer's Guide
  • quality-weight - A document quality weight to use when computing scores. For details, see quality-weight in the Search Developer's Guide
  • result-decorator - Specify a function with which to decorate each search results with additional information. For details, see result-decorator in the Search Developer's Guide
  • return-constraints - Whether or not to include the input constraint definitions in the search response. For details, see return-constraints in the Search Developer's Guide
  • return-facets - Whether or not to include facets in the search response. For details, see return-facets in the Search Developer's Guide
  • return-metrics - Whether or not to include query performance data in the search response. For details, see return-metrics in the Search Developer's Guide
  • return-plan - Whether or not to include a query plan in the search response. For details, see return-plan in the Search Developer's Guide
  • return-qtext - Whether or not to include the input query text in the search response. For details, see return-qtext in the Search Developer's Guide
  • return-query - Whether or not to include the final representation of the input query in the search response. For details, see return-query in the Search Developer's Guide
  • return-results - Whether or not to include search result details in the search response. For details, see return-results in the Search Developer's Guide
  • return-similar - Whether or not to include a list of similar document for each search result in the response. For details, see return-similar in the Search Developer's Guide
  • search-option - Specify an advanced option to pass to the underlying cts query layer. For details, see search-option in the Search Developer's Guide
  • searchable-expression - An XPath expression that selects the documents to include in a search. For details, see searchable-expression in the Search Developer's Guide
  • sort-order - Define elements, attributes, fields, or JSON properties on which to order results. For details, see sort-order in the Search Developer's Guide
  • suggestion-source - Define a suggestion completion source for constraint-qualified search terms. For details, see suggestion-source in the Search Developer's Guide
  • term - Specify the handling of empty searches and search terms not associated with a constraint. For details, see term in the Search Developer's Guide
  • transform-results - Specify a function to use for generating snippets. For details, see transform-results in the Search Developer's Guide

$startThe 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-lengthThe maximum number of hits to return. The default is 10. If the value is 0, no results are returned.

Usage Notes

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.

Example

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>

    

Example

(: 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(&quot;/foo.xml&quot;)" score="328" 
		confidence="0.807121" fitness="0.901397">
    <search:snippet>
	    <search:match path="fn:doc(&quot;/foo.xml&quot;)/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>


    

Comments

  • How can I configure the options to return the full document in search:search response and how can I return the particular elements (predefined XPaths) data?
    • See the <a href="http://docs.marklogic.com/guide/search-dev/appendixa#id_50098">transform-results</a> and <a href="http://docs.marklogic.com/guide/search-dev/appendixa#id_44222">extract-document-data</a> options.
  • Does anyone know if it's possible to sort by the xdmp:document-timestamp of uris using search:search?
    • Alright, a bit more digging has proved fruitful. Danny.Sokolsky at marklogic.com has listed an example here http://developer.marklogic.com/pipermail/general/2010-August/006123.html with my implementation as follows: xquery version "1.0-ml"; import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; declare namespace prop="http://marklogic.com/xdmp/property"; let $options := <options xmlns="http://marklogic.com/appservices/search"> <searchable-expression>xdmp:document-properties() </searchable-expression> <debug>true</debug> <term> <empty apply="all-results" /> </term> <sort-order type="xs:dateTime" direction="descending"> <element ns="http://marklogic.com/xdmp/property" name="last-modified"/> </sort-order> </options> let $b:=search:search("", $options,1,10) let $d :=$b/search:result/@uri let $c :=$b/@total/string() return <database start='1' end='10'><success>true</success> <total>{$c}</total> <date>{fn:current-date()}</date>{ for $x in $d let $n :=doc($x) return <document> <uri>{fn:document-uri($n)}</uri> <title>{$n//docDscr/citation/titlStmt/titl//text()}</title> <time>{fn:format-dateTime(xdmp:timestamp-to-wallclock(xdmp:document-timestamp(fn:document-uri($n))),'[D01]/[M01]/[Y0001] [H01]:[m01]:[s01]:[f01]')}</time> <collection>{xdmp:document-get-collections(fn:document-uri($n))}</collection> </document> } </database>
  • Understanding what level of search you want to start with in MarkLogic can be a little confusing ... a good rule of thumb is that search:search is the place to start ... if you needmore complex queries and control then you may migrate to using the sophisticated cts:search. In situations where you don't want to require your developers to know xquery, then the REST server structured search maybe the best place to start. EXPERT - Grokking the cts API    http://developer.marklogic.com/blog/grokking-the-cts-api BASIC (But sophisticated) - Search search    http://developer.marklogic.com/learn/2006-09-paginated-search NO XQUERY - REST server    http://developer.marklogic.com/learn/rest  
Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy