Index settings
Index names
Index names are derived from the class names.
To customize the index names, pass a string to the index_name
option.
1
2
3
4
5
6
7
class Contact < ActiveRecord::Base
include AlgoliaSearch
algoliasearch index_name: "MyCustomName" do
attribute :first_name, :last_name, :email
end
end
Production and staging indices
To avoid changing your production index,
you can append the current Rails environment to the index name with the per_environment
option.
This creates separate indices with names following the pattern MODEL_ENVIRONMENT
.
1
2
3
4
5
6
7
class Contact < ActiveRecord::Base
include AlgoliaSearch
algoliasearch per_environment: true do
attribute :first_name, :last_name, :email
end
end
To make it even harder to overwrite your production data,
you should use different API keys in development and production.
You can restrict access of your development API key to indices with names ending with _development
.
For more information, see API keys restrictions.
Basic relevance settings
To set a baseline for your index, define which attributes should be searchable and define a custom ranking.
1
2
3
4
5
6
7
8
9
10
11
12
13
class Product < ActiveRecord::Base
include AlgoliaSearch
algoliasearch do
# List of attributes used to build an Algolia record
attributes :title, :subtitle, :description, :likes_count, :thumbnail_url, :release_date
searchableAttributes ['title', 'subtitle', 'unordered(description)']
customRanking ['desc(likes_count)']
end
end
Faceting and filtering
Add all attributes you want to use for filtering as facets.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Product < ActiveRecord::Base
include AlgoliaSearch
algoliasearch do
# List of attributes used to build an Algolia record
attributes :title, :subtitle, :likes_count, :ratings, :categories, :features, :sizes
# ... Other settings removed for brevity
attributesForFaceting ['searchable(categories)', 'features', 'sizes']
numericAttributesForFiltering ['likes_count', 'equalOnly(ratings)']
end
end
Synonyms
You can define regular synonyms where all words are considered equivalent.
1
2
3
4
5
6
7
8
9
10
class Contact < ActiveRecord::Base
include AlgoliaSearch
algoliasearch do
attributes :first_name, :email
synonyms [ ['bob', 'bobby' 'robert'] ]
end
end
To define other types of synonyms,
directly call the saveSynonyms
method on the model’s index.
Sync your settings with Algolia
By default, your settings will be synced with Algolia.
Turn off automatic syncing
If you turn off automatic syncing, make sure to manually send updates to Algolia whenever you change your settings.
1
2
3
4
5
6
7
class Musician < ActiveRecord::Base
include AlgoliaSearch
algoliasearch check_settings: false do
searchableAttributes ['name', 'band']
end
end
Apply all settings
To send settings updates for all indices, use the set_all_settings
rake command.
It sends updates to your primary indices, your replicas, and any indices you added with add_index
.
Consider adding this command to your deployment pipeline, especially if you turned off automatic settings updates.
1
rake algoliasearch:set_all_settings