rotty3000/liferay-plugins — pull request #21 by KocsisDaniel (2012-09-06 12:53:42+00:00)
Title: LPS-27673 Fix sorting in Solr

Hey Ray,

I am sending you this PR because it is related SolR. I have found the following problems during the investigation:

- now the portal handles the sortable fields in a general way and generates always an extra xy_sortable field when we add a text field to a search document (DocumentImp.addText()) and its name matches on of the index.sortable.text.fields property values. Because of that the SolR copyfield creates another value for sortable fields which leads to exception in case of non-multivalue fields.

- after I fixed the first point I faced a bigger issue. In the new SolR 3.5 version if you sort by a field that is a multivalue one it fails every time (https://issues.apache.org/jira/browse/SOLR-2339). Unfortunately with we declared all not defined fields as multivalued so it fails every time when the sort field is not one of the other declared but not tokenized and not multivalue fields. Currently we only replace the sort field name when it has a sortable pair but leave it as-is otherwise. With Lucene and the old SolR we don't have this problem because it fails silently and produce result set as normally but not sort as we requested.

To resolve both I think the best option is to let the portal generate all the xy_sortable fields and remove the copyfield options with the _sortable schema fields altogether from SolR and persist the search document without any post-processing and I also added a new dynamic field category with name pattern: *sortable. During the search I replaced the check to use the same functionality as DocumentImpl uses today to generate sortable field names and replace the sort field every time to the default score when the name not ends with "sortable" string.

Please let me know your opinion about the solution.

Thanks,
Daniel