API Reference / API Parameters / attributeForDistinct
Type: string
Engine default: null
Parameter syntax
'attributeForDistinct' => 'attribute'

Can be used in these methods:
setSettings

About this parameter# A

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 of attributeForDistinct 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 and 1.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.

Examples# A

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'
]);
Did you find this page helpful?
PHP v3