typesense-autocomplete-demo
typesense-autocomplete-demo copied to clipboard
Using querySuggestionsPlugin with Typesense
I am not sure if this is the same problem as https://github.com/typesense/typesense/issues/570 but I can not get the suggestion plugin to work with Typesense.
I think the problem is that it does not have a getSources functionality to override Algolia
The error passing the client directly is:
Cannot read properties of undefined (reading 'addAlgoliaAgent')
I somehow could go further in passing
searchClient: typesense.collections('test_index').documents()
and adding the needed q parameter in getSearchParams:
getSearchParams() {
return { q: '*' }
},
but this results in an error as the format from Algolia is different
0: {"indexName":"test_index","query":"","params":{"hitsPerPage":5,"highlightPreTag":"__aa-highlight__","highlightPostTag":"__/aa-highlight__","q":"*"}}
Did somebody ever get the querySuggestionsPlugin to work with Typesense?
@MantraMedia The querySuggestionsPlugin is an Algolia specific plugin that's built to work only with their "Query Suggestions" feature. The name sounds generic, but it's actually a feature where they build the suggestions index for you based on query history in a specific index format inside of Algolia. So this plugin requires a document structure in that format.
Alternatively, you can build a similar query history index in Typesense by capturing what users type into the search bar, send it to your backend, aggregate, deduplicate and send those to a new collection in Typesense. Then you can query that index from autocomplete.js
Another alternative is to just hit your main index and show search results in the autocomplete interface.
Here's more context: https://typesense.org/docs/guide/query-suggestions.html
Alternatively, you can build a similar query history index in Typesense by capturing what users type into the search bar, send it to your backend, aggregate, deduplicate and send those to a new collection in Typesense. Then you can query that index from autocomplete.js
@jasonbosco Why not natively implement this in the type sense API? Typesense makes it so easy to use search, yet lacks major in-build features. It's exhausting and makes users waste resources if every single typesense user has to implement this process on their end...
@polarby We recently added built-in analytics in the upcoming version. It’s already available in 0.25.0.rc46 if you want to test it out:
https://gist.github.com/jasonbosco/0c49916fc2e7a54f30d961aac111cf4a
@jasonbosco wow, that might be a game changer. I am excited!
Hello @jasonbosco What client library would you need to use to automatically populate the top queries? And additional question, does the client library prevent the top queries to be flooded with searchterms that do have search results?
@johancoens The search terms are collected and aggregated on the Typesense server-side. So this feature is agnostic to the client-library used.
As of 0.25.0, the analytics features does not track the number of results returned, only the count of unique search terms. We plan to add this in the release after the upcoming one.