optionalFilters

Type: list of strings
Engine default: []
Parameter syntax
'optionalFilters' => [
  'attribute:value',
  '[attribute1:value, attribute2:value]', // 1 AND 2
  '[attribute1:value, attribute2:value], attribute3:value', // (1 AND 2) OR 3
  ...
]
Parameter syntax
optionalFilters: [
  'attribute:value',
  '[attribute1:value, attribute2:value]', # 1 AND 2
  '[attribute1:value, attribute2:value], attribute3:value', # (1 AND 2) OR 3
]
Parameter syntax
optionalFilters: [
  'attribute:value',
  '[attribute1:value, attribute2:value]', // 1 AND 2
  '[attribute1:value, attribute2:value], attribute3:value', // (1 AND 2) OR 3
]
Parameter syntax
'optionalFilters': [
  'attribute:value',
  '[attribute1:value, attribute2:value]', # 1 AND 2
  '[attribute1:value, attribute2:value], attribute3:value', # (1 AND 2) OR 3
]
Parameter syntax
let requestOptions = RequestOptions()
requestOptions.urlParameters["optionalFilters"] = [
  "attribute:value",
  "[attribute1:value, attribute2:value]", // 1 AND 2
  "[attribute1:value, attribute2:value], attribute3:value", // (1 AND 2) OR 3
]
Parameter syntax
.set(
  "optionalFilters",
  new JSONArray()
    .put("attribute:value")
    .put("[attribute1:value, attribute2:value]") // 1 AND 2
    .put("[attribute1:value, attribute2:value], attribute3:value") // (1 AND 2) OR 3
)
Parameter syntax
dynamic optionalFilters = new JArray(new string[] {
  "attribute:value",
  "[attribute1:value, attribute2:value]", // 1 AND 2
  "[attribute1:value, attribute2:value], attribute3:value", // (1 AND 2) OR 3
});

.AddExtraQueryParameters(
  "optionalFilters", optionalFilters.ToString()
)
Parameter syntax
.addCustomParameter(
  "optionalFilters",
  Arrays.asList(
    "attribute:value",
    "[attribute1:value, attribute2:value]", // 1 AND 2
    "[attribute1:value, attribute2:value], attribute3:value", // (1 AND 2) OR 3
  )
)
Parameter syntax
"optionalFilters": []string{
  "attribute:value",
  "[attribute1:value, attribute2:value]", // 1 AND 2
  "[attribute1:value, attribute2:value], attribute3:value", // (1 AND 2) OR 3
}
Parameter syntax
"optionalFilters" -> Some(Seq(
  "attribute:value",
  "[attribute1:value, attribute2:value]", // 1 AND 2
  "[attribute1:value, attribute2:value], attribute3:value", // (1 AND 2) OR 3
))

Can be used in these methods:
search, browseObjects, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey search, browse, search_for_facet_values, generate_secured_api_key, add_api_key, update_api_key search, browse, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey search, browse, search_for_facet_values, generate_secured_api_key, add_api_key, update_api_key search, browse, searchForFacetValues searchAsync, browseAsync, searchForFacetValues Search, Browse, SearchForFacetValues, GenerateSecuredApiKey, AddApiKey, UpdateApiKey Search, browse, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey Search, Browse, SearchForFacetValues, GenerateSecuredAPIKey, AddAPIKey, UpdateAPIKey search, browse index, search into facet values, generateSecuredApiKey, add key, update key

About this parameter

Create filters for ranking purposes, where records that match the filter are ranked highest.

Optional filtering behaves like normal filters, meaning that it returns records that match both the query and the filters. However, it also returns records that do not match the filters. The effect is on the ranking: records matching the filters are ranked higher than records that do not match the filters.


Usage notes:
  • The boolean syntax is the same as facetFilters, except for negative syntax. If you use negative syntax, for example categories:-Book, it will not work; it will be transformed into categories:Book.

  • Promoting results: See how you can use optionalFilters to promote filters and facets.

  • Ranking Formula: This setting will only work if the Filters criterion is part of the ranking. Filters is by default part of the ranking; so if you’ve removed it, and yet wish to use option filters, you’ll need to add it back to the ranking formula.

Optional filters are not available on legacy plans (Starter, Growth, Pro). If you are on one of these plans and want to benefit from this feature, you will need to move to a new plan. Additionally, Community, Essential, and Plus plans are limited to only one optionalFilters per query, while Business and Enterprise plans are unlimited.

Examples

Apply optional filters on a search query

<?php
$results = $index->search('query', [
  'optionalFilters' => [
    "category:Book",
    "author:John Doe"
  ]
]);
results = index.search('query', {
  optionalFilters: [
    'category:Book',
    'author:John Doe'
  ]
})
index.search({
  query: 'query',
  optionalFilters: [
    'category:Book',
    'author:John Doe'
  ]
}).then(res => {
  // console.log(res);
});
results = index.search('query', {
    'optionalFilters': [
      'category:Book',
      'author:John Doe'
    ]
})
let requestOptions = RequestOptions()
requestOptions.urlParameters["optionalFilters"] = [
  "category:Book",
  "author:John Doe"
]

index.search(Query(), requestOptions: requestOptions) { (content, error) in
   if error == nil {
        print(content)
   }
}
index.search(new Query("query").set(
  "optionalFilters",
  new JSONArray().put("category:Book").put("author: John Doe")
);
let query = Query(query: "query");

var requestOptions = new RequestOptions().AddExtraQueryParameters(
  "optionalFilters", Uri.EscapeUriString("[\"category:Book\",\"author:John Doe\"]")
);

var res = index.search(query, requestOptions);

Console.Writeline(res);
index.search(
  new Query("query").addCustomParameter(
    "optionalFilters",
    Arrays.asList(
      "category:Book",
      "author:John Doe"
    ))
);
res, err := index.Search("query", algoliasearch.Map{
    "optionalFilters": []string{
        "category:Book",
        "author:John Doe",
    },
})
client.execute {
  search into "myIndex" query Query(
    customParameters = Some(
      Map(
        "optionalFilters" -> Some(Seq(
          "category:Book",
          "author:John Doe"
        ))
      )
    )
}
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala