0.1.1 • Published 9 months ago

rxdb-flexsearch v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

RxDB - FlexSearch plugin

Build Status codecov

Install

npm i rxdb-flexsearch flexsearch@0.7.21 --save

Usage

import { addRxPlugin } from 'rxdb';
import { getRxStorageMemory } from 'rxdb/plugins/storage-memory';
import { RxDBFlexSearchPlugin } from 'rxdb-flexsearch';
import { userSchema } from './schemas';

addRxPlugin(RxDBFlexSearchPlugin);

const database = await createRxDatabase({
  storage: getRxStorageMemory(),
});

await database.addCollections({
  users: {
    schema: userSchema,
    options: {
      searchable: true,
    },
  },
});

...

const results = await collection.search(query: string);
console.log(results);

Import/Export indexes

await database.exportIndexes((key, data) => {
  localStorage.setItem(key, data);
});


await database.importIndexes({
  [key]: localStorage.getItem(key);
});

You can use the autoIndexExport database option to automatically export indexes when the collection is modified.

const database = await createRxDatabase({
  storage: getRxStorageMemory(),
  options: {
    autoIndexExport: (key, value) => {
      localStorage.setItem(key, value);
    },
  }
});