Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Add Sort in Liferay search
Hello All,
I want to add Sort functionality into Default Liferay search can any one suggest me how i can achieve this.?(same as like Let the User Choose scope is given into configuration).
I already use SearchBar fragment and SearchResult fragment, In SearchBar fragment add two select box one is orderColumn and another is for orderType(asc, desc).
Liferay liferay-dxp-7.1.10.2-sp2
Elasticsearch 6.50.
Appreciate your help!
I want to add Sort functionality into Default Liferay search can any one suggest me how i can achieve this.?(same as like Let the User Choose scope is given into configuration).
I already use SearchBar fragment and SearchResult fragment, In SearchBar fragment add two select box one is orderColumn and another is for orderType(asc, desc).
Liferay liferay-dxp-7.1.10.2-sp2
Elasticsearch 6.50.
Appreciate your help!
First suggestion: move to 7.2, where sorting results is a built-in capability: https://portal.liferay.dev/docs/7-2/user/-/knowledge_base/u/sorting-search-results-with-the-sort-widget
On 7.1, this appears to be the general pattern fo building a sort and adding it to the search context:
If that doesn't push you toward a solution, you might have to be more specific with your question. I don't know if I can help you, but it makes it easier for a real expert to help if it's clear what you're trying to do, what you've tried, and how it failed.
Good luck!
On 7.1, this appears to be the general pattern fo building a sort and adding it to the search context:
SortFactory sortFactory = new SortFactoryImpl();
Sort sort = sortFactory.create(String fieldName, int type, boolean reverse);
searchContext.setSorts(sort));
If that doesn't push you toward a solution, you might have to be more specific with your question. I don't know if I can help you, but it makes it easier for a real expert to help if it's clear what you're trying to do, what you've tried, and how it failed.
Good luck!
Thanks for your help, but it is still not working.
Same as like 7.2 i want to implement into 7.1, i tried many time but still not working.
I write one IndexerPostProcessor and below is a code snipest.
Same as like 7.2 i want to implement into 7.1, i tried many time but still not working.
I write one IndexerPostProcessor and below is a code snipest.
@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, BooleanFilter booleanFilter,
SearchContext searchContext) throws Exception {
searchContext.setSorts(new Sort(Field.PUBLISH_DATE, Sort.SCORE_TYPE, false));
}
Hy ,
Don't forget to add your sorted column on this property (portal-ext.properties) :
index.sortable.text.fields=...
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™