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

I can't use the package, need help #232

Closed maxacarvalho closed 3 years ago

maxacarvalho commented 3 years ago

Hi,

I'd like to first thank you for this great package, then I'd like to understand how to actually integrate it with my app, I'm having issues when trying to install and compile for production.

I use the Laravel Mix package to compile my assets, it's just a wrapper around webpack.

I've been using the hot reload and dev compile modes so far and the package was working as expected, but when I try to compile for production it fails with a Terser error. šŸ‘‡šŸ½

CleanShot 2021-06-24 at 20 14 02@2x

Here is how I was instantiating the FlexSearch instance:

...
import Document from 'flexsearch/dist/module/document';
import { encode } from "flexsearch/dist/module/lang/latin/advanced.js";
...

...
function initFlexSearch() {
    document.value = new Document({
      tokenize: 'forward',
      cache: 100,
      encode: encode,
      matcher: 'string',
      document: {
        id: props.documentId,
        field: props.fields,
      }
    });
    props.collection.forEach(item => document.value.add(item));
}
...

Now I'm trying to import the package using import FlexSearch from 'flexsearch/dist/flexsearch.bundle';, but then the execution fails with šŸ‘‡šŸ½

CleanShot 2021-06-24 at 20 15 36@2x

Here's how I'm instantiating my instance (that's from within a Vue3 component):

...
import FlexSearch from 'flexsearch/dist/flexsearch.bundle';
import { encode } from "flexsearch/dist/module/lang/latin/advanced.js";
...

...
function initFlexSearch() {
    document.value = new FlexSearch.Document({
      tokenize: 'forward',
      cache: 100,
      encode: encode,
      matcher: 'string',
      document: {
        id: props.documentId,
        field: props.fields,
      }
    });
    props.collection.forEach(item => document.value.add(item));
  }
...

I also tried to download the ES6 modules (/dist/module/), but then, when I try to import with import Document from '@/vendor/flex-search/document';, it fails with šŸ‘‡šŸ½

CleanShot 2021-06-24 at 20 23 13@2x

I'm out of options, so I'd like to know from you how's the correct way of using the package?

Thanks.

ts-thomas commented 3 years ago

Please remove matcher: 'string', because "string" isn't a valid matcher. This options needs to be better explained in the readme (it is on my tasks). The "document" also looks that it might not being used properly (I can't see your "props"). Also this import statement is false: import FlexSearch from 'flexsearch/dist/flexsearch.bundle', because you load a web bundle which is supposed to load as script tag ressource (non-module) as a module. You need to load it this way as ES6 modules: import Document from 'flexsearch/dist/module/document.js'. I can recommend you to start the readme from top with a simple index again and put your configuration one by one.