Skip to content

CSW search by keyword (dc:subject) is unsupported #11207

Open
@fvicent

Description

@fvicent

Expected Behavior

You should be able to filter by dc:subject (=keywords in pycsw and geonode) within a CSW query.

Actual Behavior

A simple query filtering by keyword returns "Invalid query syntax".

Steps to Reproduce the Problem

Make a GetRecords request against the CSW endpoint:

curl -d "@payload.xml" -X POST "http://localhost/catalogue/csw?service=CSW&version=2.0.2"

With the following payload.xml:

<csw:GetRecords
	xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"
	xmlns:ogc="http://www.opengis.net/ogc"
	xmlns:gml="http://www.opengis.net/gml"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:dct="http://purl.org/dc/terms/"
	xmlns:gmd="http://www.isotc211.org/2005/gmd"
	xmlns:gco="http://www.isotc211.org/2005/gco"
	xmlns:gmi="http://www.isotc211.org/2005/gmi"
	xmlns:ows="http://www.opengis.net/ows" service="CSW" version="2.0.2" resultType="results" startPosition="1" maxRecords="4">
	<csw:Query typeNames="csw:Record">
		<csw:ElementSetName>full</csw:ElementSetName>
		<csw:Constraint version="1.1.0">
			<ogc:Filter>
				<ogc:PropertyIsEqualTo>
					<ogc:PropertyName>dc:subject</ogc:PropertyName>
					<ogc:Literal>something</ogc:Literal>
				</ogc:PropertyIsEqualTo>
			</ogc:Filter>
		</csw:Constraint>
	</csw:Query>
</csw:GetRecords>

Response:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- pycsw 2.6.1 -->
<ows:ExceptionReport xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2.0" language="en" xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd">
  <ows:Exception exceptionCode="InvalidParameterValue" locator="constraint">
    <ows:ExceptionText>Invalid query syntax</ows:ExceptionText>
  </ows:Exception>
</ows:ExceptionReport>

But the syntax is valid, since replacing dc:subject by dc:title works as expected.

This is the exception reported by pycsw:

Invalid query syntax.  Query: {'type': 'filter', 'where': 'keyword_csv = %s', 'values': ['asd'], '_dict': {'ogc:Filter': {'ogc:PropertyIsEqualTo': {'ogc:PropertyName': 'dc:subject', 'ogc:Literal': 'asd'}}}}
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedColumn: column "keyword_csv" does not exist
LINE 1: ...et') AND (uuid IS NOT NULL AND id IN (1, 2)) AND (keyword_cs...
                                                             ^


The above exception was the direct cause of the following exception:

Invalid query syntax.  Query: {'type': 'filter', 'where': 'keyword_csv = %s', 'values': ['asd'], '_dict': {'ogc:Filter': {'ogc:PropertyIsEqualTo': {'ogc:PropertyName': 'dc:subject', 'ogc:Literal': 'asd'}}}}
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedColumn: column "keyword_csv" does not exist
LINE 1: ...et') AND (uuid IS NOT NULL AND id IN (1, 2)) AND (keyword_cs...
                                                             ^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/pycsw/ogc/csw/csw2.py", line 821, in getrecords
    matched, results = self.parent.repository.query(
  File "/usr/src/geonode/./geonode/catalogue/backends/pycsw_plugin.py", line 165, in query
    total = query.count()
  File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 412, in count
    return self.query.get_count(using=self.db)
  File "/usr/local/lib/python3.10/dist-packages/django/db/models/sql/query.py", line 528, in get_count
    number = obj.get_aggregation(using, ['__count'])['__count']
  File "/usr/local/lib/python3.10/dist-packages/django/db/models/sql/query.py", line 513, in get_aggregation
    result = compiler.execute_sql(SINGLE)
  File "/usr/local/lib/python3.10/dist-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 79, in _execute
    with self.db.wrap_database_errors:
  File "/usr/local/lib/python3.10/dist-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column "keyword_csv" does not exist
LINE 1: ...et') AND (uuid IS NOT NULL AND id IN (1, 2)) AND (keyword_cs...

Which makes sense since keyword_csv is no table field but a model property:

geonode/geonode/base/models.py

Lines 1339 to 1348 in f3a490a

@property
def keyword_csv(self):
try:
keywords_qs = self.get_real_instance().keywords.all()
if keywords_qs:
return ",".join(kw.name for kw in keywords_qs)
else:
return ""
except Exception:
return ""

Specifications

  • GeoNode version: 4.1.0-dev
  • Installation type (vanilla, geonode-project): vanilla
  • Installation method (manual, docker): docker
  • Platform:
  • Additional details:

Metadata

Metadata

Assignees

Labels

masterminorA low priority issue which might affect only some users and /or not the main functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions