From 6d4af5c10fd2f415a2fd7a93a92b9376ee8ead63 Mon Sep 17 00:00:00 2001 From: Angelos Tzotsos Date: Sat, 23 Sep 2023 13:06:44 +0300 Subject: [PATCH] Taking into consideration PostgreSQL FTS fuzzy term search vs ILIKE search --- pycsw/core/pygeofilter_evaluate.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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(