lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <>
Subject Re: custom sorting
Date Thu, 27 Sep 2007 18:50:36 GMT

: > Previously we were using lucene to do this. by using the
: > SortComparatorSource we could sort the documents returned by distance
: > nicely. we are now switching over to lucene because of the features it
: > provides, however i am not able to see a way to do this in Solr. 

Someone started another thread where they specificly discuss the 
"Geographical distance searching" aspect of your question.

to answer the broader question of using customized 
LUcene SortComparatorSource objects in solr -- it is in fact possible.

In Solr, all decisisons about how to sort are driven by FieldTypes.  You 
can subclass any of the FieldTypes that come with Solr and override just 
the getSortField method to use whatever sort logic you want and then use 
your new FieldType as you would any other plugin...

In the case where you have a custom SortComparatorSource that is not 
"field" specific (or uses data from morethen one field) you would need to 
make your field type smart enough to let you cofigure (via the <fieldType> 
declaration in the schema) which fields (if any) to get it's data from, 
and then create a marker field of that type, which you don't use to index 
or store any data, but you use to indicate when to trigger your custom 
sort logic, ie...

    <fieldType name="distance" class="solr.YourField" 
               latFieldName="latitude" lonFieldName="longitute" 
               stored="false" indexed="false />
   <field name="latitude" type="sint" indexed="true" stored="true" /> 
   <field name="latitude" type="sint" indexed="true" stored="true" /> 
   <field name="distance" type="distance" />

...and then use "sort=distance+asc" in your query


View raw message