leo-buneev / vuepress-plugin-fulltext-search

Adds full-text search capabilities to your vuepress site with a help of flexsearch library.
MIT License
93 stars 23 forks source link

add support for hooks functions, setting query from URL, search exclusion #10

Closed bobheadxi closed 3 years ago

bobheadxi commented 4 years ago
leo-buneev commented 4 years ago

Thanks! That feature looks sweet, let's make it official.

I'd prefer to add more abstract hook processSuggestions(suggestions, queryString, queryTerms) in vuepress's settings, that will return new array of suggestions - can be useful for many scenarios, including yours.

Will be awesome if you'll find time to prepare it.

bobheadxi commented 4 years ago

@leo-buneev I'd be happy to - will update this PR and ping you with a nicer implementation 🚀

bobheadxi commented 4 years ago

@leo-buneev unfortunately, 5279837 is the only practical way to implement this API within the Vuepress plugin framework - let me know what you think! You can see one use case at https://github.com/ubclaunchpad/docs/pull/84

Personally, I don't think it's too bad - vuepress still throws up fairly informative errors on syntax mistakes within the code. You could also do things like using readFileSync to provide the function string

bobheadxi commented 4 years ago

@leo-buneev I tried out the readFileSync approach in my usage of this branch (https://github.com/ubclaunchpad/docs/pull/84) and it works very nicely - see https://github.com/leo-buneev/vuepress-plugin-fulltext-search/pull/10/commits/bdfea2eb6f2bbcebe06391051201c2589c767102 for the updated docs:

const fs = require('fs');
const { path } = require('@vuepress/shared-utils');
module.exports = {
  plugins: [
    ['fulltext-search', {
      processSuggestions: fs.readFileSync(path.resolve(__dirname, 'processSuggestions.js')),
    }],
  ]
}
leo-buneev commented 4 years ago

Wow, that looks more complicated than I thought. Later today I'll try to implement option as a regular function (still can't believe it isn't possible 😮), and if I'll be unsuccessfull will merge your PR. Thank you!

bobheadxi commented 4 years ago

Yeah I couldn't find a way to "persist" a user-provided function for callback :(

bobheadxi commented 4 years ago

@leo-buneev For our purposes I've expanded the API in fdeed1f to allow an onclick callback as well - I made the poor choice of opening the PR from a master branch, so please let me know if you would like me to make more granular PRs or just continue expanding on this feature in my fork :)

leo-buneev commented 4 years ago

Feel free to continue here, it can be considered as part of the same feature

bobheadxi commented 3 years ago

@leo-buneev any chance this might land one day? :) We've been running this in https://docs.ubclaunchpad.com with some non-trivial traffic for quite a while, and am quite content with the API defined here.

bobheadxi commented 3 years ago

@leo-buneev I've cleaned up the PR description and documentation!