> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# restrictSearchableAttributes

> Limits the search to a subset of your searchable attributes

export const Setting = ({type, default: defaultValue, defaultNote, scope, min, max, formerly}) => {
  const renderedDefault = defaultValue === '' ? '""' : defaultValue;
  const renderedNote = defaultNote ? `(${defaultNote})` : '';
  return <ul>
      <li><strong>Type:</strong> <code>{type}</code></li>
      <li><strong>Default:</strong> <code>{renderedDefault}</code>{renderedNote}</li>
      {min && <li><strong>Min:</strong> <code>{min}</code></li>}
      {max && <li><strong>Max:</strong> <code>{max}</code></li>}
      <li><strong>Scope:</strong> <a href="/doc/api-reference/api-parameters"><code>{scope}</code></a></li>
      {formerly && <li>
          <strong>Deprecated name:</strong> <code>{formerly}</code>
        </li>}
    </ul>;
};

<Setting type="list<string>" default="[]" defaultNote="all searchable attributes" scope="search" />

## Usage

## Usage

* Attribute names are case-sensitive.
* This parameter only works if [`searchableAttributes`](/doc/api-reference/api-parameters/searchableAttributes) isn't empty or `null`.

This setting doesn't support:

* Target attributes from a comma-separated list of attributes within [`searchableAttributes`](/doc/api-reference/api-parameters/searchableAttributes).
  For example, if your `searchableAttributes` is set to `['title, category', 'content']`,
  you can restrict searches to `"content"`, but not to `"title"` or `"category"` individually, or to `"title,category"`.
* Change the ranking priority of matched attributes.
  For example, if `searchableAttributes` is `["title", "category", "content"]`
  and you restrict the search to `["category", "title"]`,
  matches in the `title` attribute still rank higher than matches in `category`.
* Apply or override [`searchableAttributes`](/doc/api-reference/api-parameters/searchableAttributes) modifiers such as `unordered`.
  This parameter only accepts attribute names.
  For example, if you configured `unordered(title)` in `searchableAttributes`,
  restrict the search with `["title"]`, not `["unordered(title)"]`.

## Example

The following example restricts the search to the `title` and `author` attributes,
even if your `searchableAttributes` setting includes more.

<AccordionGroup>
  <Accordion title="Current API clients" defaultOpen="true">
    <CodeGroup>
      ```cs C# theme={"system"}
      var response = await client.SearchSingleIndexAsync<Hit>(
        "INDEX_NAME",
        new SearchParams(
          new SearchParamsObject
          {
            Query = "query",
            RestrictSearchableAttributes = new List<string> { "title", "author" },
          }
        )
      );
      ```

      ```dart Dart theme={"system"}
      final response = await client.searchSingleIndex(
        indexName: "INDEX_NAME",
        searchParams: SearchParamsObject(
          query: "query",
          restrictSearchableAttributes: [
            "title",
            "author",
          ],
        ),
      );
      ```

      ```go Go theme={"system"}
      response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
        "INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
        search.NewEmptySearchParamsObject().SetQuery("query").SetRestrictSearchableAttributes(
          []string{"title", "author"}))))
      if err != nil {
        // handle the eventual error
        panic(err)
      }
      ```

      ```java Java theme={"system"}
      SearchResponse response = client.searchSingleIndex(
        "INDEX_NAME",
        new SearchParamsObject().setQuery("query").setRestrictSearchableAttributes(Arrays.asList("title", "author")),
        Hit.class
      );
      ```

      ```js JavaScript theme={"system"}
      const response = await client.searchSingleIndex({
        indexName: 'indexName',
        searchParams: { query: 'query', restrictSearchableAttributes: ['title', 'author'] },
      });
      ```

      ```kotlin Kotlin theme={"system"}
      var response =
        client.searchSingleIndex(
          indexName = "INDEX_NAME",
          searchParams =
            SearchParamsObject(
              query = "query",
              restrictSearchableAttributes = listOf("title", "author"),
            ),
        )
      ```

      ```php PHP theme={"system"}
      $response = $client->searchSingleIndex(
          'INDEX_NAME',
          ['query' => 'query',
              'restrictSearchableAttributes' => [
                  'title',

                  'author',
              ],
          ],
      );
      ```

      ```python Python theme={"system"}
      response = client.search_single_index(
          index_name="INDEX_NAME",
          search_params={
              "query": "query",
              "restrictSearchableAttributes": [
                  "title",
                  "author",
              ],
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      response = client.search_single_index(
        "INDEX_NAME",
        Algolia::Search::SearchParamsObject.new(query: "query", restrict_searchable_attributes: ["title", "author"])
      )
      ```

      ```scala Scala theme={"system"}
      val response = Await.result(
        client.searchSingleIndex(
          indexName = "INDEX_NAME",
          searchParams = Some(
            SearchParamsObject(
              query = Some("query"),
              restrictSearchableAttributes = Some(Seq("title", "author"))
            )
          )
        ),
        Duration(100, "sec")
      )
      ```

      ```swift Swift theme={"system"}
      let response: SearchResponse<Hit> = try await client.searchSingleIndex(
          indexName: "INDEX_NAME",
          searchParams: SearchSearchParams.searchSearchParamsObject(SearchSearchParamsObject(
              query: "query",
              restrictSearchableAttributes: ["title", "author"]
          ))
      )
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```cs C# theme={"system"}
      index.Search(new Query("query")
      {
          RestrictSearchableAttributes = new List{ "title", "author" }
      });
      ```

      ```go Go theme={"system"}
      res, err := index.Search(
      	"query",
      	opt.RestrictSearchableAttributes(
      		"title",
      		"author",
      	),
      )
      ```

      ```java Java theme={"system"}
      index.search(
        new Query("query").setRestrictSearchableAttributes(Arrays.asList(
          "title",
          "author"
        ))
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .search("query", {
          restrictSearchableAttributes: ["title", "author"],
        })
        .then(({ hits }) => {
          console.log(hits);
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val query = query("query") {
          restrictSearchableAttributes {
              +"title"
              +"author"
          }
      }

      index.search(query)
      ```

      ```php PHP theme={"system"}
      $results = $index->search('query', [
        'restrictSearchableAttributes' => [
          'title',
          'author'
        ]
      ]);
      ```

      ```python Python theme={"system"}
      results = index.search("query", {"restrictSearchableAttributes": ["title", "author"]})
      ```

      ```ruby Ruby theme={"system"}
      results = index.search(
        "query",
        {
          restrictSearchableAttributes: [
            "title",
            "author"
          ]
        }
      )
      ```

      ```scala Scala theme={"system"}
      client.execute {
        search into "myIndex" query Query(
          query = Some("query"),
          restrictSearchableAttributes = Some(Seq(
            "title",
            "author"
          ))
        )
      }
      ```

      ```swift Swift theme={"system"}
      let query = Query("query")
        .set(\.restrictSearchableAttributes, to: [
          "title",
          "author"
        ])

      index.search(query: query) { result in
        if case .success(let response) = result {
          print("Response: \(response)")
        }
      }
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>
