Advertisement
Intermediate Redis, RedisSearch (Full Text Search)

How do you sort and paginate search results returned by a RedisSearch query?

Short answer

You add the SORTBY clause to your search query specifying the field to sort by and the direction, and use the LIMIT clause to specify a starting offset and the maximum number of results to return, letting you build a typical paginated search results experience directly using…

Save Redis mock interview
Advertisement
AModel answer
You add the SORTBY clause to your search query specifying the field to sort by and the direction, and use the LIMIT clause to specify a starting offset and the maximum number of results to return, letting you build a typical paginated search results experience directly using RedisSearch's built-in capabilities.
FT.SEARCH product_idx '@category:{electronics}' SORTBY price ASC LIMIT 0 20
Real-world example
A product search page displays the first twenty electronics products sorted by ascending price, using RedisSearch's built-in sorting and pagination features to efficiently retrieve exactly the results needed for that specific page.
Likely follow-ups
  • Does sorting require the field to have any special index configuration?
  • How do you retrieve the second page of results using the LIMIT clause?
Related topics