7676 'http://www.opengis.net/spec/ogcapi-records-1/1.0/conf/sorting' ,
7777 'http://www.opengis.net/spec/ogcapi-records-1/1.0/conf/json' ,
7878 'http://www.opengis.net/spec/ogcapi-records-1/1.0/conf/html' ,
79+ 'http://www.opengis.net/spec/ogcapi-records-2/1.0/conf/simple' ,
80+ 'http://www.opengis.net/spec/ogcapi-records-4/1.0/conf/federated-search' ,
7981 'http://www.opengis.net/spec/cql2/1.0/conf/cql2-json' ,
8082 'http://www.opengis.net/spec/cql2/1.0/conf/cql2-text'
8183]
@@ -529,6 +531,8 @@ def queryables(self, headers_, args, collection='metadata:main'):
529531 for key , value in properties .items ():
530532 if key in self .repository .query_mappings or key == 'geometry' :
531533 properties2 [key ] = value
534+ if key in self .facets :
535+ properties2 [key ]['facet' ] = True
532536
533537 if collection == 'metadata:main' :
534538 title = self .config ['metadata' ]['identification' ]['title' ]
@@ -548,6 +552,53 @@ def queryables(self, headers_, args, collection='metadata:main'):
548552
549553 return self .get_response (200 , headers_ , response , 'queryables.html' )
550554
555+ def facets_ (self , headers_ , args , collection = 'metadata:main' ):
556+ """
557+ Provide collection facets
558+
559+ :param headers_: copy of HEADERS object
560+ :param args: request parameters
561+ :param collection: name of collection
562+
563+ :returns: tuple of headers, status code, content
564+ """
565+
566+ facets_ = {}
567+ headers_ ['Content-Type' ] = self .get_content_type (headers_ , args )
568+
569+ if 'json' in headers_ ['Content-Type' ]:
570+ headers_ ['Content-Type' ] = 'application/facets+json'
571+
572+ if collection not in self .get_collections (collection = collection ):
573+ msg = 'Invalid collection'
574+ LOGGER .exception (msg )
575+ return self .get_exception (400 , headers_ , 'InvalidParameterValue' , msg )
576+
577+ for value in self .config ['repository' ]['facets' ]:
578+ facets_ [value ] = {
579+ 'type' : 'term' ,
580+ 'property' : value ,
581+ 'sortedBy' : 'count'
582+ }
583+
584+ if collection == 'metadata:main' :
585+ title = self .config ['metadata' ]['identification' ]['title' ]
586+ else :
587+ title = self .config ['metadata' ]['identification' ]['title' ]
588+ virtual_collection = self .repository .query_ids ([collection ])[0 ]
589+ title = virtual_collection .title
590+
591+ response = {
592+ 'id' : collection ,
593+ 'type' : 'object' ,
594+ 'title' : title ,
595+ 'facets' : facets_ ,
596+ '$schema' : 'http://json-schema.org/draft/2019-09/schema' ,
597+ '$id' : f"{ self .config ['server' ]['url' ]} /collections/{ collection } /facets"
598+ }
599+
600+ return self .get_response (200 , headers_ , response , 'facets.html' )
601+
551602 def items (self , headers_ , json_post_data , args , collection = 'metadata:main' ):
552603 """
553604 Provide collection items
@@ -818,6 +869,7 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
818869 distributed = str2bool (args .get ('distributedsearch' , False ))
819870
820871 if distributed :
872+ args .pop ('distributedsearch' )
821873 distributed_search = self .config .get ('distributedsearch' , {})
822874 merge_results = distributed_search .get ('merge_results' , False )
823875
@@ -833,7 +885,6 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
833885 }
834886 try :
835887 w = Records (fc_url )
836- args .pop ('distributedsearch' )
837888 fc_results = w .collection_items (fc_collection , ** args )
838889 for feature in fc_results ['features' ]:
839890 if merge_results :
@@ -849,6 +900,8 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
849900 for key , value in fsrs .items ():
850901 response ['features' ].extend (value ['features' ])
851902
903+ args ['distributedSearch' ] = 'true'
904+
852905 LOGGER .debug ('Creating links' )
853906
854907 link_args = {** args }
0 commit comments