related-documents
Version:
Find related text documents.
49 lines (35 loc) • 1.38 kB
Markdown
[](https://www.npmjs.com/package/related-documents)


[](https://jpoehnelt.github.io/related-documents/)
Rank text documents by similarity.
Install using NPM or similar.
```sh
npm i related-documents
```
```js
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](https://jpoehnelt.github.io/related-documents/).