Skip to content

Commit

Permalink
address typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Sep 2, 2024
1 parent 281017d commit a0244fe
Show file tree
Hide file tree
Showing 13 changed files with 1,285 additions and 1,274 deletions.
28 changes: 12 additions & 16 deletions elasticsearch_dsl/faceted_search_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,27 +173,26 @@ def __init__(

def get_value_filter(self, filter_value: FilterValueType) -> Query:
f, t = self._ranges[filter_value]
limits = {}
limits: Dict[str, Any] = {}
if f is not None:
limits["gte"] = f
if t is not None:
limits["lt"] = t

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


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

def get_value_filter(self, filter_value: FilterValueType) -> Range:
return Range(
_expand__to_dot=False,
**{
self._params["field"]: {
"gte": filter_value,
"lt": filter_value + self._params["interval"],
}
self._params["field"],
{
"gte": filter_value,
"lt": filter_value + self._params["interval"],
},
_expand__to_dot=False,
)


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

return Range(
_expand__to_dot=False,
**{
self._params["field"]: {
"gte": filter_value,
"lt": self.DATE_INTERVALS[self._params[interval_type]](
filter_value
),
}
self._params["field"],
{
"gte": filter_value,
"lt": self.DATE_INTERVALS[self._params[interval_type]](filter_value),
},
_expand__to_dot=False,
)


Expand Down
39 changes: 37 additions & 2 deletions elasticsearch_dsl/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@

import collections.abc
from copy import deepcopy
from typing import Any, ClassVar, Dict, MutableMapping, Optional, Union, overload
from typing import (
Any,
ClassVar,
Dict,
Literal,
MutableMapping,
Optional,
Union,
overload,
)

from .utils import DslBase
from .utils import NOT_SET, AttrDict, DslBase, NotSet


@overload
Expand Down Expand Up @@ -137,3 +146,29 @@ class Gauss(ScoreFunction):

class Exp(ScoreFunction):
name = "exp"


class DecayFunction(AttrDict[Any]):
def __init__(
self,
*,
decay: Union[float, "NotSet"] = NOT_SET,
offset: Any = NOT_SET,
scale: Any = NOT_SET,
origin: Any = NOT_SET,
multi_value_mode: Union[
Literal["min", "max", "avg", "sum"], "NotSet"
] = NOT_SET,
**kwargs: Any,
):
if not isinstance(decay, NotSet):
kwargs["decay"] = decay
if not isinstance(offset, NotSet):
kwargs["offset"] = offset
if not isinstance(scale, NotSet):
kwargs["offset"] = scale
if not isinstance(origin, NotSet):
kwargs["offset"] = origin
if not isinstance(multi_value_mode, NotSet):
kwargs["offset"] = multi_value_mode
super().__init__(kwargs)
Loading

0 comments on commit a0244fe

Please sign in to comment.