op.fromSearch( query as cts.query, [columns as columnIdentifier[]], [qualifier as String?], [options as objectLiteral] ) as ModifyPlan
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.wordQuery. 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. |
The fromSearch
function is one of the
Data Access Functions.
// Get the data for top 20 employees with experience related to design const op = require('/MarkLogic/optic'); op.fromSearch(cts.jsonPropertyValueQuery('experience', 'design'), ['fragmentId', 'score', 'quality']) .orderBy(op.desc('score')) .limit(20) .joinInner(op.fromView(null, 'employee', '', op.fragmentIdCol('rowsDocId')), op.on('fragmentId', 'rowsDocId')) .result();
const op = require('/MarkLogic/optic'); op.fromSearch('tiger', ['confidence','fitness','score', 'quality','fragmentId'], null, {scoreMethod:'bm25', bm25LengthWeight:0.5}) .joinDocAndUri('doc','uri', op.fragmentIdCol('fragmentId')) .result();
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.