How I search datasets by multiple tags using CKAN API?

房东的猫 提交于 2021-02-08 07:18:18

问题


I'm using CKAN portal with API version "ckan_version": "2.5.x" I have few tags and I need to send using API these tags and I need to return a list of matching entries of packages or resources.

Is possible to use do use package_search endpoint to search for packages with all given tags, but it works as "AND" operator, and that I need is a "OR" operator. e.g.:

  • http://demo.ckan.org/api/3/action/package_search?fq=tags:contabilidade-social <-- return 11 packages that contains 'contabilidade-social'
  • http://demo.ckan.org/api/3/action/package_search?fq=tags:contabilidade-social+governo <-- return 11 packages that contains 'contabilidade-social' and 'governo'
  • http://demo.ckan.org/api/3/action/package_search?fq=tags:contabilidade-social+governo+enogastronomia <-- return 0 packages that contains 'contabilidade-social' and 'governo'and 'enogastronomia'. For my purpose it should return matches with 'OR' operator instead.

PS: I used top 10 tags (http://demo.ckan.org/api/action/package_search?facet.field=[%22tags%22]&facet.limit=10&rows=0).

I think it have relation with SOLR and postgresql index. There is a way to do that? If not, Is possible to extend or create a facet that make possible use this kind of search?


回答1:


Try the following syntax:

fq=tags:(tag1 OR tag2 OR tag3)

For instance:

http://demo.ckan.org/api/3/action/package_search?fq=tags:(contabilidade-social%20OR%20governo%20OR%20enogastronomia)



来源:https://stackoverflow.com/questions/41568242/how-i-search-datasets-by-multiple-tags-using-ckan-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!