Search code examples
pythonpylonsckan

CKAN - Custom Dataset/Resource Fields


I am following this tutorial concerning adding custom dataset/resource fields for CKAN: http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html

I have successfully added custom fields for both datasets and resources. However, I have two questions.

1.) Resource metadata fields do not currently appear to be indexed. How do I enable Solr indexing of the custom metadata fields for resources?

2.) How can I re-arrange the order of the metadata fields on the UI?


Solution

  • To answer your questions in order:

    1. You are probably trying to search for data that goes in through your custom fields. One solution that exists similar to SOLR indexing for custom fields is to override the search ordering block by implementing /templates/package/search.html in your extension This allows SOLR to use your fields to order the SOLR search results. You may need to reload your development server for the changes to take effect. You can follow a guide here: http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html#sorting-by-custom-fields-on-the-dataset-search-page Also, you could implement this function in your plugin.py

    `

    def before_index(self, index_dict):
       #Implement some package level stuff here and put the value in the index_dict
    
            index_dict['your_choice_index_name'] = 'your proposed value' 
            return index_dict
    
    1. In order to achieve this, you may need to override all the blocks in the current dataset meta data form by overriding them in templates/package. If that's what you refer to by meta-data fields on the UI.

    I hope this helps.