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

Cannot read property 'char_filter' of null #192

Open
elmarti opened this issue Sep 19, 2021 · 0 comments
Open

Cannot read property 'char_filter' of null #192

elmarti opened this issue Sep 19, 2021 · 0 comments

Comments

@elmarti
Copy link

elmarti commented Sep 19, 2021

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/LokiJS-Forge/LokiDB/blob/master/CONTRIBUTING.md#question

Current behavior

I'm running LokiDB in electron with the @lokidb/fs-storage adapter and @lokidb/full-text-search.
Everything works fine, apart from when I attempt to run a $fts query, the following is returned:

(node:74814) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'char_filter' of null
    at analyze (/Users/<USER>/dbClient/node_modules/@lokidb/full-text-search/webpack:/@lokidb/full-text-search/packages/full-text-search/src/analyzer/analyzer.ts:30:16)
    at index_searcher_IndexSearcher._recursive (/Users/<USER>/dbClient/node_modules/@lokidb/full-text-search/webpack:/@lokidb/full-text-search/packages/full-text-search/src/index_searcher.ts:223:23)
    at index_searcher_IndexSearcher.search (/Users/<USER>/dbClient/node_modules/@lokidb/full-text-search/webpack:/@lokidb/full-text-search/packages/full-text-search/src/index_searcher.ts:67:29)
    at full_text_search_FullTextSearch.search (/Users/<USER>/dbClient/node_modules/@lokidb/full-text-search/webpack:/@lokidb/full-text-search/packages/full-text-search/src/full_text_search.ts:89:30)
    at result_set_ResultSet.find (/Users/<USER>/dbClient/node_modules/@lokidb/loki/webpack:/@lokidb/loki/packages/loki/src/result_set.ts:622:56)
    at QueryCacheService._callee3$ (/Users/<USER>/dbClient/src/main/services/query-cache.service.ts:109:33)
    at tryCatch (/Users/<USER>/dbClient/src/node_modules/regenerator-runtime/runtime.js:63:40)
    at Generator.invoke [as _invoke] (/Users/<USER>/dbClient/src/node_modules/regenerator-runtime/runtime.js:294:22)
    at Generator.next (/Users/<USER>/dbClient/src/node_modules/regenerator-runtime/runtime.js:119:21)
    at asyncGeneratorStep (/Users/<USER>/dbClient/src/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)

Expected behavior

FTS query executes without failure.

Minimal reproduction of the problem with instructions

Initialising the database connection

    const dbPath = path.join(app.getPath('userData'), 'db.json');
    console.log({dbPath});
    if(!fs.existsSync(dbPath)){
      fs.writeFileSync(dbPath, '{"collections":{}}', "UTF-8", { flags: 'w+'});
    }

    FSStorage.register();
    LokiFullTextSearch.register();

    this.db = new loki(dbPath, {
      serializationMethod: 'normal',
      env: 'NODEJS',
    });

    await this.db.initializePersistence({
      autosave: false,
      autosaveInterval: 1000,
      autoload: false,
      throttledSaves: false,
      adapter: memAdapter,
    })
    await this.db.saveDatabase();
  }

Running an fts query

 async filter(
    collectionId: any,
    query: {},
    sort: any,
    position: { page: number; offset: number; limit: any },
    columns: Array<any>
  ) {
    console.log({ queryId });
    const collection = this.db.getCollection(collectionId)
    const queryObj = {};
    let queryBuilder = collection.chain();
    if (Object.keys(query).length > 0) {
      for (const key in query) {
        const column = columns.find((x) => x.key === key);
        if (column.type.js === 'datetime' || column.type.js === 'date') {
          //{key: {'$between': [value0, value1]}
          queryObj[key] = {
            '$between': query[key].map((x) => new Date(x))
          }
        } else {
          queryObj['$fts'] = {
            query: {
              type: "match",
              field: key,
              value: query[key][0],
              // prefix_length: 1,
              fuzziness: 0,
              extended: true,
              // minimum_should_match: 1
            }
          }
        }
      }
    }
    console.log('queryObj', queryObj);
    queryBuilder = queryBuilder.find(queryObj);
    if (sort) {
      queryBuilder = queryBuilder.simplesort(sort.key, {desc: sort.order === 'desc'});
    }

    const total = queryBuilder.count();
    queryBuilder = queryBuilder.offset(position.page);
    queryBuilder = queryBuilder.limit(position.limit);
    return {
      _id: queryId,
      result:  queryBuilder.data(),
      pagination: {
        total,
        current: position.page,
        pageSize: position.limit,
      },
    };
  }

Environment

  • Electron
  • "@types/lokijs": "^1.5.7",
  • "@lokidb/fs-storage": "^2.1.0",
  • "@lokidb/full-text-search": "^2.1.0",
  • "@lokidb/loki": "^2.1.0",
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

1 participant