attributeForDistinct
null
'attributeForDistinct' => 'attribute'
Can be used in these methods:
setSettings
set_settings
setSettings
set_settings
setSettings
setSettings
SetSettings
setSettings
SetSettings
setSettings
About this parameter
Name of the attribute to deduplicate or group records.
The attributeForDistinct
attribute works in combination with distinct
:
attributeForDistinct
establishes groups: all records with the same value ofattributeForDistinct
are treated as a group.distinct
determines how many variants per group are included in the search results.
Usage notes
- You can define only one attribute for distinct.
- You can only set
attributeForDistinct
at indexing time. You can’t set or override it at query time. - The
attributeForDistinct
attribute expects strings or numbers as values:- Number values are rounded to the nearest integer and converted to their string representation,
for example,
1
and1.2
both turn into"1"
. - String values are used as they are.
- Boolean or null values are ignored.
- Array and object values aren’t supported and result in unspecified behavior.
- Number values are rounded to the nearest integer and converted to their string representation,
for example,
Examples
Set the attribute to distinct
The following example declares the url
attribute as attributeForDistinct
.
To deduplicate or group records based on this attribute, you also have to set the distinct
parameter.
1
2
3
$index->setSettings([
'attributeForDistinct' => 'url'
]);