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

Custom pagination with totalCount #60

Closed
vylink opened this issue Nov 17, 2020 · 4 comments
Closed

Custom pagination with totalCount #60

vylink opened this issue Nov 17, 2020 · 4 comments

Comments

@vylink
Copy link

vylink commented Nov 17, 2020

Hi,

I want to use "cursor" pagination with offset and limit.

How can I get the total count of documents in the following example?

        $result = Book::search('', function (Indexes $meilisearch, $query, $options) {
            $options['offset'] = 5;
            $options['limit'] = 30;
            return $meilisearch->search($query, $options);
        });

        return [
            'data' => $result->get(),
            'totalCount' => 0 // I want to know how many documents are in the index.
        ];
@shokme
Copy link
Collaborator

shokme commented Nov 19, 2020

Hello @vylink,

I'm quite busy right now, I can't help you.

But I hope these indication can help you to solve your problem

$result->get() will show you the result from database, you should use $result->raw() to get the meilisearch response and have access to nbHits.

you also can do something like:

Book::getTotalCount($result->get())

source

@curquiza
Copy link
Member

curquiza commented Nov 19, 2020

Hello @shokme! Thanks for your help during your busy time! 🙂

Hi @vylink!
I would add some resources to complete the @shokme answer.
If you are building pagination, I really recommend you checking out this issue we (the Meili team) created to explain how MeiliSearch works with pagination: meilisearch/documentation#561
Indeed nbHits (so getTotalCount) will not return the exact number of matches, if it's was you are looking for with 'totalCount' => 0 // I want to know how many documents are in the index. You might build a pagination as explained in the first part of the issue.

Tell me if anything is not clear! And thanks for trying MeiliSearch with our laravel-scout plugin!!

@shokme
Copy link
Collaborator

shokme commented Nov 24, 2020

@vylink did we resolve your issue ?

@vylink
Copy link
Author

vylink commented Nov 24, 2020

Many thanks for your recommendations

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

3 participants