askorama / orama

🌌 Fast, dependency-free, full-text and vector search engine with typo tolerance, filters, facets, stemming, and more. Works with any JavaScript runtime, browser, server, service!
https://docs.orama.com
Other
8.53k stars 285 forks source link

OramaPlugin for vitepress, additional options. #742

Open lazarusA opened 3 months ago

lazarusA commented 3 months ago

Problem Description

At the moment, it looks like the plugin for vitepress only accepts analytics as a known options field. However, it looks like more options could be added, like schema, searchOptions, etc...

Proposed Solution

Currently, I was expecting this to work (without success) :

  vite: {
    plugins: [OramaPlugin({
      schema: {
        title: 'string',
        content: 'string',
        functionNames: 'string[]',
      },
      searchOptions: {
        boost: {
          title: 2,
          functionNames: 3,
        },
      },
      contentTransformer: (content) => {
        // This regex matches patterns like Name.func1 or Name1.name2.func2
        const regex = /(?:^|\s)((?:\w+\.)+(\w+))/g;
        const matches = [...content.content.matchAll(regex)];
        const functionNames = matches.map(match => match[2]); // Capture the last word after the period

        return {
          ...content,
          functionNames: [...new Set(functionNames)], // Remove duplicates
        }
      },
    })],
  },

any hints on how to achieved this? maybe a workaround?

Alternatives

No response

Additional Context

No response