Skip to content

Commit 83478e2

Browse files
committed
Search User Experience Improvements
Changes ======== * PYCBC-1690: Update SearchQuery to provide `__repr__` methods that reflect the query JSON that will be sent to the search service * Update tests to confirm functionality * PYCBC-1691: Improve developer experience by allowing various SearchQuery types to handle args and kwargs * Update docstrings and API docs Change-Id: Ib8b68f63faa4631a721a811c915e1370beead08e Reviewed-on: https://review.couchbase.org/c/couchbase-python-client/+/232130 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Dimitris Christodoulou <dimitris.christodoulou@couchbase.com>
1 parent 5930190 commit 83478e2

File tree

4 files changed

+1687
-212
lines changed

4 files changed

+1687
-212
lines changed

couchbase/logic/search.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ def _genprop_str(*apipaths, **kwargs):
119119

120120
@staticmethod
121121
def _gen_location(value):
122+
if isinstance(value, dict):
123+
if 'lon' in value and 'lat' in value:
124+
return [float(value['lon']), float(value['lat'])]
125+
raise InvalidArgumentException(message='Requires a dict with keys: lon, lat')
122126
if len(value) != 2 or not all(map(lambda pt: isinstance(pt, (int, float)), value)):
123127
raise InvalidArgumentException(message='Requires a tuple: (lon, lat)')
124128
return [float(value[0]), float(value[1])]
@@ -174,8 +178,7 @@ def _assign_kwargs(cls, kwargs):
174178
def _validate_range_query(self, r1, r2, **kwargs):
175179
_QueryBuilder._assign_kwargs(self, kwargs)
176180
if r1 is None and r2 is None:
177-
raise TypeError('At least one of {0} or {1} should be specified',
178-
*self._MINMAX)
181+
raise ValueError(f'At least one of the following params should be specified: {", ".join(self._MINMAX)}')
179182
if r1 is not None:
180183
setattr(self, self._MINMAX[0], r1)
181184
if r2 is not None:
@@ -198,10 +201,12 @@ def class_wrapper(cls):
198201
field_prop = _COMMON_FIELDS[f]
199202
setattr(cls, f, field_prop)
200203

201-
def new_init(self, term, *args, **kwargs):
204+
def new_init(self, *args, **kwargs):
202205
super(type(self), self).__init__()
203206
if self._TERMPROP not in kwargs:
204-
kwargs[self._TERMPROP] = term
207+
if len(args) == 0:
208+
raise ValueError(f'{cls.__name__} missing required property: {self._TERMPROP}')
209+
kwargs[self._TERMPROP] = args[0]
205210
_QueryBuilder._assign_kwargs(self, kwargs)
206211

207212
cls.__init__ = new_init

0 commit comments

Comments
 (0)