Skip to Content

FlexibleSearchQuery getting into ranges.

Hello Friends,

As per the documentation when we retrieve the Products using FlexibleSearch SAP Hybris recommends to get the data into ranges to improve the performance using below approach.

 String query = "SELECT {" + UnitModel.PK + "} FROM {" + UnitModel._TYPECODE + "} ORDER BY " + UnitModel._TYPECODE;
 final FlexibleSearchQuery fQuery = new FlexibleSearchQuery(query);
 int start = 0;
 final int range = 3;
 int total;
        final SearchResult<UnitModel> searchResult =;
        total = searchResult.getTotalCount();
        start += range;
 while (start < total);

i expected 3 items each iteration. But i am getting all the time full records from Product Table. Am I misssing anything here.


Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Oct 26, 2019 at 02:41 PM

    Vinay Kumar Samudrala - Glad to see you after a long time.

    There are two things that you need to consider w.r.t. the code you have posted:

    1. Your code won't compile as you have written fQuery.setCount(range); before declaring range.
    2. Probably you are looking at searchResult.getTotalCount() which will always give you the count of all the records returned by the query and that is why you have put the condition while(start< total); with the do...while loop. If searchResult.getTotalCount() would return you the value of range (which is 3 in your code), it would not make sense to put the condition like while(start< total); as in that case, your do...while loop would not execute more than once.
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.