Warning, this is just a brain dump.
I wanted to add a custom facet to replace the Tags facet in the popular tags on the home page search box. I ended up coming up with 3 options:
- update CKAN core home.py view to include getting package facetscode
- override home.py index() in my own extension code
- create custom template helper code
But then realized later I could have tried adding some default facets in my configuration file e.g.
search.facets = u'organization groups tags res_format license_id keywords_en'.
Here’s my long-winded, hopefully helpful thoughts on what’s going on when I started digging in…
The popular tags on the home page are called from the
get_facet_items_dict helper. This uses the
search_facets to figure out what facets to display.
search_facets are set in the views/home.py from the query it calls (through
package_search()). The queries facets are set from
h.facets() which will set the default facets from the config or with a constant in the helper file.
The query uses
def package_search from the action/get.py.
So, if you’re using a
before_search() to modify the search params you should be able to alter the
fq or as @wardi said, maybe the
fq_list but I haven’t played with that one. Because, in a round about way this the action that returns the popular tags.
fq be careful. It’s implemented differently depending on object you’re modifying (in this case package). In my experience with package_search it escapes out some of the
fq params which is good but annoying at times.
In my case for something similar I had to write a function that “customized” the
fq params how I wanted to keep the proper values to get them to search the way I wanted.
I did the above for a custom facet on the package search page.
However, I also wanted to customize the popular tags for a separate request I had. In this case I just wrote a custom helper that queried my own “popular tags” and structured them the same way as the core helper. This let me get all the facets I wanted without having to modify the existing default facets (although thinking about it now, I could have just updated the config file but I wouldn’t have went down this rabbit hole).
E.g. of custom helper that I call in my homepage template: