cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

how to Limit no. of rows in in flexible search

former_member674349
Participant
0 Likes
2,601

Hi Experts,

how can we Limit the no. of rows in in flexible search

e.g. If i want to get only 3 rows from given result. the operation should perform at database side Thanks, Jayant

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes

Hello Jayant,

You can use most of the common SQL clauses like TOP or LIMIT

e.g.

 SELECT {c.name}
 FROM {Customer as c} 
 ORDER BY {c.name} DESC 
 LIMIT 3

or

 SELECT TOP 3 {c.name}
 FROM {Customer as c}
 ORDER BY {c.name} DESC

Regards, Pawel

former_member674349
Participant
0 Likes

But top and limit are database specific. it might not work well with oracle. any suggestion for same.

Thanks, Jayant

Former Member
0 Likes

take a look at my answer

Answers (1)

Answers (1)

Former Member
0 Likes

An other not database specific solution would be:

 private List<Object> searchObject(final String typeCode, final int limit) {
     final FlexibleSearchQuery query = new FlexibleSearchQuery("SELECT {PK} FROM {" + typeCode + "}");
     query.setDisableCaching(DISABLE_CACHING);
     query.setDisableSearchRestrictions(DISABLE_SEARCH_RESTRICTIONS);
     query.setCount(limit); // <== limit
     return emptyIfNull(getFlexibleSearchService().search(query).getResult());
 }