[ckan-dev] Sort metadata fields.
Joe Tsoi
joe.tsoi at okfn.org
Thu Jan 30 20:12:45 UTC 2014
Also if you'd like more custom sorts as you've mentioned, then it'll
be worth looking into solr sorting.
http://wiki.apache.org/solr/CommonQueryParameters#sort
http://wiki.apache.org/solr/FunctionQuery
which should alow you to define a custom function to score your
results and sort by them!
On 30 January 2014 20:06, Joe Tsoi <joe.tsoi at okfn.org> wrote:
> ok I had a bit more of a look and this is much easier than I had first
> assumed. Any custom fields you've added as package extras will also
> automatically get indexed by solr as extras_{name of your extra}. This
> means you can add custom sorting on your metadata field by overriding
> this block in your extension
> (https://github.com/ckan/ckan/blob/master/ckan/templates/package/search.html#L29)
> and adding something like
>
> (_('My Custom Field Ascending'), 'extras_{name of your extra} asc'),
> (_('My Custom Field Descending'), 'extras_{name of your extra} desc'),
>
> to your template.
>
> Hope this helps.
>
> On 27 January 2014 12:59, Joe Tsoi <joe.tsoi at okfn.org> wrote:
>> You'd probably want to add your custom field to the solr schema and
>> have your plugin implement IPackageController.before_index, althougth
>> I've never had to try this myself
>>
>> You might also want to have your plugin implement
>> IPackageController.before_search to add your custom sorting fields to
>> the ui, but you can probably just get away with adding the sort
>> parameter to the solr query to start with
>>
>> I think stats-canada has done
>> this.https://github.com/open-data/ckanext-canada so you might want to
>> speak to wardi on IRC, otherwise this might make a good subject for a
>> tutorial.
>>
>> On 27 January 2014 12:34, Henrik Aagaard Sørensen <BU1G at tmf.kk.dk> wrote:
>>> Thank you for the answer. I'm interested in a more custom sort, so if it
>>> would be possible to add sort_order or something similar to each
>>> metadata-field, it would be great? Order by alphabet etc. does not work.
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> ckan-dev mailing list
>>> ckan-dev at lists.okfn.org
>>> https://lists.okfn.org/mailman/listinfo/ckan-dev
>>> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>>>
More information about the ckan-dev
mailing list