lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shawn Heisey <>
Subject Re: Sorting by custom order
Date Sat, 01 Sep 2018 21:10:00 GMT
On 9/1/2018 12:36 AM, Salvo Bonanno wrote:
> I need to sort a results set in a particolar way... the documents
> looks like this:

There are two problems with what you want and your setup.

> I need to sort them by profile_txt value (it's a multiValue field but
> actually it contains just a single value), but since the possible
> values are just 5, I'd like to tokenize them for deciding in wich
> order the should came.

You can't sort on a multivalued field.  The fact that your documents 
only contain one value in that field makes no difference.  Solr will 
*refuse* to sort on the field.

> the order should follows a simple schema:
> 1. profile_txt = "Gold"
> 2. profile_txt = "Super"
> 3. profile_txt = "Smart"
> 4. profile_txt = "Base"
> 5. profile_txt = "Essential"

This is the other problem.  Solr only sorts on two criteria -- numeric, 
or alphanumeric.  The sort order you want doesn't fit either of these.

Since you can't change the schema, I'm not entirely sure what you can 
do.  I think it's probably possible to provide a custom sort plugin for 
Solr, but I have absolutely no idea how to do it.

I don't know if it's possible to devise a function query that would 
result in this ordering or not.  Clever usage of the function query 
feature in Solr can do a lot of things.  This function, ascending, MIGHT 
do it:


I do not know if the string values need to be wrapped in quotes for that 
to work.  I'm also not entirely sure that I've placed the parentheses 

If you do end up being able to change the schema, then you can add a 
numeric field and have your indexing program populate that field with a 
number based on the value of profile_txt, then you could sort on that 
field. Solr would not be able to do this for you unless you wrote a 
custom UpdateProcessor and activated it in your solrconfig.xml file.


View raw message