nextapps-de / flexsearch

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

how can I use flexsearch in my next project? #375

Open imhalid opened 1 year ago

imhalid commented 1 year ago
import FlexSearch from 'flexsearch'

const index = FlexSearch.create({
  encode: 'icase',
  tokenize: 'forward',
  depth: 3,
})

image

I want to add a search feature for a document project.

where am I making a mistake now

productdevbook commented 1 year ago

same problem :/

howesteve commented 1 year ago

Same here, using vite

Internal server error: __vite_ssr_import_0__.default.create is not a function
hunght commented 1 year ago

same here

hanneskuettner commented 1 year ago

I think this is the same problem as #341. See my comment in #333 for an explanation.

imhalid commented 1 year ago
import { Index } from 'flexsearch'

export function buildIndex(data) {
  const index = new Index({
    charset: 'latin:extra',
    tokenize: 'full',
    resolution: 9,
    cache: true,
  })

  data.forEach((posts, i) => {
    const pattern = posts.content
    index.add(i, pattern)
  })
  return index
}

I solved my problem by doing it this way.

ShivamJoker commented 1 year ago

Whats the point of getting the best performance library which just can't work with ESM.

bmccorm2 commented 1 year ago

This is what i had to do to get it to work:

import Flexsearch from "flexsearch";

const Index= Flexsearch.Index ?? Flexsearch;
const index = Index({
  tokenize: 'forward',
});

...