Skip to content

Commit

Permalink
simplified get_value_filter in Facet to return None
Browse files Browse the repository at this point in the history
added assert to test get_value_filter returning None

Signed-off-by: Mark Cohen <markcoh@amazon.com>
  • Loading branch information
macohen committed Jan 22, 2024
1 parent 07c11c5 commit 0528052
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
13 changes: 1 addition & 12 deletions opensearchpy/helpers/faceted_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from abc import abstractmethod
from datetime import datetime, timedelta
from typing import Any, Optional

Expand Down Expand Up @@ -85,12 +84,8 @@ def add_filter(self, filter_values: Any) -> Any:
f |= self.get_value_filter(v)
return f

@abstractmethod
def get_value_filter(self, filter_value: Any) -> Any:
"""
Construct a filter for an individual value
"""
...
return None

def is_filtered(self, key: Any, filter_values: Any) -> bool:
"""
Expand Down Expand Up @@ -137,9 +132,6 @@ def add_filter(self, filter_values: Any) -> Any:
_expand__to_dot=False, **{self._params["field"]: filter_values}
)

def get_value_filter(self, filter_value: Any) -> Any:
return None


class RangeFacet(Facet):
agg_type = "range"
Expand Down Expand Up @@ -276,9 +268,6 @@ def add_filter(self, filter_values: Any) -> Any:
if inner_q:
return Nested(path=self._path, query=inner_q)

def get_value_filter(self, filter_value: Any) -> Any:
return None


class FacetedResponse(Response):
@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ async def test_filters_are_applied_to_search_ant_relevant_facets() -> None:
"post_filter": {"bool": {}},
"highlight": {"fields": {"body": {}, "title": {}}},
} == d
assert bs["category"].get_value_filter(None) == None


async def test_date_histogram_facet_with_1970_01_01_date() -> None:
Expand Down
2 changes: 2 additions & 0 deletions test_opensearchpy/test_helpers/test_faceted_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def test_query_is_created_properly_with_sort_tuple() -> None:
"highlight": {"fields": {"body": {}, "title": {}}},
"sort": ["category", {"title": {"order": "desc"}}],
} == s.to_dict()
assert bs.facets["category"].get_value_filter(None) == None


def test_filter_is_applied_to_search_but_not_relevant_facet() -> None:
Expand All @@ -117,6 +118,7 @@ def test_filter_is_applied_to_search_but_not_relevant_facet() -> None:
},
"highlight": {"fields": {"body": {}, "title": {}}},
} == s.to_dict()
assert bs.facets["category"].get_value_filter(None) == None


def test_filters_are_applied_to_search_ant_relevant_facets() -> None:
Expand Down

0 comments on commit 0528052

Please sign in to comment.