Skip to content
This repository has been archived by the owner on May 13, 2021. It is now read-only.

Include facetsDistribution in paginate() response? #118

Closed
foreverheavy opened this issue Mar 26, 2021 · 1 comment
Closed

Include facetsDistribution in paginate() response? #118

foreverheavy opened this issue Mar 26, 2021 · 1 comment

Comments

@foreverheavy
Copy link

Loving Meilisearch so far, guys... Only think holding me back from integrating it into our app is a lack of clarity on how to access the extra metadata like facetsDistribution.

I can currently access facetsDistribution by using raw() when executing the query, so my temporary workaround is calling the raw search function, then the traditional paginate query right afterwards. Is there a way to integrate the facetsDistribution response into the paginate response so I don't have to do this hacky, resource-intensive workaround?

Thanks!

@curquiza
Copy link
Member

curquiza commented Mar 26, 2021

Hello @foreverheavy!

Thanks for trying MeiliSearch 😄
If I'm correct, we don't provide any possibility like this one for the moment since we want to be totally compliant with the official Laravel/Scout package. See this issue for more details #111.

However, to avoid calling twice the server, you can perform your pagination in a custom search, at the same time as the facetsDistribution parameter:

User::search('your query', function (Indexes $meilisearch, $query, $options) {
        $options['offset'] = 10;
        $options['limit'] = 5;
        $options['facetsDistribution'] = ['your facet'];

        return $meilisearch->search($query, $options);
})->raw();

Here is the README section about custom search:
https://github.com/meilisearch/meilisearch-laravel-scout#custom-search-

offset and limit are what the paginate() method uses.
The paginate() method also uses the getTotalCount() method to know the total number of hits, which uses the nbHits returned in the raw search. See

public function getTotalCount($results)
{
return $results['nbHits'];
}

You have all the elements to implement the pagination, even if it's less convenient than the paginate() method, it removes the double HTTP call.

I hope I understood your issue and it will help you. Feel free to ask any question about my explanation 🙂

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants