When setting up and configuring your index, the first step is to decide which attributes you want to use for searching.
When you create an index, all attributes in all your records are searchable by default.
This means you can perform searches straight away without configuring anything.
However, to enhance search relevance and exclude unnecessary results, you should specify which attributes should be searchable.
An example of a useful searchable attribute is the name of a product.
An example of an attribute that isn’t useful for searching is a URL. Since users seldom search for URLs, exclude them from the searchable attributes list. However, you can still use image URLs to display images in the results.
For example, on a recipes website it makes sense to make title, ingredients, and comments searchable, and exclude images.
You can still use non-searchable attributes for display or filtering.
Attributes to include
The following attributes are commonly included (searchable):
Descriptive attributes: name, description, brand, list of actors in a film, list of features in a computer.
Filters: color, brand, size.
Keywords and tags.
Valuable data like telephone numbers, SKU, ISBN, and other identifying attributes.
Attributes to exclude
These are often excluded (not searchable):
For display only: image and other URLs, price, brand logos, SKU.
Short descriptions are meant to be displayed, not searched since they usually summarize what’s in a longer description.
For information only: not yet available, just released, on promotion.
For ranking only: most sales, most viewed, highest rated.
Set searchable attributes
Specify searchable attributes from the dashboard or API.
Set searchable attributes in the Algolia dashboard
On the Configuration tab, select Searchable attributes.
Click Add a Searchable Attribute and type or select an attribute from the list.
Change the order of attributes by dragging them up or down in the Searchable attributes list.
To make two attributes equally important, when you add a new attribute,
type the attributes directly as a comma-separated list—for example, title, comments.
Save your changes.
Set searchable attributes with the API
To make certain attributes searchable, include them in the searchableAttributes setting when configuring your index with the setSettings method.
// `title` and `comments` have the same priority$index->setSettings(['searchableAttributes'=>["title,comments","ingredients"]]);// `title` has the highest priority, then `ingredients`, then `comments`$index->setSettings(['searchableAttributes'=>["title","ingredients","comments"]]);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# `title` and `comments` have the same priorityindex.set_settings({searchableAttributes: ['title,comments','ingredients']})# `title` has the highest priority, then `ingredients`, then `comments`index.set_settings({searchableAttributes: ['title','ingredients','comments']})
// `title` and `comments` have the same priorityindex.setSettings({searchableAttributes:['title,comments','ingredients']}).then(()=>{// done});// `title` has the highest priority, then `ingredients`, then `comments`index.setSettings({searchableAttributes:['title','ingredients','comments']}).then(()=>{// done});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# `title` and `comments` have the same priority
index.set_settings({'searchableAttributes':['title,comments','ingredients']})# `title` has the highest priority, then `ingredients`, then `comments`
index.set_settings({'searchableAttributes':['title','ingredients','comments']})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// `title` and `comments` have the same priorityindex.setSettings(["searchableAttributes":["title,comments","ingredients"]])// `title` has the highest priority, then `ingredients`, then `comments`index.setSettings(["searchableAttributes":["title","ingredients","comments"]])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// "title" and "comments" have the same priorityvarsettings=settings{searchableAttributes{+"title,comments"+"ingredients"}}// "title" has the highest priority, then "ingredients", then "comments"settings=settings{searchableAttributes{+"title"+"ingredients"+"comments"}}index.setSettings(settings)
// `title` and `comments` have the same priorityIndexSettingssettings=newIndexSettings{SearchableAttributes=newList<string>{"title,comments","ingredients"}};// `title` has the highest priority, then `ingredients`, then `comments`IndexSettingssettings=newIndexSettings{SearchableAttributes=newList<string>{"title","ingredients","comments"}};index.SetSettings(settings);// Asynchronousawaitindex.SetSettingsAsync(settings);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// `title` and `comments` have the same priorityindex.setSettings(newIndexSettings().setSearchableAttributes(Arrays.asList("title,comments","ingredients")));// `title` has the highest priority, then `ingredients`, then `comments`index.setSettings(newIndexSettings().setSearchableAttributes(Arrays.asList("title","ingredients""comments",)));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// `title` and `comments` have the same priorityres,err:=index.SetSettings(search.Settings{SearchableAttributes:opt.SearchableAttributes("title,comments","ingredients",),})// `title` has the highest priority, then `ingredients`, then `comments`res,err:=index.SetSettings(search.Settings{SearchableAttributes:opt.SearchableAttributes("title","ingredients","comments",),})
// `title` and `comments` have the same priorityclient.execute{setSettingsof"myIndex"`with`IndexSettings(searchableAttributes=Some(Seq(SearchableAttributes.attributes("title","comments"),SearchableAttributes.attribute("ingredients"))))}// `title` has the highest priority, then `ingredients`, then `comments`client.execute{setSettingsof"myIndex"`with`IndexSettings(searchableAttributes=Some(Seq(SearchableAttributes.attributes("title"),SearchableAttributes.attribute("ingredients"),SearchableAttributes.unordered("comments"))))}
In the first example, title and comments have the same priority.
In the second example, matches in the title attribute rank before matches in the comments attribute.