Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue 769:Collapse not preserved when chaining a search instance #771

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Deprecated
### Removed
### Fixed
- Fixed issue 769: Collapse not preserved when chaining a search instance ([#771](https://github.com/opensearch-project/opensearch-py/pull/771))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@imvtsl, thank you for the contribution. Please change the changelog entry to something like: 'Fixed Search helper to ensure proper retention of the _collapse attribute in chained operations.' No need to mention the issue number.

Copy link
Contributor Author

@imvtsl imvtsl Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the change. Thank you!
I believe you will have to approve again. It dismissed review automatically as soon as I pushed the change.

### Updated APIs
- Updated opensearch-py APIs to reflect [opensearch-api-specification@7452827](https://github.com/opensearch-project/opensearch-api-specification/commit/745282767026703ea27967d2705633c3e2661c97)
- Updated opensearch-py APIs to reflect [opensearch-api-specification@f2afd71](https://github.com/opensearch-project/opensearch-api-specification/commit/f2afd7171406c7477fbd644d74087bb0e2948c75)
Expand Down
1 change: 1 addition & 0 deletions opensearchpy/helpers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def _clone(self) -> Any:
s._highlight_opts = self._highlight_opts.copy()
s._suggest = self._suggest.copy()
s._script_fields = self._script_fields.copy()
s._collapse = self._collapse.copy()
for x in ("query", "post_filter"):
getattr(s, x)._proxied = getattr(self, x)._proxied

Expand Down
16 changes: 16 additions & 0 deletions test_opensearchpy/test_helpers/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,19 @@ def test_rescore_query_to_dict() -> None:
},
},
}


def test_collapse_chaining() -> None:
s = search.Search(index="index_name")
s = s.filter("term", color="red")
s = s.collapse(field="category")
s = s.filter("term", brand="something")

assert {
"query": {
"bool": {
"filter": [{"term": {"color": "red"}}, {"term": {"brand": "something"}}]
}
},
"collapse": {"field": "category"},
} == s.to_dict()
Loading