op:from-search( $query as cts:query, [$columns as columnIdentifier*], [$qualifier as xs:string?], [$options as map:map] ) as map:map
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', or 'simple' 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. |
(: 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()
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.