Question:
How am I able to reproduce the result from the url below from the package_search
API endpoint with CKAN's web UI?
https://demo.ckan.org/api/3/action/package_search?fq=num_resources:[1%20TO%20*]
I want to let a user filter by Packages with resources or without (0 num_resources
or 1 to * num_resources
).
What I've tried:
I've looked at and tried adding some facets and sorting already.
The facet allows filtering by Packages with X number of resources (e.g. 1). The sorting allows you to Sort all data sets by order of number of resources e.g. Packages with 10 resources first then 9 resources, then 8, etc...
I've tried to duplicate the API URI with the below
https://demo.ckan.org/dataset?num_resources=[1%20TO%20*]
If I add the fq
portion it does not work either. The search()
action will grab num_resources=[1 TO *]
and append it to the solr fq
param (can be seen here with log statements).
However, after trouble shooting this I've found that the CKAN Package controller's search()
action DOES allow you to add values to the solr filter option fq
like in the API call BUT that it first converts the params to a string num_resources:"[1 TO *]"
. This works fine to get a single value but not the range I'm after. If I use this exact param (with the quotes and not like the above url/api endpoint) with the API I get the incorrect result as well.
General Info:
- using ckan 2.8.1
- source install, deployed to production following the docs but using as my dev box
UPDATES:
2018-12-20:
I have since found that q=num_resources:[1%20TO%20*]
as a query string works as this is not escaped in the search()
action. The q
parameters are extracted before the encoding takes place.
However, this isn't ideal as it updates the search input and overrides any existing query strings unless you append to the query string and adding this to the filters so far is a pain.
# I've switched spaces to + to help with readability.
https://demo.ckan.org/dataset?q=num_resources:[1+TO+*]+Test
2018-12-21:
Working on implementing IPackageController from within an extension. This seems to be the proper way to go about this given the circumstances. Will add implementation after.
However, I feel an updated implementation of the params could be done in ckan's package_search
Turns out the search index and organization read are implemented quite a bit differently so the exact same implementation wont work. extra params are actually included as part of the q
parameters instead of fq
like search.
search()
action / view blueprint though to look for fq params.