Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to search by field #4

Closed
Georgehatouts opened this issue Sep 4, 2018 · 4 comments
Closed

ability to search by field #4

Georgehatouts opened this issue Sep 4, 2018 · 4 comments

Comments

@Georgehatouts
Copy link

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: ... }]
@localvoid
Copy link
Owner

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.

@Georgehatouts
Copy link
Author

Thank you,
any suggestion for javascript or typescript engine that has that feature. ?

@localvoid
Copy link
Owner

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.

@Georgehatouts
Copy link
Author

Thank you @localvoid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants