MarkLogic 12 Product Documentation
op:from-search-docs

op:from-search-docs(
   $query as cts:query,
   [$qualifier as xs:string?],
   [$options as map:map]
) as map:map

Summary

This function matches and returns the uri, content, and score for documents.

Parameters
$query Qualifies and establishes the scores for a set of documents. The query can be a cts:query or a string as a shortcut for a cts:word-query.
$qualifier Specifies a name for qualifying the column names.
$options A map with options similar to cts:search. The results are ordered by score by default. Options include:
  • scoreMethod

    Specifies the method for assigning a score to matched documents. Accepted values are 'logtfidf' (default), 'logtf', 'simple', 'zero', 'random', or 'bm25'.

  • qualityWeight

    A numeric multiplier for the quality contribution to the score.

  • bm25LengthWeight

    When using 'bm25' scoring, specifies the weight of the document length to average document length ratio. Valid values are greater than 0 and up to and including 1. The default is 0.333.

  • fragment

    Controls which fragment types are selected, document fragments, any fragments, properties fragments, or locks fragments. Accepted values are 'document' (default), 'any', 'properties', or 'locks'.

Usage Notes

The op:from-search-docs function is a convenience for executing a op:from-search equivalent to:

declare function local:from-search-docs($query as cts:query, $qualifier as xs:string?, $options as map:map?) as map:map {
   op:from-search($query, ('confidence', 'fitness', 'fragmentId', 'quality', 'score'), $qualifier, $options)
     => op:order-by(op:desc('score'))
     => op:join-doc-and-uri('doc', op:fragment-id-col('fragmentId'))
};
  

Please note that if you have other Optic functions following op:from-search-docs, it may change the ordering of the results.

See Also

Example

(: Get the documents for top 20 employees with experience related to design :)

xquery version "1.0-ml";

import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

   op:from-search-docs(cts:json-property-value-query('experience', 'design'))
     => op:limit(20)
     => op:result()
  

Example

xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

op:from-search-docs('tiger', (),
    map:entry('scoreMethod', 'bm25')
      =>map:with('bm25LengthWeight', 0.5)
   )
=> op:result()
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy