nextapps-de / flexsearch

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

Problem indexing a number value #312

Closed jarrodek closed 2 years ago

jarrodek commented 2 years ago

I am using flexsearch version 0.7.21.

The following code results in an error.

The test.js file:

import FlexSearch from 'flexsearch';

const index = new FlexSearch.Document({
  document: {
    id: 'id',
    index: [
      'doc:info:name',
      'doc:variables[]:name',
      'doc:variables[]:value',
    ],
  },
  charset: 'latin:extra',
  tokenize: 'reverse',
  resolution: 9,
});

index.add({
  id: 0,
  doc: {
    info: {
      name: 'name 1'
    },
    variables: [
      {
        name: 'port',
        value: 8080,
      }
    ],
  }
});
const result = index.search('name');
console.log(result)

And the result is:

TypeError: b.toLowerCase is not a function
    at K.Aa (/Users/ppsztyc/workspace/arc/cli/node_modules/flexsearch/dist/flexsearch.bundle.js:33:779)
    at K.Da (/Users/ppsztyc/workspace/arc/cli/node_modules/flexsearch/dist/flexsearch.bundle.js:33:991)
    at K.Ha (/Users/ppsztyc/workspace/arc/cli/node_modules/flexsearch/dist/flexsearch.bundle.js:33:1449)
    at Ka [as encode] (/Users/ppsztyc/workspace/arc/cli/node_modules/flexsearch/dist/flexsearch.bundle.js:33:1634)
    at K.t.add (/Users/ppsztyc/workspace/arc/cli/node_modules/flexsearch/dist/flexsearch.bundle.js:12:102)
    at V (/Users/ppsztyc/workspace/arc/cli/node_modules/flexsearch/dist/flexsearch.bundle.js:25:353)
    at V (/Users/ppsztyc/workspace/arc/cli/node_modules/flexsearch/dist/flexsearch.bundle.js:25:453)
    at V (/Users/ppsztyc/workspace/arc/cli/node_modules/flexsearch/dist/flexsearch.bundle.js:25:420)
    at V (/Users/ppsztyc/workspace/arc/cli/node_modules/flexsearch/dist/flexsearch.bundle.js:25:453)
    at Q.t.add (/Users/ppsztyc/workspace/arc/cli/node_modules/flexsearch/dist/flexsearch.bundle.js:26:191)

I identified the problem with the use of the charset: 'latin:extra', configuration property. After removing the configuration property it starts working again. The same behavior is for latin:advanced value.

I am not sure how to proceed now. I need the extra variant to match the query. Any help would be appreciated.

jarrodek commented 2 years ago

To add, the library is an ESM module (as it has "type": "module") in the package.json file so all imports are resolved as ESM. You then run the file as node test.js.

ts-thomas commented 2 years ago

This is now fixed in v0.7.23