nextapps-de / flexsearch

Next-Generation full text search library for Browser and Node.js
Apache License 2.0
12.54k stars 492 forks source link

Enrich search not working (typescript) #328

Closed jonasbetareader closed 2 years ago

jonasbetareader commented 2 years ago

I'm trying to retrieve enriched documents from the Document index, but only getting the non-enriched id back.

Example code:

import { Document } from 'flexsearch';

type TestDocument = {
  foo: number;
  bar: string;
}

const docIndex = new Document<
      TestDocument,
      true
    >({
      document: {
        id: 'foo',
        store: true,
      },
    });

docIndex.add({ foo: 1, bar: 'test-document' });

console.log(docIndex.search<true>(1));

The above results in the following result:

Array [
  Object {
    "field": "foo",
    "result": Array [
      "1",
    ],
  },
]

I would have expected something like the following: Array [ Object { "field": "foo", "result": Array [ { foo: 1, bar: 'test-document' }, ], }, ]

Am I missing or misunderstanding something? Using "flexsearch: "^0.7.21", and "@types/flexsearch": "^0.7.3",

ts-thomas commented 2 years ago

When search you'll need to pass the enrich field.

https://github.com/nextapps-de/flexsearch#document-search-options