{"action":"created","issue":{"url":"https://api.github.com/repos/datagovuk/ckanext-dgu/issues/461","repository_url":"https://api.github.com/repos/datagovuk/ckanext-dgu","labels_url":"https://api.github.com/repos/datagovuk/ckanext-dgu/issues/461/labels{/name}","comments_url":"https://api.github.com/repos/datagovuk/ckanext-dgu/issues/461/comments","events_url":"https://api.github.com/repos/datagovuk/ckanext-dgu/issues/461/events","html_url":"https://github.com/datagovuk/ckanext-dgu/issues/461","id":169393862,"number":461,"title":"Adding a custom metadata field to search filters","user":{"login":"zvetaM","id":18571939,"avatar_url":"https://avatars.githubusercontent.com/u/18571939?v=3","gravatar_id":"","url":"https://api.github.com/users/zvetaM","html_url":"https://github.com/zvetaM","followers_url":"https://api.github.com/users/zvetaM/followers","following_url":"https://api.github.com/users/zvetaM/following{/other_user}","gists_url":"https://api.github.com/users/zvetaM/gists{/gist_id}","starred_url":"https://api.github.com/users/zvetaM/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zvetaM/subscriptions","organizations_url":"https://api.github.com/users/zvetaM/orgs","repos_url":"https://api.github.com/users/zvetaM/repos","events_url":"https://api.github.com/users/zvetaM/events{/privacy}","received_events_url":"https://api.github.com/users/zvetaM/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-04T14:51:36Z","updated_at":"2016-08-09T12:30:16Z","closed_at":null,"body":"Hello,\r\n\r\nusing the tips you provided in the issue https://github.com/datagovuk/ckanext-dgu/issues/440 I have successfully created several metadata fields. One of these fields I would now like to add among the search filters on the left-hand side of the ckan search page (among Publisher, Theme, Resource format and others).\r\n\r\nThe field that I would like to add to search filters has several possible values, which are stored in a vocabulary that has been populated using the paster command that executes:\r\n_existing = model.Vocabulary.by_name('podrocja')\r\n        if not existing:\r\n            result1 = tk.get_action('vocabulary_create')(\r\n                data_dict={'name': 'podrocja', 'tags': [\r\n                {'name': u'Energetika'},\r\n                {'name': u'Finance in davki'},\r\n               ...\r\n                {'name': u'Vlada in javni sektor'},\r\n                {'name': u'Zdravje'},\r\n                {'name': u'Znanost in tehnologija'}\r\n            ]})_\r\n\r\nNow I would like to be able to filter dataset by these tags. I've been trying to figure my way around the source code (search_facets in helpers.py, facet_options in _dgu_jinja_utils.html, etc.) but yet again I came out clueless as to how things work and how I could even start.\r\nCould you please give me some hints on how I could start and how things work?\r\n\r\nThank you very much."},"comment":{"url":"https://api.github.com/repos/datagovuk/ckanext-dgu/issues/comments/238538023","html_url":"https://github.com/datagovuk/ckanext-dgu/issues/461#issuecomment-238538023","issue_url":"https://api.github.com/repos/datagovuk/ckanext-dgu/issues/461","id":238538023,"user":{"login":"zvetaM","id":18571939,"avatar_url":"https://avatars.githubusercontent.com/u/18571939?v=3","gravatar_id":"","url":"https://api.github.com/users/zvetaM","html_url":"https://github.com/zvetaM","followers_url":"https://api.github.com/users/zvetaM/followers","following_url":"https://api.github.com/users/zvetaM/following{/other_user}","gists_url":"https://api.github.com/users/zvetaM/gists{/gist_id}","starred_url":"https://api.github.com/users/zvetaM/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zvetaM/subscriptions","organizations_url":"https://api.github.com/users/zvetaM/orgs","repos_url":"https://api.github.com/users/zvetaM/repos","events_url":"https://api.github.com/users/zvetaM/events{/privacy}","received_events_url":"https://api.github.com/users/zvetaM/received_events","type":"User","site_admin":false},"created_at":"2016-08-09T12:30:16Z","updated_at":"2016-08-09T12:30:16Z","body":"Hello,\r\n\r\nthank you for your reply. Unfortunately, I am having problems...\r\n\r\nIn _plugin.py_ I have added `SearchIndexing.add_podrocje(pkg_dict)` to the end of _before_index(self,pkg_dict)_. The function _add_podrocje()_ is as following\r\n\r\n```\r\ndef add_podrocje(cls, pkg_dict):\r\n        pkg_dict['all_podrocje'] = []\r\n        podrocje = helpers.get_pkg_dict_extra(pkg_dict, 'podrocje', default=None)\r\n        if podrocje:\r\n            if isinstance(podrocje, types.StringType):\r\n                podrocje = unicode(podrocje)\r\n        pkg_dict['all_podrocje'].append(podrocje)\r\n\r\n        log.debug('Podrocje: %s', ' '.join(str(podrocje)))\r\n```\r\n\r\nWhen I run _paster --plugin=ckan search-index rebuild --config=/var/ckan/ckan.ini_ , I can see in output\r\n`2016-08-09 14:15:46,301 DEBUG [ckanext.dgu.search_indexing] **Podrocje: N o n e**`\r\n\r\nBut the field _podrocje_ is populated in datasets and is successfully displayed also on the dataset summary page. If I understand correctly, _add_podrocje(cls, pkg_dict)_ is called for each dataset and since the value of podrocje is accessible in _edit_form.html_ and _helpers.py_, it should be accessible also here...\r\n------------------------------------------------------------\r\n\r\nIn _dataset_form.py_ is the field _podrocje_ defined as\r\n...\r\n`'podrocje': [not_empty, unicode, convert_to_extras],`\r\n...\r\n`'podrocje': [convert_from_extras, ignore_missing],`\r\n...\r\n\r\nand in _helpers.py_ as\r\n\r\n`'podrocje': {'label': u'Področje', 'value': pkg_extras.get('podrocje','')},`"}}
{"actor":{"display_login":"zvetaM"}}