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

FlexSearch undefined when using with Typescript in 0.7.0 #171

Closed sceee closed 3 years ago

sceee commented 4 years ago

I am trying to test 0.7.0 in a typescript project but I cannot get it to work. I don't know if the types are completely out of sync in 0.7.0 but when trying to initialize a FlexSearch index in 0.7.0, its just an empty object:

This is my code:

// Lazy import here
const flexSearch = await import(flexsearch')
const FlexSearch = flexSearch.default
const index = FlexSearch.create<Entry>({
  doc: {
    id: 'id',
    field: ['title', 'array[test]']
  }
})

The issue is that FlexSearch is just an empty object when looking at it in the debugger.

When I downgrade to the regular 0.6.32 it's working with the above code. Was there any change in 0.7.0 how to instantiate the index that is out of sync with the typedefs?

samboman commented 4 years ago

Any updates here? :) Thanks for your support and work!

haysclark commented 3 years ago

Here is a sample working with TS: https://codesandbox.io/s/flexsearch07x-typescript-example-rm6fb?file=/src/index.ts

aurostudio commented 11 months ago

@ts-thomas -- Hi, this issue shouldn't be closed. I have the same issue when using Document() not Index() as the sample @haysclark shared.

I am with 0.7.31 the latest version.

404-html commented 11 months ago

@aurostudio this worked for me:


import Flexsearch from "flexsearch";

// @ts-ignore
const index = Flexsearch.Index();
index.add(0, 'test');
const res = index.search("test");
console.log(res);