Using MoreLikeThis

MoreLikeThis is available through query methods and will return similar documents according to the provided criteria and options.

Syntax

query.moreLikeThis(moreLikeThis);

query.moreLikeThis(builder);
Parameters
moreLikeThis MoreLikeThisBase Defines the type of MoreLikeThis that should be executed
builder function Builder with fluent API that constructs the MoreLikeThisBase instance

Builder

builder.usingAnyDocument();

builder.usingDocument(documentJson);

builder.usingDocument(filterBuilder);

builder.withOptions(options);
Parameters
documentJson string Inline JSON document that will be used as a base for operation
builder (filterBuilder) => void Filtering expression utilized to find a document that will be used as a base for operation
options object Non-default options that should be used for operation
   minimumTermFrequency number Ignores terms with less than this frequency in the source doc
   maximumQueryTerms number Returns a query with no more than this many terms
   maximumNumberOfTokensParsed number The maximum number of tokens to parse in each example doc field that is not stored with TermVector support
   minimumWordLength number Ignores words less than this length or, if 0, then this has no effect
   maximumWordLength number Ignores words greater than this length or if 0 then this has no effect
   minimumDocumentFrequency number Ignores words which do not occur in at least this many documents
   maximumDocumentFrequency number Ignores words which occur in more than this many documents
   maximumDocumentFrequencyPercentage number Ignores words which occur in more than this percentage of documents
   boost boolean Boost terms in query based on score
   boostFactor number Boost factor when boosting based on score
   stopWordsDocumentId string Document ID containing custom stop words
   fields string[] Fields to compare

Example I

// Search for similar articles to 'articles/1'
// using 'Articles/MoreLikeThis' index and search only field 'body'
const options = { fields: [ "body" ] };

const articles = await session
    .query({ indexName:  "Articles/MoreLikeThis" })
    .moreLikeThis(builder => builder
        .usingDocument(x => x.whereEquals("id()", "articles/1"))
        .withOptions(options))
    .all();
from index 'Articles/MoreLikeThis' 
where morelikethis(id() = 'articles/1', '{ "Fields" : [ "body" ] }')

Example II

// Search for similar articles to 'articles/1'
// using 'Articles/MoreLikeThis' index and search only field 'body'
// where article category is 'IT'
const options = { fields: [ "body" ] };
const articles = await session
    .query({ indexName: "Articles/MoreLikeThis" })
    .moreLikeThis(builder => builder
        .usingDocument(x => x.whereEquals("id()", "articles/1"))
        .withOptions(options))
    .whereEquals("category", "IT")
    .all();
from index 'Articles/MoreLikeThis' 
where morelikethis(id() = 'articles/1', '{ "Fields" : [ "body" ] }') and category == 'IT'