lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <>
Subject Re: Sorting on a field that can have null values
Date Thu, 12 Apr 2007 22:08:01 GMT

: If i rememebr correctly (you'll have to test this) sorting on a field
: which doesn't exist for every doc does what you would want (docs with
: values are listed before docs without)

: The actual behavior is different than described above. I modified

: The actual order of the results is: "ZJI". I believe this happens because
: the field string cache 'order' array contains 0's for all the documents that
: don't contain the field and thus sort first.

i guess wasn't precise enough in that old thread, what i ment was that not
having a vlaue results in the docs sorting the same as if they had a value
lower then the lowest existing value -- so they sort at the end of the
list if you are doing a descending sort, and at the begining of the list
if you do an ascending sort.  If you want to always have them come "last"
regardless of order, there is a SortComparator for that purpose in Solr...

: Suppose I want to exclude documents from being collected if they don't
: contain the sort field. One way to do this is to index a unique
: 'empty_value' value for those documents and add a MUST_NOT boolean clause to
: the query, for example: "<query terms> -field:empty_value)". But this seems
: inefficient. Is there a better way?

excluding them completely is a slightly differnet task, you don't need to
index a special marker value, you can just use a
RangeFilter (or ConstantScoreRangeQuery) to ensure you only get docs with
a value for that field (ie: field:[* TO *])


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message