From d752b7c3a11d2dacf019fb14e2e8b4b057bb1570 Mon Sep 17 00:00:00 2001 From: nick Date: Sat, 13 Apr 2024 14:32:23 +0700 Subject: [PATCH 1/7] Implemented the composite aggregation feature --- .github/workflows/publish.yml | 33 ---- .github/workflows/test.yml | 2 +- docs/Aggregation.md | 1 + docs/AggregationComposite.md | 13 ++ docs/AggregationCompositeSourcesInnerValue.md | 11 ++ ...regationCompositeSourcesInnerValueTerms.md | 11 ++ docs/AggregationTerms.md | 4 +- docs/SearchRequest.md | 19 ++- manticoresearch/__init__.py | 3 + manticoresearch/model/__init__.py | 3 + manticoresearch/model/aggregation.py | 32 +++- .../model/aggregation_composite.py | 148 ++++++++++++++++++ ...gregation_composite_sources_inner_value.py | 120 ++++++++++++++ ...ion_composite_sources_inner_value_terms.py | 122 +++++++++++++++ manticoresearch/model/aggregation_terms.py | 8 +- manticoresearch/model/search_request.py | 4 + test/test_manual.py | 16 +- 17 files changed, 505 insertions(+), 45 deletions(-) delete mode 100644 .github/workflows/publish.yml create mode 100644 docs/AggregationComposite.md create mode 100644 docs/AggregationCompositeSourcesInnerValue.md create mode 100644 docs/AggregationCompositeSourcesInnerValueTerms.md create mode 100644 manticoresearch/model/aggregation_composite.py create mode 100644 manticoresearch/model/aggregation_composite_sources_inner_value.py create mode 100644 manticoresearch/model/aggregation_composite_sources_inner_value_terms.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 8749922..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Publishing - -on: [push] - -jobs: - test: - uses: ./.github/workflows/test.yml - publish: - name: Publish the client to the public registry - needs: [test] - runs-on: ubuntu-latest - env: - PYPIRC: ${{ secrets.PYPIRC }} - PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} - steps: - - uses: actions/checkout@v4 - - name: Use Python 3.10 - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Check for dev-version - if: ${{ contains(github.ref, 'master') }} - run: | - VERSION=`git log -1 --date=format:"%y%m%d%H" --format=%cd|head` - echo "version $VERSION" - sed -i -E "s/(VERSION = \")([0-9]\.[0-9]\.)(.*)(\")/\1\2$VERSION\4/1" setup.py - - name: Publish - run: | - echo $PYPIRC > ~/.pypirc - python -m pip install --user --upgrade wheel - python -m pip install --user --upgrade twine - python setup.py sdist bdist_wheel - python -m twine upload dist/* -u __token__ -p $PYPI_TOKEN diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7720972..3f9a92d 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,6 @@ name: Testing -on: [workflow_call] +on: [push] jobs: test: diff --git a/docs/Aggregation.md b/docs/Aggregation.md index 7a16e00..7d952f9 100644 --- a/docs/Aggregation.md +++ b/docs/Aggregation.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **terms** | [**AggregationTerms**](AggregationTerms.md) | | [optional] **sort** | [**[{str: (AggregationSortInnerValue,)}]**](AggregationSortInnerValue.md) | | [optional] +**composite** | [**AggregationComposite**](AggregationComposite.md) | | [optional] [[Using in search requests]](SearchApi.md#Aggregation) diff --git a/docs/AggregationComposite.md b/docs/AggregationComposite.md new file mode 100644 index 0000000..cb9b795 --- /dev/null +++ b/docs/AggregationComposite.md @@ -0,0 +1,13 @@ +# AggregationComposite + +Composite aggregation +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**size** | **int** | Maximum number of composite buckets in the result | [optional] +**sources** | [**[{str: (AggregationCompositeSourcesInnerValue,)}]**](AggregationCompositeSourcesInnerValue.md) | | [optional] + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/docs/AggregationCompositeSourcesInnerValue.md b/docs/AggregationCompositeSourcesInnerValue.md new file mode 100644 index 0000000..d8a875a --- /dev/null +++ b/docs/AggregationCompositeSourcesInnerValue.md @@ -0,0 +1,11 @@ +# AggregationCompositeSourcesInnerValue + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**terms** | [**AggregationCompositeSourcesInnerValueTerms**](AggregationCompositeSourcesInnerValueTerms.md) | | [optional] + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/docs/AggregationCompositeSourcesInnerValueTerms.md b/docs/AggregationCompositeSourcesInnerValueTerms.md new file mode 100644 index 0000000..0b7afaa --- /dev/null +++ b/docs/AggregationCompositeSourcesInnerValueTerms.md @@ -0,0 +1,11 @@ +# AggregationCompositeSourcesInnerValueTerms + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**field** | **str** | Name of attribute to aggregate by | [optional] + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/docs/AggregationTerms.md b/docs/AggregationTerms.md index dbd5b4b..5be7ef3 100644 --- a/docs/AggregationTerms.md +++ b/docs/AggregationTerms.md @@ -3,8 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**field** | **str** | Attribute Name to Aggregate | [optional] -**size** | **int** | Maximum Number of Buckets in the Result | [optional] +**field** | **str** | Name of attribute to aggregate by | [optional] +**size** | **int** | Maximum number of buckets in the result | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/docs/SearchRequest.md b/docs/SearchRequest.md index 5723b22..88dd317 100644 --- a/docs/SearchRequest.md +++ b/docs/SearchRequest.md @@ -140,11 +140,28 @@ Name | Type | Description | Notes aggTerms1 = AggregationTerms('year', 10) agg1 = Aggregation(aggTerms1) agg2 = Aggregation(AggregationTerms('rating'), ['rating']) + search_request.aggs = {'agg1': agg1} search_request.aggs['agg2'] = agg2 - + api_response = api_instance.search(search_req) pprint(api_response) + + # Composite aggregation + compAggTerms1 = AggregationCompositeSourcesInnerValueTerms('year') + compAgg1 = AggregationCompositeSourcesInnerValue(compAggTerms1) + compAggTerms2 = AggregationCompositeSourcesInnerValueTerms('rating') + compAgg2 = AggregationCompositeSourcesInnerValue(compAggTerms2) + compSources = {'comp_agg_1': compAgg1, 'comp_agg_2': compAgg2} + compAgg = AggregationComposite(size=5, sources=compSources) + agg = Aggregation(composite=compAgg) + + search_request.aggs = {'comp_agg': agg} + + api_response = api_instance.search(search_req) + pprint(api_response) + + ``` ### Highlight diff --git a/manticoresearch/__init__.py b/manticoresearch/__init__.py index 0cd9d13..c58d703 100644 --- a/manticoresearch/__init__.py +++ b/manticoresearch/__init__.py @@ -33,6 +33,9 @@ from manticoresearch.exceptions import ApiException # import models into sdk package from manticoresearch.model.aggregation import Aggregation +from manticoresearch.model.aggregation_composite import AggregationComposite +from manticoresearch.model.aggregation_composite_sources_inner_value import AggregationCompositeSourcesInnerValue +from manticoresearch.model.aggregation_composite_sources_inner_value_terms import AggregationCompositeSourcesInnerValueTerms from manticoresearch.model.aggregation_sort_inner_value import AggregationSortInnerValue from manticoresearch.model.aggregation_terms import AggregationTerms from manticoresearch.model.attr_filter import AttrFilter diff --git a/manticoresearch/model/__init__.py b/manticoresearch/model/__init__.py index 41a46ac..83acb67 100644 --- a/manticoresearch/model/__init__.py +++ b/manticoresearch/model/__init__.py @@ -16,6 +16,9 @@ # import models into model package from manticoresearch.model.aggregation import Aggregation +from manticoresearch.model.aggregation_composite import AggregationComposite +from manticoresearch.model.aggregation_composite_sources_inner_value import AggregationCompositeSourcesInnerValue +from manticoresearch.model.aggregation_composite_sources_inner_value_terms import AggregationCompositeSourcesInnerValueTerms from manticoresearch.model.aggregation_sort_inner_value import AggregationSortInnerValue from manticoresearch.model.aggregation_terms import AggregationTerms from manticoresearch.model.attr_filter import AttrFilter diff --git a/manticoresearch/model/aggregation.py b/manticoresearch/model/aggregation.py index 115fcb5..66e7d6f 100644 --- a/manticoresearch/model/aggregation.py +++ b/manticoresearch/model/aggregation.py @@ -31,15 +31,17 @@ class Aggregation(object): """ openapi_types = { 'terms': 'AggregationTerms', - 'sort': '[{str: (AggregationSortInnerValue,)}]' + 'sort': '[{str: (AggregationSortInnerValue,)}]', + 'composite': 'AggregationComposite' } attribute_map = { 'terms': 'terms', - 'sort': 'sort' + 'sort': 'sort', + 'composite': 'composite' } - def __init__(self, terms=None, sort=None, local_vars_configuration=None): # noqa: E501 + def __init__(self, terms=None, sort=None, composite=None, local_vars_configuration=None): # noqa: E501 """Aggregation - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() @@ -47,12 +49,15 @@ def __init__(self, terms=None, sort=None, local_vars_configuration=None): # noq self._terms = None self._sort = None + self._composite = None self.discriminator = None if terms is not None: self.terms = terms if sort is not None: self.sort = sort + if composite is not None: + self.composite = composite @property def terms(self): @@ -96,6 +101,27 @@ def sort(self, sort): self._sort = sort + @property + def composite(self): + """Gets the composite of this Aggregation. # noqa: E501 + + + :return: The composite of this Aggregation. # noqa: E501 + :rtype: AggregationComposite + """ + return self._composite + @composite.setter + def composite(self, composite): + """Sets the composite of this Aggregation. + + + :param composite: The composite of this Aggregation. # noqa: E501 + :type composite: AggregationComposite + """ + + self._composite = composite + + def to_dict(self): """Returns the model properties as a dict""" diff --git a/manticoresearch/model/aggregation_composite.py b/manticoresearch/model/aggregation_composite.py new file mode 100644 index 0000000..80637f2 --- /dev/null +++ b/manticoresearch/model/aggregation_composite.py @@ -0,0 +1,148 @@ +# coding: utf-8 + +# Manticore Search Client +# Copyright (c) 2020-2021, Manticore Software LTD (https://manticoresearch.com) +# +# All rights reserved +# + + + +import pprint +import re # noqa: F401 + +import six + +from manticoresearch.configuration import Configuration + +class AggregationComposite(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'size': 'int', + 'sources': '[{str: (AggregationCompositeSourcesInnerValue,)}]' + } + + attribute_map = { + 'size': 'size', + 'sources': 'sources' + } + + def __init__(self, size=None, sources=None, local_vars_configuration=None): # noqa: E501 + """AggregationComposite - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._size = None + self._sources = None + self.discriminator = None + + if size is not None: + self.size = size + if sources is not None: + self.sources = sources + + @property + def size(self): + """Gets the size of this AggregationComposite. # noqa: E501 + + Maximum number of composite buckets in the result # noqa: E501 + + :return: The size of this AggregationComposite. # noqa: E501 + :rtype: int + """ + return self._size + @size.setter + def size(self, size): + """Sets the size of this AggregationComposite. + + Maximum number of composite buckets in the result # noqa: E501 + + :param size: The size of this AggregationComposite. # noqa: E501 + :type size: int + """ + + self._size = size + + + @property + def sources(self): + """Gets the sources of this AggregationComposite. # noqa: E501 + + + :return: The sources of this AggregationComposite. # noqa: E501 + :rtype: [{str: (AggregationCompositeSourcesInnerValue,)}] + """ + return self._sources + @sources.setter + def sources(self, sources): + """Sets the sources of this AggregationComposite. + + + :param sources: The sources of this AggregationComposite. # noqa: E501 + :type sources: [{str: (AggregationCompositeSourcesInnerValue,)}] + """ + + self._sources = sources + + + + def to_dict(self): + """Returns the model properties as a dict""" + + result = {} + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, AggregationComposite): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, AggregationComposite): + return True + + return self.to_dict() != other.to_dict() diff --git a/manticoresearch/model/aggregation_composite_sources_inner_value.py b/manticoresearch/model/aggregation_composite_sources_inner_value.py new file mode 100644 index 0000000..bd75207 --- /dev/null +++ b/manticoresearch/model/aggregation_composite_sources_inner_value.py @@ -0,0 +1,120 @@ +# coding: utf-8 + +# Manticore Search Client +# Copyright (c) 2020-2021, Manticore Software LTD (https://manticoresearch.com) +# +# All rights reserved +# + + + +import pprint +import re # noqa: F401 + +import six + +from manticoresearch.configuration import Configuration + +class AggregationCompositeSourcesInnerValue(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'terms': 'AggregationCompositeSourcesInnerValueTerms' + } + + attribute_map = { + 'terms': 'terms' + } + + def __init__(self, terms=None, local_vars_configuration=None): # noqa: E501 + """AggregationCompositeSourcesInnerValue - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._terms = None + self.discriminator = None + + if terms is not None: + self.terms = terms + + @property + def terms(self): + """Gets the terms of this AggregationCompositeSourcesInnerValue. # noqa: E501 + + + :return: The terms of this AggregationCompositeSourcesInnerValue. # noqa: E501 + :rtype: AggregationCompositeSourcesInnerValueTerms + """ + return self._terms + @terms.setter + def terms(self, terms): + """Sets the terms of this AggregationCompositeSourcesInnerValue. + + + :param terms: The terms of this AggregationCompositeSourcesInnerValue. # noqa: E501 + :type terms: AggregationCompositeSourcesInnerValueTerms + """ + + self._terms = terms + + + + def to_dict(self): + """Returns the model properties as a dict""" + + result = {} + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, AggregationCompositeSourcesInnerValue): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, AggregationCompositeSourcesInnerValue): + return True + + return self.to_dict() != other.to_dict() diff --git a/manticoresearch/model/aggregation_composite_sources_inner_value_terms.py b/manticoresearch/model/aggregation_composite_sources_inner_value_terms.py new file mode 100644 index 0000000..2353a84 --- /dev/null +++ b/manticoresearch/model/aggregation_composite_sources_inner_value_terms.py @@ -0,0 +1,122 @@ +# coding: utf-8 + +# Manticore Search Client +# Copyright (c) 2020-2021, Manticore Software LTD (https://manticoresearch.com) +# +# All rights reserved +# + + + +import pprint +import re # noqa: F401 + +import six + +from manticoresearch.configuration import Configuration + +class AggregationCompositeSourcesInnerValueTerms(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'field': 'str' + } + + attribute_map = { + 'field': 'field' + } + + def __init__(self, field=None, local_vars_configuration=None): # noqa: E501 + """AggregationCompositeSourcesInnerValueTerms - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._field = None + self.discriminator = None + + if field is not None: + self.field = field + + @property + def field(self): + """Gets the field of this AggregationCompositeSourcesInnerValueTerms. # noqa: E501 + + Name of attribute to aggregate by # noqa: E501 + + :return: The field of this AggregationCompositeSourcesInnerValueTerms. # noqa: E501 + :rtype: str + """ + return self._field + @field.setter + def field(self, field): + """Sets the field of this AggregationCompositeSourcesInnerValueTerms. + + Name of attribute to aggregate by # noqa: E501 + + :param field: The field of this AggregationCompositeSourcesInnerValueTerms. # noqa: E501 + :type field: str + """ + + self._field = field + + + + def to_dict(self): + """Returns the model properties as a dict""" + + result = {} + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, AggregationCompositeSourcesInnerValueTerms): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, AggregationCompositeSourcesInnerValueTerms): + return True + + return self.to_dict() != other.to_dict() diff --git a/manticoresearch/model/aggregation_terms.py b/manticoresearch/model/aggregation_terms.py index f5361a8..1985fd3 100644 --- a/manticoresearch/model/aggregation_terms.py +++ b/manticoresearch/model/aggregation_terms.py @@ -58,7 +58,7 @@ def __init__(self, field=None, size=None, local_vars_configuration=None): # noq def field(self): """Gets the field of this AggregationTerms. # noqa: E501 - Attribute Name to Aggregate # noqa: E501 + Name of attribute to aggregate by # noqa: E501 :return: The field of this AggregationTerms. # noqa: E501 :rtype: str @@ -68,7 +68,7 @@ def field(self): def field(self, field): """Sets the field of this AggregationTerms. - Attribute Name to Aggregate # noqa: E501 + Name of attribute to aggregate by # noqa: E501 :param field: The field of this AggregationTerms. # noqa: E501 :type field: str @@ -81,7 +81,7 @@ def field(self, field): def size(self): """Gets the size of this AggregationTerms. # noqa: E501 - Maximum Number of Buckets in the Result # noqa: E501 + Maximum number of buckets in the result # noqa: E501 :return: The size of this AggregationTerms. # noqa: E501 :rtype: int @@ -91,7 +91,7 @@ def size(self): def size(self, size): """Sets the size of this AggregationTerms. - Maximum Number of Buckets in the Result # noqa: E501 + Maximum number of buckets in the result # noqa: E501 :param size: The size of this AggregationTerms. # noqa: E501 :type size: int diff --git a/manticoresearch/model/search_request.py b/manticoresearch/model/search_request.py index 90b504e..879a13c 100644 --- a/manticoresearch/model/search_request.py +++ b/manticoresearch/model/search_request.py @@ -570,6 +570,10 @@ def to_dict(self): for k,v in result['aggs'].items(): if v['sort'] is None: result['aggs'][k]['sort'] = [] + if v['terms'] is None: + result['aggs'][k]['terms'] = [] + if v['composite'] is None: + result['aggs'][k]['composite'] = [] if result['highlight'] is not None: if result['highlight']['fields'] is None: result['highlight']['fields'] = result['highlight']['fieldnames'] diff --git a/test/test_manual.py b/test/test_manual.py index 40659b2..dba4af5 100755 --- a/test/test_manual.py +++ b/test/test_manual.py @@ -82,7 +82,21 @@ def test_manual(self): agg2 = Aggregation(AggregationTerms('rating'), ['rating']) search_request.aggs = {'agg1': agg1} search_request.aggs['agg2'] = agg2 - + + res = searchApi.search(search_request) + pprint(res) + + compAggTerms1 = AggregationCompositeSourcesInnerValueTerms('_year') + compAgg1 = AggregationCompositeSourcesInnerValue(compAggTerms1) + compAggTerms2 = AggregationCompositeSourcesInnerValueTerms('rating') + compAgg2 = AggregationCompositeSourcesInnerValue(compAggTerms2) + compSources = {'comp_agg_1': compAgg1, 'comp_agg_2': compAgg2} + compAgg = AggregationComposite(size=5, sources=compSources) + agg = Aggregation(composite=compAgg) + search_request.aggs = {'comp_agg': agg} + + res = searchApi.search(search_request) + pprint(res) highlight = manticoresearch.model.Highlight() highlight.fieldnames = ['title'] From f7383f6c17d9f7d73c9f32e032146d43af715f9d Mon Sep 17 00:00:00 2001 From: nick Date: Sat, 13 Apr 2024 14:38:50 +0700 Subject: [PATCH 2/7] Fixed codestyle --- manticoresearch/model/search_request.py | 14 ++++++------- test/test_manual.py | 28 ++++++++++++------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/manticoresearch/model/search_request.py b/manticoresearch/model/search_request.py index 879a13c..13f964b 100644 --- a/manticoresearch/model/search_request.py +++ b/manticoresearch/model/search_request.py @@ -567,13 +567,13 @@ def to_dict(self): result['_source'] = result['source'] del result['source'] if result['aggs'] is not None: - for k,v in result['aggs'].items(): - if v['sort'] is None: - result['aggs'][k]['sort'] = [] - if v['terms'] is None: - result['aggs'][k]['terms'] = [] - if v['composite'] is None: - result['aggs'][k]['composite'] = [] + for k,v in result['aggs'].items(): + if v['sort'] is None: + result['aggs'][k]['sort'] = [] + if v['terms'] is None: + result['aggs'][k]['terms'] = [] + if v['composite'] is None: + result['aggs'][k]['composite'] = [] if result['highlight'] is not None: if result['highlight']['fields'] is None: result['highlight']['fields'] = result['highlight']['fieldnames'] diff --git a/test/test_manual.py b/test/test_manual.py index dba4af5..5b80d9b 100755 --- a/test/test_manual.py +++ b/test/test_manual.py @@ -83,20 +83,20 @@ def test_manual(self): search_request.aggs = {'agg1': agg1} search_request.aggs['agg2'] = agg2 - res = searchApi.search(search_request) - pprint(res) - - compAggTerms1 = AggregationCompositeSourcesInnerValueTerms('_year') - compAgg1 = AggregationCompositeSourcesInnerValue(compAggTerms1) - compAggTerms2 = AggregationCompositeSourcesInnerValueTerms('rating') - compAgg2 = AggregationCompositeSourcesInnerValue(compAggTerms2) - compSources = {'comp_agg_1': compAgg1, 'comp_agg_2': compAgg2} - compAgg = AggregationComposite(size=5, sources=compSources) - agg = Aggregation(composite=compAgg) - search_request.aggs = {'comp_agg': agg} - - res = searchApi.search(search_request) - pprint(res) + res = searchApi.search(search_request) + pprint(res) + + compAggTerms1 = AggregationCompositeSourcesInnerValueTerms('_year') + compAgg1 = AggregationCompositeSourcesInnerValue(compAggTerms1) + compAggTerms2 = AggregationCompositeSourcesInnerValueTerms('rating') + compAgg2 = AggregationCompositeSourcesInnerValue(compAggTerms2) + compSources = {'comp_agg_1': compAgg1, 'comp_agg_2': compAgg2} + compAgg = AggregationComposite(size=5, sources=compSources) + agg = Aggregation(composite=compAgg) + search_request.aggs = {'comp_agg': agg} + + res = searchApi.search(search_request) + pprint(res) highlight = manticoresearch.model.Highlight() highlight.fieldnames = ['title'] From 0080dde16257fd969d84141f479d6a53793044f6 Mon Sep 17 00:00:00 2001 From: nick Date: Sat, 13 Apr 2024 14:47:57 +0700 Subject: [PATCH 3/7] Updated tests --- test/test_manual.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_manual.py b/test/test_manual.py index 5b80d9b..1385f15 100755 --- a/test/test_manual.py +++ b/test/test_manual.py @@ -94,6 +94,7 @@ def test_manual(self): compAgg = AggregationComposite(size=5, sources=compSources) agg = Aggregation(composite=compAgg) search_request.aggs = {'comp_agg': agg} + pprint(search_request.to_dict()) res = searchApi.search(search_request) pprint(res) From cf695ad3f71fbc9e08a15b3e8aec6c5257be4df7 Mon Sep 17 00:00:00 2001 From: nick Date: Sat, 13 Apr 2024 15:01:56 +0700 Subject: [PATCH 4/7] Fixed codestyle --- test/test_manual.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_manual.py b/test/test_manual.py index 1385f15..a0d100c 100755 --- a/test/test_manual.py +++ b/test/test_manual.py @@ -94,7 +94,7 @@ def test_manual(self): compAgg = AggregationComposite(size=5, sources=compSources) agg = Aggregation(composite=compAgg) search_request.aggs = {'comp_agg': agg} - pprint(search_request.to_dict()) + pprint(search_request.to_dict()) res = searchApi.search(search_request) pprint(res) From b6400cfff6bd21cf8ee26374928dec6390972475 Mon Sep 17 00:00:00 2001 From: nick Date: Sat, 13 Apr 2024 15:37:20 +0700 Subject: [PATCH 5/7] Updated tests --- test/test_manual.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_manual.py b/test/test_manual.py index a0d100c..09fdabe 100755 --- a/test/test_manual.py +++ b/test/test_manual.py @@ -90,7 +90,7 @@ def test_manual(self): compAgg1 = AggregationCompositeSourcesInnerValue(compAggTerms1) compAggTerms2 = AggregationCompositeSourcesInnerValueTerms('rating') compAgg2 = AggregationCompositeSourcesInnerValue(compAggTerms2) - compSources = {'comp_agg_1': compAgg1, 'comp_agg_2': compAgg2} + compSources = [{'comp_agg_1': compAgg1}, {'comp_agg_2': compAgg2}] compAgg = AggregationComposite(size=5, sources=compSources) agg = Aggregation(composite=compAgg) search_request.aggs = {'comp_agg': agg} From 7e08f6f696f407a6de2f0f58b22b6acd38568e6f Mon Sep 17 00:00:00 2001 From: nick Date: Sat, 13 Apr 2024 16:18:31 +0700 Subject: [PATCH 6/7] Updated tests --- docs/SearchRequest.md | 2 +- manticoresearch/model/search_request.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/SearchRequest.md b/docs/SearchRequest.md index 88dd317..c12a036 100644 --- a/docs/SearchRequest.md +++ b/docs/SearchRequest.md @@ -152,7 +152,7 @@ Name | Type | Description | Notes compAgg1 = AggregationCompositeSourcesInnerValue(compAggTerms1) compAggTerms2 = AggregationCompositeSourcesInnerValueTerms('rating') compAgg2 = AggregationCompositeSourcesInnerValue(compAggTerms2) - compSources = {'comp_agg_1': compAgg1, 'comp_agg_2': compAgg2} + compSources = [{'comp_agg_1': compAgg1}, {'comp_agg_2': compAgg2}] compAgg = AggregationComposite(size=5, sources=compSources) agg = Aggregation(composite=compAgg) diff --git a/manticoresearch/model/search_request.py b/manticoresearch/model/search_request.py index 13f964b..c3e3995 100644 --- a/manticoresearch/model/search_request.py +++ b/manticoresearch/model/search_request.py @@ -568,12 +568,10 @@ def to_dict(self): del result['source'] if result['aggs'] is not None: for k,v in result['aggs'].items(): + if v['composite'] is not None: + del result['aggs'][k]['terms'] if v['sort'] is None: - result['aggs'][k]['sort'] = [] - if v['terms'] is None: - result['aggs'][k]['terms'] = [] - if v['composite'] is None: - result['aggs'][k]['composite'] = [] + del result['aggs'][k]['sort'] if result['highlight'] is not None: if result['highlight']['fields'] is None: result['highlight']['fields'] = result['highlight']['fieldnames'] From c52e635bb3b120d11dfcae79e0e9bff7d4232536 Mon Sep 17 00:00:00 2001 From: nick Date: Sat, 13 Apr 2024 16:21:30 +0700 Subject: [PATCH 7/7] Updated tests --- test/test_manual.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/test_manual.py b/test/test_manual.py index 09fdabe..05e62c7 100755 --- a/test/test_manual.py +++ b/test/test_manual.py @@ -84,7 +84,6 @@ def test_manual(self): search_request.aggs['agg2'] = agg2 res = searchApi.search(search_request) - pprint(res) compAggTerms1 = AggregationCompositeSourcesInnerValueTerms('_year') compAgg1 = AggregationCompositeSourcesInnerValue(compAggTerms1) @@ -94,10 +93,8 @@ def test_manual(self): compAgg = AggregationComposite(size=5, sources=compSources) agg = Aggregation(composite=compAgg) search_request.aggs = {'comp_agg': agg} - pprint(search_request.to_dict()) res = searchApi.search(search_request) - pprint(res) highlight = manticoresearch.model.Highlight() highlight.fieldnames = ['title']