<ais-configure> is a component that allows you to configure search parameters declaratively. Any Algolia search parameter can be passed as a prop and will be applied to the search.
Usage
< template >
< ais-instant-search :search-client = "searchClient" index-name = "products" >
< ais-configure
:hits-per-page.camel = "20"
:distinct = "true"
:filters = "'available = true'"
/>
< ais-hits />
</ ais-instant-search >
</ template >
< script >
import algoliasearch from 'algoliasearch/lite' ;
import { AisInstantSearch , AisConfigure , AisHits } from 'vue-instantsearch' ;
export default {
components: { AisInstantSearch , AisConfigure , AisHits } ,
data () {
return {
searchClient: algoliasearch ( 'YourApplicationID' , 'YourSearchOnlyAPIKey' ),
};
} ,
} ;
</ script >
Props
<ais-configure> accepts any valid Algolia search parameter as a prop. All props are passed directly to the Algolia search API.
When using camelCase search parameters in Vue templates, you need to use the .camel modifier (e.g., :hits-per-page.camel="20") or bind them as strings with bracket notation.
Common Search Parameters
Number of hits to retrieve per page. < ais-configure : hits-per-page . camel = " 20 " />
Filter expression to apply to the search. < ais-configure : filters = " 'category:shoes AND price < 100' " />
Filter hits by facet values. < ais-configure : facet-filters . camel = " [[ 'brand:Apple' , 'brand:Samsung' ]] " />
Filter hits by numeric attributes. < ais-configure : numeric-filters . camel = " [ 'price >= 10' , 'price <= 100' ] " />
Filter hits by tags. < ais-configure : tag-filters . camel = " [ 'featured' ] " />
Enable distinct feature to remove duplicates based on the attribute set in the index settings. < ais-configure : distinct = " true " />
List of attributes to retrieve. < ais-configure : attributes-to-retrieve . camel = " [ 'name' , 'price' , 'image' ] " />
List of attributes to highlight. < ais-configure : attributes-to-highlight . camel = " [ 'name' , 'description' ] " />
List of attributes to snippet with their maximum length. < ais-configure : attributes-to-snippet . camel = " [ 'description:50' ] " />
String to insert before highlighted parts. < ais-configure : highlight-pre-tag . camel = " '<strong>' " />
String to insert after highlighted parts. < ais-configure : highlight-post-tag . camel = " '</strong>' " />
String to use as an ellipsis indicator for snippets. < ais-configure : snippet-ellipsis-text . camel = " '...' " />
restrictHighlightAndSnippetArrays
Restrict highlighting and snippeting to matched query words only. < ais-configure : restrict-highlight-and-snippet-arrays . camel = " true " />
Specify the page to retrieve (zero-based). < ais-configure : page = " 0 " />
Specify the offset of the first hit to return. < ais-configure : offset = " 20 " />
Number of hits to return when using offset/length pagination. < ais-configure : length = " 10 " />
Search for entries around a central geolocation. < ais-configure : around-lat-lng . camel = " '40.71, -74.01' " />
Maximum radius for geo search (in meters). < ais-configure : around-radius . camel = " 5000 " />
Minimum radius for geo search (in meters). < ais-configure : minimum-around-radius . camel = " 1000 " />
Enable or disable analytics. < ais-configure : analytics = " true " />
Tags to apply to the analytics. < ais-configure : analytics-tags . camel = " [ 'mobile' , 'sale' ] " />
Enable click analytics. < ais-configure : click-analytics . camel = " true " />
Associates a user token with the search. < ais-configure : user-token . camel = " 'user-123' " />
Enable personalization. < ais-configure : enable-personalization . camel = " true " />
Enable specific query rules based on context. < ais-configure : rule-contexts . camel = " [ 'mobile' , 'sale' ] " />
Scoped Slot
The component provides a scoped slot that exposes the current search parameters and a refine function:
Current search parameters applied to the search.
Function to update search parameters programmatically.
< ais-configure : hits-per-page . camel = " 10 " >
<template v-slot="{ searchParameters, refine }">
<div>
Current hits per page: {{ searchParameters.hitsPerPage }}
<button @click="refine({ hitsPerPage: 20 })">
Show more results
</button>
</div>
</template>
</ ais-configure >
CSS Classes
When using the scoped slot, the component renders with:
ais-Configure - Root container class
Examples
Basic Configuration
< template >
< ais-instant-search :search-client = "searchClient" index-name = "products" >
< ais-configure
:hits-per-page.camel = "12"
:distinct = "true"
:click-analytics.camel = "true"
/>
< ais-search-box />
< ais-hits />
</ ais-instant-search >
</ template >
With Filters
< template >
< ais-instant-search :search-client = "searchClient" index-name = "products" >
< ais-configure
:hits-per-page.camel = "20"
:filters = "activeFilters"
/>
< ais-hits />
</ ais-instant-search >
</ template >
< script >
export default {
data () {
return {
showOnlyAvailable: true ,
};
} ,
computed: {
activeFilters () {
return this . showOnlyAvailable ? 'available = true' : '' ;
},
} ,
} ;
</ script >
Geo Search Configuration
< template >
< ais-instant-search :search-client = "searchClient" index-name = "stores" >
< ais-configure
:around-lat-lng.camel = "userLocation"
:around-radius.camel = "5000"
:hits-per-page.camel = "10"
/>
< ais-hits />
</ ais-instant-search >
</ template >
< script >
export default {
data () {
return {
userLocation: '40.7128,-74.0060' , // New York City
};
} ,
} ;
</ script >
Custom Highlighting
< template >
< ais-instant-search :search-client = "searchClient" index-name = "articles" >
< ais-configure
:attributes-to-highlight.camel = "['title', 'content']"
:attributes-to-snippet.camel = "['content:100']"
:highlight-pre-tag.camel = "'<mark class=\" highlight\ " > '"
:highlight-post-tag.camel="' </ mark > '"
/>
< ais-search-box />
< ais-hits />
</ ais-instant-search >
</ template >
Analytics Configuration
< template >
< ais-instant-search :search-client = "searchClient" index-name = "products" >
< ais-configure
:analytics = "true"
:analytics-tags.camel = "analyticsTagsList"
:click-analytics.camel = "true"
:user-token.camel = "userId"
/>
< ais-hits />
</ ais-instant-search >
</ template >
< script >
export default {
data () {
return {
userId: 'user-12345' ,
analyticsTagsList: [ 'web' , 'desktop' ],
};
} ,
} ;
</ script >
Dynamic Configuration with Scoped Slot
< template >
< ais-instant-search :search-client = "searchClient" index-name = "products" >
< ais-configure :hits-per-page.camel = "hitsPerPage" >
< template v-slot = " { searchParameters , refine } " >
< div class = "configure-panel" >
< p > Showing {{ searchParameters.hitsPerPage }} results per page </ p >
< button @click = "refine({ hitsPerPage: 10 })" > 10 </ button >
< button @click = "refine({ hitsPerPage: 20 })" > 20 </ button >
< button @click = "refine({ hitsPerPage: 50 })" > 50 </ button >
</ div >
</ template >
</ ais-configure >
< ais-hits />
</ ais-instant-search >
</ template >
< script >
export default {
data () {
return {
hitsPerPage: 20 ,
};
} ,
} ;
</ script >
Multiple Configurations for Different Indices
< template >
< ais-instant-search :search-client = "searchClient" >
< ais-index index-name = "products" >
< ais-configure
:hits-per-page.camel = "12"
:filters = "'available = true'"
/>
< ais-hits />
</ ais-index >
< ais-index index-name = "articles" >
< ais-configure
:hits-per-page.camel = "5"
:attributes-to-snippet.camel = "['content:200']"
/>
< ais-hits />
</ ais-index >
</ ais-instant-search >
</ template >
Notes
The configure state is not included in the URL when using routing. This is by design to avoid polluting the URL with technical search parameters.
Parameters set via ais-configure override any default settings from your Algolia dashboard. Make sure your configuration doesn’t conflict with index settings.