How does LIMIT work?

Since SEARCH always return a count of all documents matching the query, I assume Redis performs a search on the entire index and then only returns the number dictated by LIMIT?
Is there a way to stop searching when reaching the specified count? Is this a necessary thing Redisearch does to allow sorting?
I have noticed some problems with queries taking long periods of time and sometimes failing when, for instance, I want to get a list of the 10 newest record (with a query matching every document).

The LIMIT command appears to work the same for AGGREGATE and SEARCH, but with AGGREGATE you can define a MAX value. According to the documentation:

However, limit can be used to limit results without sorting, or for paging the n-largest results as determined by SORTBY MAX . For example, getting results 50-100 of the top 100 results is most efficiently expressed as SORTBY 1 @foo MAX 100 LIMIT 50 50 . Removing the MAX from SORTBY will result in the pipeline sorting all the records and then paging over results 50-100.

It is vague but implies that the MAX command at worst only sorts the sought-after documents and at best stops searching when it finds them.

As for the LIMIT function, I wonder why it is implemented in that manner. It seems counterintuitive and non-orthodox. Would really like to know what technical/other reasons there were/are for having it work like that.

Thank you

FT.SEARCH is always sorting the result using FTIDF so this is why we need to first score all the result and then sort. If you do not care about sorting you can use FT.AGGREGATE which will stop after reaching the specified limit (but notice that you will lose the sorting by result score). Look on this reply for more information: