#community-help

TypesenseInstantsearchAdapter and Algolia Query

TLDR Jordan had issues with utilizing Algolia's helper method after creating the TypesenseInstantsearchAdapter. Jason clarified that this adapter is unnecessary with Autocomplete.js. The correct approach is to use the typesense-js library directly.

Powered by Struct AI

1

7
22mo
Solved
Join the chat
Mar 16, 2022 (22 months ago)
Jordan
Photo of md5-ad648f0416b0aa480b934e45bcc719ee
Jordan
07:28 PM
Hi all - quick question. After creating the TypesenseInstantsearchAdapter, we should be able to utilize algolia's getAlgoliaResults helper method (docs ref here) to query for results in an algolia autocomplete widget correct? Looking at my network tab, I only see one network request and it's a query with a wildcard parameter instead of my query string in the input. Posting code in the thread...one sec
07:29
Jordan
07:29 PM
here's my adapter, i then pass this client to a react component
const typesenseSearchAdapter = new TypesenseInstantsearchAdapter({
  server: {
    apiKey: "REDACTED",
    nodes: [
      {
        host: "localhost",
        port: 8108,
        protocol: "http"
      }
    ],
  },
  additionalSearchParameters: {
    query_by: "title"
  },
})

const searchClient = typesenseSearchAdapter.searchClient;
07:30
Jordan
07:30 PM
<AutocompleteSearch
  autoCompleteProps={{
    searchClient,
    getSources({ query }) {
      return [
        {
          sourceId: "tracks",
          getItems() {
            return getAlgoliaResults({
              searchClient,
              queries: [
                {
                  indexName: "tracks",
                  query
                }
              ]
            })
          },
          templates: {
            item({ item, components }) {
              return (
                <div>response</div>
              )
            }
          }
        }
      ]
    }
  }}
/>

my AutocompleteSearch component is defined using the algolia example here
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:32 PM
Jordan The typesense-instantsearch-adapter is only needed if you're using react-instantsearch.

With Autocomplete.js you don't need the adapter. Instead, you want to use the typesense-js library directly inside of getItems()
07:33
Jason
07:33 PM
instead of calling getAlgoliaResults
Jordan
Photo of md5-ad648f0416b0aa480b934e45bcc719ee
Jordan
07:35 PM
oh I see! thank you so much for clarifying. That makes a lot more sense

1