Algolia distinct or unique property

how to only return unique results if multiple same results are present. i am using algolia/autocomplete.js

Hi @ahmednkhan5,

In order to return unique values, you can use our settings parameter distinct. You can specify it in the hits widget right after the hitsPerPage parameter.

Sir distinct is not working for me. it is spitting out same results. i am using autocomplete.jquery.min.js
here is the code

index.setSettings({
  distinct: true
});

$('#profession').autocomplete({ hint: false, minLength: 3, }, [
		{
			source: $.fn.autocomplete.sources.hits(this.index, 
				{ 
					hitsPerPage: this.hitsNo ,
					restrictSearchableAttributes: [
					    'title'
					],
                                           distinct: 1,
				}),

Hi @ahmednkhan5,

When you are using distinct it’s required to have an attribute for the deduplication. You can configure this attribute with the option attributeForDistinct. Then you will be able to use the distinct option to deduplicate your results.

Hope that helps! Let me know if you have questions.

can you please explain how can i use it in autocomplete.jquery.js? attributeForDistinct

Hi @ahmednkhan5,

The parameter attributeForDistinct is not available at query time. You can only specify it as a settings time. Applying to your example you can provide the parameter to the setSettings function.

index.setSettings({
  attributeForDistinct: "url"
});

On this example we choose to apply the deduplication of the records on the URL attribute. You can update this attribute according to your needs. Then inside the instantiation of your autocomplete you can specify the distinct attribute like you already do.