attribute
method.
The attribute
method
The attribute
method defines which model attributes to index.
- If you pass one or more symbols, it calls the methods with the same name.
- If you pass it a block, you can only use one symbol to define the attribute name. The block defines the value.
attributes
is an alias forattribute
- You can call both methods multiple times
Ruby
The add_attribute
method
You can use the add_attribute
and add_attributes
methods,
if you want to add new attributes to your records.
Ruby
Custom object IDs
Every Algolia record needs anobjectID
.
By default, this gem uses Rails id
as the Algolia objectID
.
To use a custom ID, use the id
option.
Each objectID
must be unique in the index, or your records might be overwritten or deleted by other models.
The id
can be a model attribute or you can define your own attribute.
Ruby
Ruby
Helpers
Thealgoliasearch-rails
gem comes with helpers for special Algolia attributes.
To detect changes for these helpers,
see tags
and geoloc
helpers.
Coordinates for location search
Adding coordinates to your records lets you search by location.Ruby
Tags
The_tags
attribute is required for filtering by tags.
You use any attribute for filtering if you configure it in the settings.
Ruby
Ruby
Sanitize HTML
To remove all HTML tags from your attributes, use thesanitize
options.
Ruby
UTF-8 encoding
To make all your attributes UTF-8 encoded, use theforce_utf8_encoding
option.
Ruby
Serialization with ActiveModelSerializers
You can use ActiveModelSerializers to extract all logic for creating your records into a separate class. In thealgoliasearch
block, specify what class to use with use_serializer
.
If specified, all attribute(s)
methods are ignored.
You can still use add_attribute(s)
and the tags
or geoloc
helpers.
Ruby