Skip to content

Add hook/callback on searches #36

@KieranHunt

Description

@KieranHunt

Hey!

Thanks for the great library!

We have some analytics running on our VuePress site. Currently, we're just collecting page views but would like to extend that to collect search terms too. We'll use that to align our documentation to what people are actually searching for.

What are you feelings on adding a hook to this plugin that gets called on every search? That'll be a great extension point for us to emit our metrics.

I was thinking something like this:

[
  "flexsearch",
  {
    search_options: {
      encode: "balance",
      tokenize: "reverse",
      threshold: 0,
      resolution: 3,
      depth: 3,
      doc: {
        id: "key",
        field: ["title", "headers", "content"],
      },
    },
    callbacks: {
      onSearch: (someObjectRepresentingTheSearch) => {
        // emit metrics here
      }
    }
  },
]

I don't mind doing the work, I just wanted your input whether this is something you'd like in the library and what the API should look like.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions