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

How to give certain fields indexed weights in scoring/searching #308

Closed QUzair closed 2 years ago

QUzair commented 2 years ago

I can't seem to find a way to add 'weights' to fields in index for mdx documents. Preferably i would want page title to be top result over the word occurance in another page.

Mongodb example: https://docs.mongodb.com/manual/tutorial/control-results-of-text-search/

Or am i misunderstanding these fields?

e.g

document: {
          id: 'id',
          index: [
            {
              field: 'title',
              context: {
                depth: 3,
                resolution: 9,
              },
            },
            {
              field: 'excerpt',
              context: {
                depth: 1,
                resolution: 1,
              },
            },
            {
              field: 'rawBody',
              context: {
                depth: 1,
                resolution: 1,
              },
            },
          ],
        },

Would much appreciate the help! @ts-thomas

rpsirois commented 2 years ago

I can't answer your question specifically but it looks like the docs on NPM have much better information for what you're trying to do: https://npm.io/package/flexsearch.

ts-thomas commented 2 years ago

You cant apply weight/boost actually. But you can apply your own weight logic when getting back results grouped by field.

davidhq commented 1 year ago

Here it is also true that only one request with a big limit and default zero offset can be used and nothing else, right?

Cannot rely on FlexSearch pagination if doing ranking outside of it... so maybe limit=1000 and see how everything performs and that's it? I also need this feature and sorting by dates as well, will test all of this now... but please clarify if you can @ts-thomas, thank you