-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is this compatible with Algolia Autocomplete? #88
Comments
@edsonfeimberg I used to find this a little confusing too! It turns out that there is a library called Autocomplete.js and then there's a widget called If you are using Autocomplete.js, then you don't need this adapter to use it with Typesense, as it already supports fetching data from any async data sources. So you can use the Typesense JS library directly and make calls to the search or multi search endpoints to fetch the data from Typesense to pass on to autocomplete.js. Here's an example of how to integrate autocomplete.js with typesense. If you are using the |
Please document this!!! I'm in the same boat as the OP and was struggling to decide which is which. |
@vnugent I'm trying to implement this but I'm having a hard time converting the data received from typesense into a form that I can use |
@joker-777 You should be able to import the SearchResponseAdapter from the typesense-instantsearch-adapter and pass it the Typesense response to get an object in Algolia's response format that should work with the highlight component. |
@jasonbosco I'm trying but it doesn't work import SearchResponseAdapter from "typesense-instantsearch-adapter/lib/SearchResponseAdapter" webpack also tells me |
@jasonbosco is there a public sandbox example or a public typesense server with some dummy data which I could use to create some examples? |
@joker-777 You want to import it like this: Feel free to use this collection: https://recipe-search.typesense.org/. You'll see the API keys in the network requests. |
@jasonbosco oh wow didn't realize there was a search response adapter! I've been trying to get this to work with an algolia autocomplete custom plugin so this adapter will be super helpful. However using the import as specified above, it states there are missing declaration files :( |
@uncvrd I think that's just a warning. We don't yet publish types for that file. So if you add |
@jasonbosco Thanks a lot. I created a sandbox that shows my current problem. I can't get the highlight to work. In fact https://codesandbox.io/s/typesense-autocomplete-rkgrkr?file=/src/index.js |
@joker-777 It looks like import { autocomplete } from '@algolia/autocomplete-js';
import Typesense from 'typesense';
import { SearchResponseAdapter } from 'typesense-instantsearch-adapter/lib/SearchResponseAdapter';
import '@algolia/autocomplete-theme-classic';
const init_search_field = () => {
const client = typesense_client();
// const adapter = typesense_adapter()
autocomplete({
debug: true,
container: '#root',
getSources: ({ query }) => [
{
sourceId: 'r',
templates: {
item({ item, components, html }) {
// ======> Had to surround with a <div> to fix issues with the default CSS ===
return html`<div>
${components.Snippet({
hit: item,
attribute: 'title',
})})
</div>`;
},
},
getItems: () =>
client
.collections('r')
.documents()
.search({
q: query,
query_by: 'title',
highlight_start_tag: '__aa-highlight__', // <===== Customize highlight tags
highlight_end_tag: '__/aa-highlight__', // <===== Customize highlight tags
highlight_full_fields: 'title', // <===== Needed for Highlight component
})
.then((result) => {
return search_response_adapter(result).adapt().hits;
}),
getItemInputValue: ({ item }) => {
return item.title;
},
},
],
});
};
const search_response_adapter = (result) =>
new SearchResponseAdapter(
result,
{ params: {} },
{ geoLocationField: '_geoloc' }
);
const typesense_client = () =>
new Typesense.Client({
apiKey: 'XXX',
nodes: [
{
host: 'XXX',
port: '443',
protocol: 'https',
},
],
connectionTimeoutSeconds: 2,
});
init_search_field(); Link to code sandbox: https://codesandbox.io/s/typesense-autocomplete-forked-www6x9?file=/src/index.js Update: for the |
@jasonbosco Thanks a lot for this detailed solution it works indeed. Are you planning to support this in a more convenient way? For example, you could provide a method that basically does the following export const adaptSearchResponse = (result) => {
const adapter = new SearchResponseAdapter(
result,
{ params: {} },
{ geoLocationField: '_geoloc' }
return adapter.adapt().hits
} or simply a method that creates a |
@joker-777 I'm wondering where a method like this would go in the adapter... |
@jasonbosco Something like this master...joker-777:master (I didn't test it) Then I could just write |
For future reference, here's another way to show highlights using |
As far as my understanding goes, Instant Search and Autocomplete are treated as different things in Algolia's Instant Search documentation. My current implementation in Algolia uses the Autocomplete feature and i am trying to migrate it to Typesense, but Algolia's documentation is making me a bit confused if Autocomplete is part of instant search or not
The text was updated successfully, but these errors were encountered: