ability to search by field
Thank you for this repo, can I ask you if is possible to search by field, for example, search all the docks where field = address and the query is 'test' .
import { DocumentIndex } from "ndx";
const index = new DocumentIndex();
index.addField("title");
index.addField("content");
const documents = [
{
id: "doc1",
title: "First Document",
content: "Lorem ipsum dolor",
address: "15",
},
{
id: "doc2",
title: "Second Document",
content: "Lorem ipsum",
address: "23",
}
];
documents.forEach((doc) => {
index.add(doc.id, doc);
});
index.search("First");
// => [{ docId: "doc1", score: ... }]
index.search("Lorem");
// => [{ docId: "doc2", score: ... }, { docId: "doc1", score: ... }]
No, ndx doesn't support searching by field. It was designed to have a small memory footprint, so it stores as little information as possible.
Thank you, any suggestion for javascript or typescript engine that has that feature. ?
Just looked at lunr, elasticlunr and it seems that they support specifying which fields should be used for searching, but it is probably not enough for your use case if you want to create a query that uses different terms in different fields.
Don't know about any other full text search implementations, haven't looked at alternative implementations since I wrote this package two years ago, maybe nowadays there are more libraries.
Thank you @localvoid