Rank text documents by similarity.
Install using NPM or similar.
npm i related-documents
import { Related } from "related-documents";
const documents = [
{ title: "ruby", text: "this lorem ipsum blah foo" },
{ title: "ruby", text: "this document is about python." },
{ title: "ruby and node", text: "this document is about ruby and node." },
{
title: "examples",
text: "this document is about node. it has node examples",
},
];
// The serializer array length must match that of the weights array.
// This example applies a weight of 10 to the title and 1 to the text.
const options = {
serializer: (document: any) => [document.title, document.text],
weights: [10, 1],
};
const related = new Related(documents, options);
// Find documents related to document[0]
related.rank(documents[0]);
See the reference documentation.