Adding custom field for sorting?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding custom field for sorting?

Vinci
Hi,

Inspirited by the previous post, does it possible to add my custom field and use it for sorting the search result?
If It is possible, what will be the step? Do I need to modify the source code?
 
Thank you,
Vinci
Reply | Threaded
Open this post in threaded view
|

Re: Adding custom field for sorting?

hossman
:
: Inspirited by the previous post, does it possible to add my custom field and
: use it for sorting the search result?
: If It is possible, what will be the step? Do I need to modify the source
: code?

adding a custom field is easy, just add the <field/> to your schema.xml
and put data in it.

adding a custom *fieldtype* is trickier ... compile your new fieldtype
against the solr code base, package it in a jar, and put that jar in the
plugin lib dir...

        http://wiki.apache.org/solr/SolrPlugins

...no need to modify any Solr code.




-Hoss

Reply | Threaded
Open this post in threaded view
|

Re: Adding custom field for sorting?

Vinci
Hi hossman,

Thank you for your reply.
Some question on sorting:
1. Does Solr have a limit, e.g a % or a number to limit the number of document involved in sorting? or just sort all document?
2. Does the order in parameter 'sort' refer to the sorting order? (sort the first argument first, then the second and so on)

Thank you,
Vinci

hossman wrote
:
: Inspirited by the previous post, does it possible to add my custom field and
: use it for sorting the search result?
: If It is possible, what will be the step? Do I need to modify the source
: code?

adding a custom field is easy, just add the <field/> to your schema.xml
and put data in it.

adding a custom *fieldtype* is trickier ... compile your new fieldtype
against the solr code base, package it in a jar, and put that jar in the
plugin lib dir...

        http://wiki.apache.org/solr/SolrPlugins

...no need to modify any Solr code.




-Hoss
Reply | Threaded
Open this post in threaded view
|

Re: Adding custom field for sorting?

hossman

: 1. Does Solr have a limit, e.g a % or a number to limit the number of
: document involved in sorting? or just sort all document?

it depends on the context of your question ... if you use any existing
fieldtypes, then standard LUcnee sorting kicks in, and a Fieldcache is
built containing the values of every doc no matter how many need to be
sorted for a given query -- but that cache is reused for every sorted
query.  if you write your own FieldType, you can do whatever you want in
your SortField implentation.

: 2. Does the order in parameter 'sort' refer to the sorting order? (sort the
: first argument first, then the second and so on)

http://wiki.apache.org/solr/CommonQueryParameters#sort

-Hoss