掲示板

How to pass function query in sort param from Liferay 6.2 to Solr 4.3

8年前 に Riddhi Shah によって更新されました。

How to pass function query in sort param from Liferay 6.2 to Solr 4.3

New Member 投稿: 24 参加年月日: 12/03/06 最新の投稿
Hello All,

I am using Liferay 6.2 and Solr 4.3. Solr has a feature of adding function query in "sort" param like

sort=query({!v='myId:108002^1000.0 myId:2348032^700.0'}) desc, myId desc, title_sortable asc


Above works perfectly fine when I test from solr browser i.e. adding "q" param and adding "sort" param gives me my expected result.

From Liferay, we need to add Array of Sort object in search context, which would eventually go to SolrIndexSearcher.java where sort array would be retrieved from search context. This flow is working. Sort array is received in SolrIndexSearcher.

But challenge is to pass function query in Sort object from Liferay. Sort object expects a String fieldName, Int type and Boolean reverse. How shall I pass function query (Refer above code). I tried passing whole string "query({!v='myId:108002^1000.0 myId:2348032^700.0'})" in fieldName and true in reverse field. But it doesn't work because of below reason.

I checked the src of solr4-web plugin -> SolrIndexSearcher, it expects the fieldname passed in each element of the sorts array needs to be suffixed with "_sortable". So eventually even if I pass whole function query as a fieldName in Sort object, it would be defaulted to "score".

I couldn't find any other way to pass sort from Liferay to Solr. Can anyone please help if there is actually a way to pass function query from Liferay.

Or if someone can guide me on how to modify solr4-web plugin code.
thumbnail
8年前 に Bijan Vakili によって更新されました。

RE: How to pass function query in sort param from Liferay 6.2 to Solr 4.3

Expert 投稿: 375 参加年月日: 09/03/10 最新の投稿
To modify the solr4-web plugin code, there are couple ways:
  • Extend the plugin as shown in this guide: https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/lp-6-1-dgen02-creating-plugins-to-extend-plugins-0
  • Modify the source code and deploy it


I suggest choose whatever you feel more comfortable with keeping in mind first approach may be easier to maintain than the latter though may not be as easy to start with if you're not familiar with it.

I think if the functionality you like is not in the code, best way is to modify the source; after all, it is open source!

If you think you modify source code not in way it should be, just make a post (perhaps a blog?) to explain what you did and seek feedback; though the change you're seeking seems minor enough that wouldn't call for all that.

Good luck and let us know if you run into any snags.