You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@lucene.apache.org by jfeldmar <jf...@ais.ucla.edu> on 2011/06/22 17:57:00 UTC

Inconsistent Sort order for empty and null fields

I tried searching for an answer to my question but haven't found anything
relevant.

When I query solr and sort by a given field in ASCENDING order, the records
which do not have a value for this field (i.e. null) appear AFTER the valued
records. The records that have an empty string for the field appear BEFORE
the valued records. This produces a visually inconsistent result.

example: sort by x asc
empty
empty
value
value
empty (because null)
empty (because null)

Logically, all the empty values should appear before the non-empty values
when sorting ascending. I could make all the null fields into empty strings
but this seems like a waste of resources.

Is there some setting in solr to force null fields to appear before valued
fields when sorting in ascending order?

Thank you

--
View this message in context: http://lucene.472066.n3.nabble.com/Inconsistent-Sort-order-for-empty-and-null-fields-tp3096175p3096175.html
Sent from the Lucene - General mailing list archive at Nabble.com.

Re: Inconsistent Sort order for empty and null fields

Posted by Chris Hostetter <ho...@fucit.org>.
: When I query solr and sort by a given field in ASCENDING order, the records
: which do not have a value for this field (i.e. null) appear AFTER the valued
: records. The records that have an empty string for the field appear BEFORE
: the valued records. This produces a visually inconsistent result.

a field containing the empty string (ie: "") is not the same as no field 
existing.  regardless of how else you deal with your sorting problem, it's 
important to make sure you udnerstand that, because they are fundementally 
different.

for instance: "field:[* TO *]" will match documents where you've indexed 
the empty string as a term, but it won't match documents where you haven't 
indexed any field value at all.



-Hoss

Re: Inconsistent Sort order for empty and null fields

Posted by pravesh <su...@yahoo.com>.
You need to set "sortMissingFirst=true" for the specific field/type in your
schema.xml

--
View this message in context: http://lucene.472066.n3.nabble.com/Inconsistent-Sort-order-for-empty-and-null-fields-tp3096175p3103934.html
Sent from the Lucene - General mailing list archive at Nabble.com.