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

Usage help #226

Closed sidugboe closed 3 years ago

sidugboe commented 3 years ago

Hello, I am new to flexsearch. I am currently experiencing errors when i initially try to use it.

All I am doing right now is the following =>

const { Index, Document, Worker } = require("flexsearch")
const index = new Index ();
const document = new Document();
const worker = new Worker();

but I get the following error =>

function ya(a,b,c){let d;try{d=b?eval('new (require("worker_threads")["Worker"])("../dist/node/node.js")'):a?new Worker(URL.createObjectURL(new Blob(["onmessage="+wa.toString()],{type:"text/javascript"}))):new Worker(x(c)?c:"worker/worker.js",{type:"module"})}catch(e){}return d};function Q(a){if(!(this instanceof Q))return new Q(a);var b=a.document||a.doc||a,c;this.K=[];this.h=[];this.A=[];this.register=v();this.key=(c=b.key||b.id)&&S(c,this.A)||"id";this.m=u(a.fastupdate);this.G=(c=b.store)&&!0!==c&&[];this.store=c&&v();this.I=(c=b.tag)&&S(c,this.A);this.l=c&&v();this.cache=(c=a.cache)&&new J(c);a.cache=!1;this.o=a.worker;this.async=!1;c=v();let d=b.index||b.field||b;x(d)&&(d=[d]);for(let e=0,f,g;e<d.length;e++)f=d[e],x(f)||(g=f,f=f.field),g=C(g)?Object.assign({},a,g):a,

TypeError: Cannot read property 'document' of undefined

    at new Q (C:\Users\IDUGBOES\Desktop\Project\s1000d-ietp\node_modules\flexsearch\dist\flexsearch.bundle.js:24:343)

    at Object.<anonymous>

The only time i dont get this error is when i take out the worker and document initializations. Perhaps I am not using the correct syntax for those two?

ishanuda commented 3 years ago

Hi @sidugboe, Try to use only one of the Index, Document, or the Worker according to your requirement. You do not need all three together.

Ex: https://codesandbox.io/s/indexing-number-fields-flexsearch-9e790?file=/src/index.js

Also, read the documentation carefully.

Thank you very much.

ts-thomas commented 3 years ago

I've extended the readme: https://github.com/nextapps-de/flexsearch#load-library The issue is you probably just need one of the 3 types of indexes, the document index needs a config object passed as first parameter, that throws your error.