distinct

Type: integer | boolean
Engine default: 0 (no distinct)
Parameter syntax
'distinct' => 0|1|2|3
Parameter syntax
distinct: 0|1|2|3
Parameter syntax
distinct: 0|1|2|3
Parameter syntax
'distinct': 0|1|2|3
Parameter syntax
"distinct": 0|1|2|3
Parameter syntax
new JSONObject()
  .put("distinct", 0|1|2|3)
Parameter syntax
dynamic settings = new JObject();
settings.distinct = 0|1|2|3;
Parameter syntax
.setDistinct(Distinct.of(0|1|2|3))
Parameter syntax
"distinct": 0|1|2|3
Parameter syntax
distinct = Some(Distinct.int(0|1|2|3))

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

About this parameter

Enables de-duplication or grouping of results.

Distinct functionality is based on one attribute, as defined in attributeForDistinct. Using this attribute, you can limit the number of returned records that contain the same value in that attribute.

For example, if the distinct attribute is show_name and several hits (episodes) have the same value for show_name (for example “game of thrones”)

  • if distinct is set to 1 (de-duplication):

    • then only the most relevant episode is kept (with respect to the ranking formula); the others are not returned. The direct effect of this is to remove redundant records from your results.
  • if distinct is set to N > 1 (grouping):

    • then the N most relevant episodes for every show are kept, with similar consequences.

Usage notes:
  • For this setting to work, you need to set the distinct attribute in attributeForDistinct.

  • When set to 1, you enable de-duplication, in which only the most relevant result is returned for all records that have the same value in the distinct attribute. This is similar to the SQL distinct keyword.

  • When set to N (where N > 1), you enable grouping, in which most N hits will be returned with the same value for the distinct attribute.

  • If no distinct attribute is configured, distinct will be accepted at query time but silently ignored.

  • A 0 value disables de-duplication and grouping.

Examples

Set default distinct mode

<?php
$index->setSettings([
  'distinct' => 0
  // 'distinct' => 1
  // 'distinct' => 2
]);
index.set_settings({
  distinct: 0
  # distinct: 1
  # distinct: 2
})
index.setSettings({
  distinct: 0
  // distinct: 1
  // distinct: 2
});
index.set_settings({
  'distinct': 0
  # 'distinct': 1
  # 'distinct': 2
})
index.setSettings([
  "distinct": 0
  // "distinct": 1
  // "distinct": 2
])
index.setSettings(
  new JSONObject()
    .put("distinct", 0)
);
dynamic settings = new JObject();
settings.distinct = 0;
// settings.distinct = 1;
// settings.distinct = 2;
// settings.distinct = 3;

index.SetSettings(settings);
index.setSettings(
  new IndexSettings()
    .setDistinct(Distinct.of(0))
);
res, err := index.SetSettings(algoliasearch.Map{
  "distinct": 0,
  // "distinct": 1,
  // "distinct": 2,
})
client.execute {
  changeSettings of "myIndex" `with` IndexSettings(
    distinct = Some(Distinct.int(0))
    // distinct = Some(Distinct.int(1))
    // distinct = Some(Distinct.int(2))
  )
}
<?php
$results = $index->search('query', [
  'distinct' => 1
  // 'distinct' => 0
  // 'distinct' => 2
]);
results = index.search('query', {
  distinct: 1
  # distinct: 0
  # distinct: 2
})
index.search({
  query: 'query',
  distinct: 1
  // 'distinct: 0
  // 'distinct: 2
}).then(res => {
  // console.log(res);
});
results = index.search('query', {
  'distinct': 1
  # 'distinct': 0
  # 'distinct': 2
})
let query = Query(query: "query")
query.distinct = 1
// query.distinct = 0
// query.distinct = 2

index.search(query, completionHandler: { (res, error) in
    print(res)
})
index.search(
  new Query("query").setDistinct(1)
);
index.search(
  new Query("query").AddCustomParameter("distinct", "1")
  // new Query("query").AddCustomParameter("distinct", "0")
  // new Query("query").AddCustomParameter("distinct", "2")
);
index.search(
  new Query("query").setDistinct(1)
  // new Query("query").setDistinct(0)
  // new Query("query").setDistinct(2)
);
res, err := index.Search("query", algoliasearch.Map{
  "distinct": 1,
  // "distinct": 0,
  // "distinct": 2,
})
client.execute {
  search into "myIndex" query Query(
    query = Some("query"),
    distinct = Some(Distinct.int(1))
    // distinct = Some(Distinct.int(0))
    // distinct = Some(Distinct.int(2))
  )
}
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