Loading TOC...

MarkLogic 12 Product Documentation
op:from-search

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

Summary

This function dynamically constructs a row set based on a cts.query where the columns for the document fragment id and score reflecting the degree of match of the document with the query criteria.

By joining on the document fragment id, a query can add the score to the rows, triples, lexicon values, or content provided by the document.

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. The fragments are not filtered to ensure they match the query, but instead selected in the same manner as "unfiltered" cts:search operations.
$columns Specifies which of the available columns to include in the rows. The available columns include the metrics for relevance ('confidence', 'fitness', 'quality', and 'score') and fragmentId for the document identifier. By default, the rows have the fragmentId and score columns. To rename a column, use op:as specifying the new name for an op:col with the old name.
$qualifier Specifies a name for qualifying the column names.
$options A map with options similar to cts:search. 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'.

See Also

Example

(: Get the data 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(cts:json-property-value-query('experience', 'design'),
                ('fragmentId', 'score', 'quality'))
     => op:order-by(op:desc('score'))
     => op:limit(20)
     => op:join-inner(op:from-view((), 'employee', '', op:fragment-id-col('rowsDocId')),
                op:on('fragmentId', 'rowsDocId'))
     => op:result()
  

Example

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

op:from-search('tiger',
            ('confidence','fitness','score', 'quality','fragmentId'),
            (),
            map:entry('scoreMethod', 'bm25')
              =>map:with('bm25LengthWeight', 0.25)
          )
 =>op:join-doc-and-uri('doc','uri',op:fragment-id-col('fragmentId'))
 => op:result()
  

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