Skip to content

Commit ef8d929

Browse files
address typing issues
1 parent 281017d commit ef8d929

13 files changed

+1247
-1240
lines changed

elasticsearch_dsl/faceted_search_base.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,27 +173,26 @@ def __init__(
173173

174174
def get_value_filter(self, filter_value: FilterValueType) -> Query:
175175
f, t = self._ranges[filter_value]
176-
limits = {}
176+
limits: Dict[str, Any] = {}
177177
if f is not None:
178178
limits["gte"] = f
179179
if t is not None:
180180
limits["lt"] = t
181181

182-
return Range(_expand__to_dot=False, **{self._params["field"]: limits})
182+
return Range(self._params["field"], limits, _expand__to_dot=False)
183183

184184

185185
class HistogramFacet(Facet[_R]):
186186
agg_type = "histogram"
187187

188188
def get_value_filter(self, filter_value: FilterValueType) -> Range:
189189
return Range(
190-
_expand__to_dot=False,
191-
**{
192-
self._params["field"]: {
193-
"gte": filter_value,
194-
"lt": filter_value + self._params["interval"],
195-
}
190+
self._params["field"],
191+
{
192+
"gte": filter_value,
193+
"lt": filter_value + self._params["interval"],
196194
},
195+
_expand__to_dot=False,
197196
)
198197

199198

@@ -258,15 +257,12 @@ def get_value_filter(self, filter_value: Any) -> Range:
258257
interval_type = "interval"
259258

260259
return Range(
261-
_expand__to_dot=False,
262-
**{
263-
self._params["field"]: {
264-
"gte": filter_value,
265-
"lt": self.DATE_INTERVALS[self._params[interval_type]](
266-
filter_value
267-
),
268-
}
260+
self._params["field"],
261+
{
262+
"gte": filter_value,
263+
"lt": self.DATE_INTERVALS[self._params[interval_type]](filter_value),
269264
},
265+
_expand__to_dot=False,
270266
)
271267

272268

elasticsearch_dsl/function.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@
1717

1818
import collections.abc
1919
from copy import deepcopy
20-
from typing import Any, ClassVar, Dict, MutableMapping, Optional, Union, overload
20+
from typing import (
21+
Any,
22+
ClassVar,
23+
Dict,
24+
Literal,
25+
MutableMapping,
26+
Optional,
27+
Union,
28+
overload,
29+
)
2130

22-
from .utils import DslBase
31+
from .utils import NOT_SET, AttrDict, DslBase, NotSet
2332

2433

2534
@overload
@@ -137,3 +146,29 @@ class Gauss(ScoreFunction):
137146

138147
class Exp(ScoreFunction):
139148
name = "exp"
149+
150+
151+
class DecayFunction(AttrDict[Any]):
152+
def __init__(
153+
self,
154+
*,
155+
decay: Union[float, "NotSet"] = NOT_SET,
156+
offset: Any = NOT_SET,
157+
scale: Any = NOT_SET,
158+
origin: Any = NOT_SET,
159+
multi_value_mode: Union[
160+
Literal["min", "max", "avg", "sum"], "NotSet"
161+
] = NOT_SET,
162+
**kwargs: Any,
163+
):
164+
if not isinstance(decay, NotSet):
165+
kwargs["decay"] = decay
166+
if not isinstance(offset, NotSet):
167+
kwargs["offset"] = offset
168+
if not isinstance(scale, NotSet):
169+
kwargs["offset"] = scale
170+
if not isinstance(origin, NotSet):
171+
kwargs["offset"] = origin
172+
if not isinstance(multi_value_mode, NotSet):
173+
kwargs["offset"] = multi_value_mode
174+
super().__init__(kwargs)

0 commit comments

Comments
 (0)