diff --git a/pycsw/core/pygeofilter_evaluate.py b/pycsw/core/pygeofilter_evaluate.py index e6211d1a8..77cb12568 100644 --- a/pycsw/core/pygeofilter_evaluate.py +++ b/pycsw/core/pygeofilter_evaluate.py @@ -66,9 +66,16 @@ def ilike(self, node, lhs): LOGGER.debug(f'Term: {node.pattern}') if (str(lhs.prop) == 'dataset.anytext' and self._pycsw_dbtype.startswith('postgres')): - if '%' not in node.pattern: + if not node.pattern.startswith('%'): LOGGER.debug('Kicking into PostgreSQL FTS mode') - return text(f"plainto_tsquery('english', '{node.pattern}') @@ anytext_tsvector") # noqa + if node.pattern.endswith('%'): + LOGGER.debug('Fuzzy term search') + term = node.pattern.replace('%', ':*') + else: + LOGGER.debug('Normal term search') + term = node.pattern + LOGGER.debug(f"FTS term: {term}") + return text(f"to_tsquery('english', '{term}') @@ anytext_tsvector") # noqa LOGGER.debug('Default ILIKE behaviour') return filters.like(