-
Notifications
You must be signed in to change notification settings - Fork 1.2k
API: faceting
This page is used as a temporary work area for sketching the new (2023) facets API as described in #10995. So far API have been designed and refined in the main description of that issue, but this is making he following coments no longer related to it, so this is the reference page, that will be moved in the geonode doc files once this API is stable enough.
-
_GEONODE_VERSIONED_API_/facetsReturns a list of available facets The returned payload is a dict{"facets": [facet,...]}- GET params:
-
include_topics: bool, 0..1: include first n topics to every facet -
filter: string, 0..N: if
include_topics, this field is used to pre-filter resources (see pre-filtering) -
lang: bool, 0..1: return localized labels if possible -
add_links: bool, 0..1: add links to facets endpoint
-
- GET params:
-
_GEONODE_VERSIONED_API_/facets/<facet_name>Returns info for the requested facet. First page of topics is included.- GET params:
-
page/page_size: (int,int), 0..1: topics pagination params - filter: string, 0..N: used to pre-filter resources (see pre-filtering)
-
topic_contains: string, 0..1: used to pre-filter topics with a string -
lang: str (2 letters), 0..1: return localized labels if possible -
add_links: bool, 0..1: add links to prev/next pages
-
- GET params:
The filter parameters are parsed by the DREST library and are in the form filter{FIELD_EXPRESSION}=VALUE, for instance:
filter{metadata_only}=falsefilter{date.gte}=2023-06-01T00:00:00
-
facetis a dict:key type opt description namestr no Name of the facet (to be used in the /facet/<facet_name>entrypoint)filterkeystr no string to be used as KVP param in the resources query labelstr no Label for the facet (could be localized) is_localizedstr yes If exists and it's true, tells that the label is already translated and requires no further localization actions by the client typeenum no Type of facet, may be used by the client for rendering. So far region,category,people,thesaurushierarchicalbool yes noTells if the facet has nested elements (don't know if this is really useful) orderint opt May be useful for telling the UI how to present the facets
thesauri have their own internal ordering
(where can it be configured?)linkurl opt link to the facet
-/facets: requested using theadd_linksparam
-/facets/<ID>: N/Aprevurl opt link to previous paginated set of topics
-/facets: N/A
-/facets/<ID>: requested using theadd_linksparamnexturl opt link to next paginated set of topics
-/facets: N/A
-/facets/<ID>: requested using theadd_linksparamtopicsdict opt (see descr) Info on topic set.
-/facets: only present ifinclude_topicsrequested
-/facets/<ID>: always present -
topicsis a dict:key type description pageint page number page_sizeint number of topics per page startint initial # of topic in current page totalint total number of topics itemslist list of topic -
topicis a dict, having at least 3 mandatory elements:key type opt description keystr String to be used as KVP value in the query labelstr Label (may be localized) is_localizedstr yes If exists and it's true, tells that the label is already translated and requires no further localization actions by the client countint Count of facet's item in current filter
The topics may also have other elements, according to the Facet handler; i.e.:
- categories may have a link to an icon,
- regions may have a bbox
e.g.:
"items": [
{
"key": "Pianificazione",
"label": "Pianificazione",
"is_localized": true,
"count": 156,
"fa_class": "fa-home"
},The facets payloads provide all the info to create a filter on the resources.
In order to create a filter on the topic you need to add in the KVP string FACET_FILTER=ITEM_KEY.
For instance, if we have this payload:
{
"name": "3-2-4-1-gemet-inspire-themes-rdf",
"filter": "filter{tkeyword}",
"label": "Categorie tematiche INSPIRE",
"is_localized": true,
...
"topics": {
...
"items": [
{
"key": 36,
"label": "Zone a rischio naturale",
"is_localized": true,
"count": 152
},
...in order to filter by "Zone a rischio naturale" we need to add in the search query filter{tkeyword}=36
The faceting framework is extensible and configurable:
- faceting is implemented by extending a base class
FacetProvider - the list of facets can be configured in the setting:
FACET_PROVIDERS = ( "geonode.facets.providers.category.CategoryFacetProvider", "geonode.facets.providers.users.OwnerFacetProvider", "geonode.facets.providers.thesaurus.ThesaurusFacetProvider", )