Skip to content

Commit 3886d0f

Browse files
authored
Merge pull request #32 from eccenca/feature/autocomplete-CMEM-6755
Added `autocomplete_query` to `ParameterType`, which gives more flexibility than the existing `autocomplete` function.
2 parents 6f160ce + a6a7c54 commit 3886d0f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
77

88
## [Unreleased]
99

10-
TODO: add at least one Added, Changed, Deprecated, Removed, Fixed or Security section
10+
### Added
11+
12+
- Added `autocomplete_query` to `ParameterType`, which gives more flexibility than the existing `autocomplete` function (CMEM-6755).
1113

1214
## [4.13.0] 2025-09-09
1315

cmem_plugin_base/dataintegration/types.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ def to_string(self, value: T) -> str:
6060
"""Convert parameter values into their string representation."""
6161
return str(value)
6262

63+
def autocomplete_query(
64+
self, query: str, depend_on_parameter_values: list[Any], context: PluginContext
65+
) -> list[Autocompletion]:
66+
"""Search for autocompletions based on a query string.
67+
68+
Splits the query string into separate lower-cased terms and calls `autocomplete`.
69+
Usually, it is preferred to implement `autocomplete` instead of this method.
70+
"""
71+
terms = [query.lower() for query in query.split() if query.strip()]
72+
return self.autocomplete(terms, depend_on_parameter_values, context)
73+
6374
def autocomplete(
6475
self,
6576
query_terms: list[str],
@@ -94,7 +105,10 @@ def autocompletion_enabled(self) -> bool:
94105
True, if autocompletion should be enabled on this type.
95106
By default, checks if the type implements its own autocomplete method.
96107
"""
97-
return type(self).autocomplete != ParameterType.autocomplete
108+
return (
109+
type(self).autocomplete != ParameterType.autocomplete
110+
or type(self).autocomplete_query != ParameterType.autocomplete_query
111+
)
98112

99113

100114
class StringParameterType(ParameterType[str]):

0 commit comments

Comments
 (0)