Use Algolia’s UI libraries, InstantSearch and Autocomplete, for client-side searching.
Search requests are made from the browser or app, and results are returned without going through your server.
This ensures rapid searching.For more information, see:
Sometimes, backend search can be more suitable.
The search request goes from your server to Algolia.Algolia sends the response back to your server, where you can process it.
# Query and search parametersp(Contact.search("jon doe", {hitsPerPage: 5, page: 2}))
If you always pass the same parameters,
set them as index settings.
Ruby
Report incorrect code
Copy
class Contact < ActiveRecord::Base include AlgoliaSearch algoliasearch do # Default search parameters stored in the index settings minWordSizefor1Typo 4 minWordSizefor2Typos 8 hitsPerPage 42 endend
Every ORM object of the response contains the highlighted text for the search query.
This corresponds to the highlight_result attribute in Algolia’s raw response.
If you have more facet values than what can fit in your UI,
it can be helpful to let users search for them.If you want to support searching for facet values, configure the facet as
searchable.
Ruby
Report incorrect code
Copy
# Array of {value, highlighted, count}Product.search_for_facet_values("category", "Headphones")
This method accepts search parameters, such as filters.
Ruby
Report incorrect code
Copy
# Only sends back the categories containing red Apple products (and only counts those)Product.search_for_facet_values( "category", "phone", { query: "red", filters: "brand:Apple" # Array of phone categories linked to red Apple products })