Basic Usage

Finds documents similar to a given document or set of field values. This is useful for recommendation engines or finding related content based on textual similarities.

You must pass either:

  • with_document_id, which takes a “key field” value to match against the corresponding document.
  • with_document_fields, which takes a JSON object string to match against.

All other parameters are compatible with both with_document_id and with_document_fields.

-- with_document_id
SELECT * FROM search_idx.search(
    query => paradedb.more_like_this(
        with_document_id => 2,
        with_min_word_length => 2,
        with_max_word_length => 5,
        with_boost_factor => 1.0,
        with_stop_words => ARRAY['and', 'the', 'for']
    )
);

-- with_document_fields
SELECT * FROM search_idx.search(
    query => paradedb.more_like_this(
        with_document_fields => '{"flavour": "banana"}',
        with_min_doc_frequency => 0,
        with_max_doc_frequency => 100,
        with_min_term_frequency => 1,
    )
);
with_document_id

The ID of the document to find similar documents to.

with_document_fields

A JSON object representing the field values to use for similarity matching.

with_min_doc_frequency

Minimum document frequency of terms to be considered.

with_max_doc_frequency

Maximum document frequency of terms to be considered.

with_min_term_frequency

Minimum term frequency of terms to be considered.

with_max_query_terms

Maximum number of query terms to be used.

with_min_word_length

Minimum word length of terms to be considered.

with_max_word_length

Maximum word length of terms to be considered.

with_boost_factor

Boost factor to amplify the impact of matching terms.

with_stop_words

A JSON array of stop words to be ignored in the query.