[opencms-dev] Solr sorting issue
Stephan Hartmann
hartmann at metamesh.de
Wed Feb 12 13:08:07 CET 2014
Hi Thorsten,
You could configure a new field in Solr's schema
(/WEB-INF/solr/conf/schema.xml) that takes a copy of your title with a type
that is appropriate for your sorting requirements.
First let's define the new field:
<field name="adjusted_sorttitle_de" type="alphaOnlySort" indexed="true"
stored="false" />
"alphaOnlySort" is a predefined type that first transforms the value to
lower case and then strips off all non-letters. The result will be a string
that consists only of characters between a-z.
Then define a copy directive for this field:
<copyField source="sorttitle_de_s" dest="adjusted_sorttitle_de"/>
The source is the name of the field as you specified it in OpenCms. The
target is our new field.
That's it. Now you should be able to sort your content types by the field
"adjusted_sorttitle_de".
Note: if you would like to consider numeric characters also for sorting,
you have to declare a new type (copy the alphaOnlySort) and adjust the
pattern of the solr.PatternReplaceFilterFactory accordingly.
HTH,
Stephan
2014-02-12 10:08 GMT+01:00 Thorsten Duhn <duhn at regio-gmbh.de>:
> Hello,
>
> I'm still in trouble with sorting in Solr. Problem is that I am sorting
> content types (like list-large and list-small examples in the bootstrap
> example module) and I want to sort for title of the element. I created a
> mapping from title in schema, so I can now see "sorttitle_de_s" in Solr
> index and sort for that. Unfortunally this is still case sensitive (big
> letters first), but that is the smaller problem. For specific contents I
> need some possibility to add manual sorting values. So f.i. that one entry
> is shown first. In other cases special characters like quotation marks
> should be ignored (without changing Title).
>
> So it came to my mind that an additional field like "sortname" could be
> helpful, so in such specific cases a different text is used for sort. But
> for migration and future editing reasons this should not be required, but
> optional. Always copying title to sortname by hand for every entry is not
> useful. So two ideas came to my mind:
>
> 1. Schema could have some default setting so that saving content fills
> sortname field with title content, if there is no content already.
>
> 2. Solr query could be written in a way, that it uses the sortname field
> only if it is filled, otherwise it uses the mapped title ("sorttitle_de_s").
>
> Both ideas did not succeed. I have not seen how to implement such a
> default mechanism in schema and for Solr I found no solution as well.
> Comma-separating several fields in query does not work as it assumes empty
> for "sorttitle" and gives all items with set sorttitle first, and the rest
> afterwards. Trying FunctionQuery (f.i. "sort=def(sortname_de_s,
> sorttitle_de_s) asc") throws UnsupportedOperationException.
>
> Thanks,
> Thorsten
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20140212/1d76aeca/attachment.htm>
More information about the opencms-dev
mailing list