Skip to content

serenysoft/rxdb-flexsearch

Repository files navigation

RxDB - FlexSearch plugin

Build Status codecov

Install

npm i rxdb-flexsearch [email protected] --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);
    },
  }
});