Api reference icon

searchableAttributes

searchableAttributes

scope settings
type array of strings
default [] (all string attributes)
formerly known as attributesToIndex
description

List of attributes eligible for textual search.

In search engine parlance, those attributes will be “indexed”, i.e. their content will be made searchable.

If not specified or empty, all string values of all attributes are indexed. If specified, only the specified attributes are indexed; any numerical values within those attributes are converted to strings and indexed.

When an attribute is listed, it is recursively processed, i.e. all of its nested attributes, at any depth, are indexed according to the same policy.

Make sure you adjust this setting to get optimal results.

This parameter has two important uses:

  1. Limit the scope of the search. Restricting the searchable attributes to those containing meaningful text guarantees a better relevance. For example, if your objects have associated pictures, you need to store the picture URLs in the records in order to retrieve them for display at query time, but you probably don’t want to search inside the URLs.

    A side effect of limiting the attributes is increased performance: it keeps the index size at a minimum, which has a direct and positive impact on both build time and search speed.

  2. Control part of the ranking. The contents of the searchableAttributes parameter impacts ranking in two complementary ways:

    • Attribute priority: The order in which attributes are listed defines their ranking priority: matches in attributes at the beginning of the list will be considered more important than matches in attributes further down the list.

      To assign the same priority to several attributes, pass them within the same string, separated by commas. For example, by specifying ["title,alternative_title", "text"], title and alternative_title will have the same priority, but a higher priority than text.

    • Importance of word positions: Within a given attribute, matches near the beginning of the text are considered more important than matches near the end. You can disable this behavior by wrapping your attribute name inside an unordered() modifier. For example, ["title", "unordered(text)"] will consider all positions inside the text attribute as equal, but positions inside the title attribute will still matter.

To get a full description of how the ranking works, you can have a look at our Ranking guide.

Examples

Set searchableAttributes

The following example shows how to:

  • make some attributes searchable
  • put several attributes at the same level
  • make an attribute as unordered
<?php
$index->setSettings([
  'searchableAttributes' => [
    "title,alternative_title",
    "author",
    "unordered(text)"
  ]
]);
index.set_settings({
  searchableAttributes: [
    "title,alternative_title",
    "author",
    "unordered(text)"
  ]
})
index.setSettings({
  searchableAttributes: [
    'title,alternative_title',
    'author',
    'unordered(text)'
  ]
});
index.set_settings({
    'searchableAttributes': [
        'title,alternative_title',
        'author',
        'unordered(text)'
    ]
})
index.setSettings([
    "searchableAttributes": [
        "title,alternative_title",
        "author",
        "unordered(text)"
    ]
])
index.setSettings(new JSONObject().put("searchableAttributes",
    new JSONArray().put("title,alternative_title").put("author").put("unordered(text)")));
index.SetSettings(
  JObject.Parse(@"{""searchableAttributes"":[""title,alternative_title"",""author"",""unordered(text)""]}")
);
index.setSettings(
  new IndexSettings().setSearchableAttributes(Arrays.asList(
    "title,alternative_title",
    "author",
    "unordered(text)"
  ))
);
res, err := index.SetSettings(algoliasearch.Map{
    "searchableAttributes": []string{
        "title,alternative_title",
        "author",
        "unordered(text)",
    },
})
client.execute {
  changeSettings of "myIndex" `with` IndexSettings(
    searchableAttributes = Some(Seq(
      SearchableAttributes.attributes("title", "alternative_title")
      SearchableAttributes.attribute("author")
      SearchableAttributes.unordered("text")
    ))
  )
}