meilisearch / meilisearch/meilisearch-php

Adding 'distinct' attribute at search time causing ApiException

Open
#724 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
757
Forks
125
Avg merge
6d 8h
Merged PRs (30d)
2

Description

Description
I'm using laravel scout to help me get a product list.
When building my search i wanted to provide a distinct attribute. i noticed meilisearch-php added that feature:
https://github.com/meilisearch/meilisearch-php/pull/648

Error:

Unknown field distinct: expected one of q, vector, offset, limit, 
page, hitsPerPage, attributesToRetrieve, attributesToCrop, cropLength, 
attributesToHighlight, showMatchesPosition, showRankingScore, showRankingScoreDetails, 
filter, sort, facets, highlightPreTag, highlightPostTag, cropMarker, matchingStrategy, attributesToSearchOn

Code is use to build the search query, when i want to add 'distinct' to the options i get the error.

Product::search($this->search)
    ->options([
        'filter' => $this->buildFilter(),
        'sort' => $this->buildSort(),
        'facets' => $this->buildFacets(),
        'limit' => $this->limit,
        // 'distinct' => $this->distinct, 
    ], fn ($value) => !is_null($value))
    ->$method(...$arguments);

I do notice the toArray() function in SearchQuery.php is missing distinct. Maybe that has something to do with it?

Environment (please complete the following information):

  • OS: [e.g. Debian GNU/Linux]
  • Meilisearch version: v1.12.3
  • meilisearch-php version: v1.12.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in SearchQuery.php, especially toArray(), and compare the supported search options with the distinct support linked in the issue. Reproduce the Product::search()->options() request against Meilisearch v1.12.3 and verify that distinct is accepted without the ApiException.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.