3/28/2012

Liferay And Solr: SolrException: can not sort on multivalued field:

If you get this Exception:

org.apache.solr.common.SolrException: can not sort on multivalued field: modified
at org.apache.solr.schema.SchemaField.checkSortability(SchemaField.java:161)
at org.apache.solr.schema.FieldType.getStringSort(FieldType.java:527)
at org.apache.solr.schema.StrField.getSortField(StrField.java:40)
at org.apache.solr.schema.SchemaField.getSortField(SchemaField.java:144)
at org.apache.solr.search.QueryParsing.parseSort(QueryParsing.java:385)
at org.apache.solr.search.QParser.getSort(QParser.java:251)
at org.apache.solr.handler.component.QueryComponent.prepare(QueryComponent.java:82)
at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:173)
at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:129)
at org.apache.solr.core.SolrCore.execute(SolrCore.java:1368)



then you might be using the liferay solr plugin together with Liferay 6.0.6. Right ?
If so, then continue reading.


Please add the following field to the schema.xml file of the index you are trying to access:
<field name="modified" type="text" indexed="true" stored="true" />


Please also change your SolrIndexSearchImpl and add this to the method "subset", replacing the original code:
 for (String name : names) {
        Field field = new Field(name, 
ArrayUtil.toStringArray(solrDocument.getFieldValues(name).toArray()), false);
document.add(field);
}


There are some posts that helped me on my way to find the solution.
Here they come:


http://issues.liferay.com/browse/LPS-17569
http://www.liferay.com/community/forums/-/message_boards/message/9532150
http://www.liferay.com/community/forums/-/message_boards/message/9024087



If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.