Loading TOC...

MarkLogic 12 EA 2 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 Similar to the options of cts:search, supplies the 'scoreMethod' key with a value of 'logtfidf', 'logtf', 'simple', 'zero', 'random', or 'bm25' to specify the method for assigning a score to matched documents or supplies the 'qualityWeight' key with a numeric value to specify a multiplier for the quality contribution to the score. Specify a value between 0 (exclusive) and 1 (inclusive) for bm25LengthWeight if 'bm25' scoring method is used.

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.