nbHits behavior #467
Replies: 3 comments 1 reply
-
Does this mean that as long as I'm not searching but only filtering (facets or geo), I actually can expect I understand that, as a work around, I can set the limit to a number larger than the total document count (so there's only one page and it will be the first and the last at the same time). Question is, do I need this workaround when only filtering, not searching? One use case is https://www.mapmf.org/explorer where the numbers on the map and the charts are based on |
Beta Was this translation helpful? Give feedback.
-
Update on this discussion: we've just created this discussion to get your feedback about the Meilisearch end-user pagination in general, not especially related to |
Beta Was this translation helpful? Give feedback.
-
Locked in favor of #483 |
Beta Was this translation helpful? Give feedback.
-
I open this discussion to try to make clearer the
nbHits
behavior that is not always clear for our users.Meilisearch is a search engine designed for performance and relevancy, not designed to retrieve ALL the matches for a search: only the most relevant documents regarding the user request (a
limit
of 20 documents by default) will be retrieved.nbHits
returned by the search engine is not the exact total number of candidates, but an estimation of this number of candidates.Explanation
I will try to explain it in a simple way:
Let's imagine you do this query:
This query means: I ask for the 20 most relevant documents (
offset: 0
andlimit: 20
), so documents from offset0
to19
.Meilisearch will first try to find documents matching exactly "women", I mean without any typo. Let's imagine Meilisearch (internally) finds 45 candidates (i.e 45 documents containing "women"): it will apply an optimal sort to return the 20 most relevant candidates (in
hits
). Also, Meilisearch will returnnbHits: 45
because it finds out 45 candidates when applying your request.Now, with the same database of documents, let's imagine you do this query, for example when doing pagination.
This query means: I ask for the 70 most relevant documents (
offset: 51
andlimit: 20
, so 70 documents), and I want Meilisearch to return the document from offset51
to70
.Meilisearch will try to get documents matching exactly "women" without any typo first, but in this case, the number of candidates is not enough (45) since you asked for 70. In this case, Meilisearch has to fetch other candidates. How? It will try to fetch documents containing "women" with a typo, like "woman".
Let's say in this case, Meilisearch finds (internally) 100 new candidates with "woman": it will apply an optimal sort to gt the 70 most relevant candidates and return the ones from 51 to 70. Also, Meilisearch will return a new
nbHits: 145
because it finds out 100 + 45 candidates when applying your request.Conclusion
nbHits
is a good way to know if there are still candidates matching your query you have not browsed yet, but it cannot guarantee this number is the exhaustive number of candidates.With
nbHits
you can not directly access the LAST page of your pagination, but only know if there are next pages. Reaching the last page is not recommended anyway, for performance reasons, because enforcing Meilisearch to get ALL the relevant documents, sort them, to retrieve the latest ones you asked for.Knowing this we are sorry for the potential confusion, and we hope these explanation are clearer. We want to be transparent with our users.
FYI, here are the next steps we are considering and working on:
nbHits
to remove the confusion due to the name in v0.28.0 (planned to July): Confusing nbHits #394Beta Was this translation helpful? Give feedback.
All reactions