Hi
I have created a custom content type using the date module. I want the search results to be sorted according to this custom date field instead of the created/modified date.
Can anyone point me in the right direction?
best regards
Libby
Hi
I have created a custom content type using the date module. I want the search results to be sorted according to this custom date field instead of the created/modified date.
Can anyone point me in the right direction?
best regards
Libby
Comments
Comment #1
libbyy commentedComment #2
sawtell commentedYou can add a sort in hook_apachesolr_query_prepare().
You can find the list of fields in the solr index at http://example.com/admin/reports/apachesolr/SERVER_NAME
The field you want to add as a sort needs to be single valued, multivalued fields cannot be used to sort results.
Comment #3
Yorgg commentedI can't seem to create a single valued "ds_" field using date module.
It's being stored as a multivalued field even if I don't tick the "collect end date" or change the number of values to multiple. The workaround was to use published date to perform the sort.
How can I make this the default sort? I don't want to expose the sort block.
Comment #4
ressaThanks for the tips @ls206. I wanted to sort by a Price field, and had to use 'its_field_price' for it to work. There was also a 'itm_field_price' which didn't work.
I really think your explanation on how to add a custom sort field should be added to the README.txt file.
Comment #5
subhojit777@j_nunes The point is apache solr module considers custom field as multivalued, nevertheless the field is single valued. You can see
apachesolr_get_field_mappings($entity_type)inapachesolr.module. What you can do is alter field mapping for the custom field. See the code:This way you can alter the cardinality of a solr field.
Comment #6
sarikak commentedHow to name the fields to be used in sorting.As @ressa mentioned in above comment I am confused in naming the fields.
Also while using a custom fields date and year for sorting, I am getting results in wrong sort order.
Any help will be appreciated.Thanks