Usage


This module exposes composables that are auto-imported by Nuxt 3.

For more details check out the official documentation of initializing algolia client here

useAlgoliaSearch

Use this composable to search the index by certain query and optional request options

<script setup>const { result, search } = useAlgoliaSearch('test_index') // pass your index name as paramonMounted(async () => {  await search({ query: 'Samsung' });})</script>
  • result will contain a value of a search method. It is reactive computed property that will be populated when a search method will fulfill. This result will have a form described here
  • search method is used to fetch the results by the index and populates result reactive property. This method requires a parameter query and accepts an optional parameter of requestOptions that you can check out here

For more details check out the official documentation of this method here

useAlgoliaFacetedSearch

Use this composable to search using facet values like category, phone.

In order for this to work, you have to add facet attributes in your dashboard or via code. Read more about it here
<script setup>const { result, search } = useAlgoliaFacetedSearch('test_index')onMounted(async () => {  const facet = {     name: 'category',    query: 'phone'   }  await search({ facet })})</script>
  • result will contain a value of a search method. It is reactive computed property that will be populated when a search method will fulfill. This result will have a form described here
  • search method is used to fetch the results by the certain facet value pairs like name and query, and populates result reactive property. This method requries a parameter for facet and accepts an optional parameter of requestOptions that you can check out here

For more details about using this search method check out the official documentation here

useAlgoliaRecommend

Use this composable to get the recommendations matching certain criteria optional request options.

In order to make this composable work, make sure to setup a recommend property to true in algolia configuration in nuxt.config.ts.
<script setup>const { result, get } = useAlgoliaRecommend()onMounted(async () => {  await get({ queries: [{ indexName: 'test_index', model: 'related-products', objectID: 'dca44dd5-aea6-4553-a3af-fcbda981a2ef' }] });})</script>
  • result will contain a value of a get method. It is reactive computed property that will be populated when a get method will fulfill. This result will have a form described here
  • get method is used to get the recommendations based on the criteria described here and an optional parameter of requestOptions that you can check out here

For more details check out the official documentation of this method here

useAlgoliaRef

By calling this composable you have access to algoliasearch instance anywhere in your app

<script setup>const algolia = useAlgoliaRef()</script>

useAlgoliaInitIndex

Use this composable to initialize index you would like to search through. It accepts an index name as a parameter

<script setup>const algoliaIndex = useAlgoliaInitIndex('test')console.log(algoliaIndex.appId)</script>

For more details about initializing index check out the official documentation here