diff --git a/CHANGELOG.md b/CHANGELOG.md index 49e8b95..7ab110e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] -TODO: add at least one Added, Changed, Deprecated, Removed, Fixed or Security section +### Added + +- Added `autocomplete_query` to `ParameterType`, which gives more flexibility than the existing `autocomplete` function (CMEM-6755). ## [4.13.0] 2025-09-09 diff --git a/cmem_plugin_base/dataintegration/types.py b/cmem_plugin_base/dataintegration/types.py index afc3134..e25d510 100644 --- a/cmem_plugin_base/dataintegration/types.py +++ b/cmem_plugin_base/dataintegration/types.py @@ -60,6 +60,17 @@ def to_string(self, value: T) -> str: """Convert parameter values into their string representation.""" return str(value) + def autocomplete_query( + self, query: str, depend_on_parameter_values: list[Any], context: PluginContext + ) -> list[Autocompletion]: + """Search for autocompletions based on a query string. + + Splits the query string into separate lower-cased terms and calls `autocomplete`. + Usually, it is preferred to implement `autocomplete` instead of this method. + """ + terms = [query.lower() for query in query.split() if query.strip()] + return self.autocomplete(terms, depend_on_parameter_values, context) + def autocomplete( self, query_terms: list[str], @@ -94,7 +105,10 @@ def autocompletion_enabled(self) -> bool: True, if autocompletion should be enabled on this type. By default, checks if the type implements its own autocomplete method. """ - return type(self).autocomplete != ParameterType.autocomplete + return ( + type(self).autocomplete != ParameterType.autocomplete + or type(self).autocomplete_query != ParameterType.autocomplete_query + ) class StringParameterType(ParameterType[str]):