Clarification of value of FTS meta "total_hits"

FTS documentation states “total_hits”:
" Total hits represents the total number of matches for this result. It can be any integer starting from 0".

By “matches” is the total number of documents containing matches? Or, is that the total number of matches among some number of documents?

To set up pagination, one requires the limit, offset, and the total number of documents included in the result, not just those returned as a result of the limit restriction. If total_hits is the number of document that could be included in the result, then I have my solution.

I appreciate confirmation of this understanding.

JG

@jgcoding

" Total hits represents the total number of matches for this result. It can be any integer starting from 0"

This is accurate.

By “matches” is the total number of documents containing matches? Or, is that the total number of matches among some number of documents?

This seems sort of synonymous to total_hits.
“size”/“limit” returns a subset of these total_hits.

To set up pagination, one requires the limit, offset, and the total number of documents included in the result, not just those returned as a result of the limit restriction. If total_hits is the number of document that could be included in the result, then I have my solution

total_hits is included in the search result object, and you would be using offset and limit for pagination, with these conditions: offset <= total_hits and offset + limit <= total_hits.

@abhinav

I do appreciate your reply but I dont believe my question was phrased properly. Please allow me to ask it within a simple example to eliminate confusion:

A search for the term “pretzel” might have 1300 matches among 340 documents. Would “total_hits” returned in the meta object of the response be 340 or 1300?

Thanks

JG

With Couchbase’s FTS, a document ID is returned as a match. Meaning, number of matches is equal to total hits.

A search for the term “pretzel” might have 1300 matches among 340 documents. Would “total_hits” returned in the meta object of the response be 340 or 1300?

If the term “pretzel” occurred 1300 times in 340 documents, total_hits would be 340. If you had scoring enabled for your results (which it is by default), these 340 documents are scored based on the tf-idf of the term “pretzel” => which takes into account the number of occurrences of the term in each document.

@abhinav

My only concern was to ensure “total_hits” was the document count. This you have confirmed. I appreciate that clarification.

Thank you

JG