cancel
Showing results for 
Search instead for 
Did you mean: 

FlexibleSearchQuery getting into ranges.

VinayKumarS
Active Contributor
0 Kudos

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);
 fQuery.setCount(range);
 fQuery.setNeedTotal(true);
 
 int start = 0;
 final int range = 3;
 int total;
 
 do
 {
        fQuery.setStart(start);
        final SearchResult<UnitModel> searchResult = flexibleSearchService.search(fQuery);
        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.

https://help.sap.com/doc/c74a78df6c654be3a432b9c1ab173d42/6.7.0.0/en-US/index.html

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

former_member620692
Active Contributor
0 Kudos

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.
VinayKumarS
Active Contributor
0 Kudos

Thank you Aravind. I overlooked the documentation. I just copy pasted it as it is working. I could understand now.. thanks for reply.

former_member620692
Active Contributor
0 Kudos

You are most welcome, Vinay.

Answers (0)