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

Implemented the composite aggregation feature #13

Merged
merged 7 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 0 additions & 33 deletions .github/workflows/publish.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Testing

on: [workflow_call]
on: [push]

jobs:
test:
Expand Down
1 change: 1 addition & 0 deletions docs/Aggregation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 13 additions & 0 deletions docs/AggregationComposite.md
Original file line number Diff line number Diff line change
@@ -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)


11 changes: 11 additions & 0 deletions docs/AggregationCompositeSourcesInnerValue.md
Original file line number Diff line number Diff line change
@@ -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)


11 changes: 11 additions & 0 deletions docs/AggregationCompositeSourcesInnerValueTerms.md
Original file line number Diff line number Diff line change
@@ -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)


4 changes: 2 additions & 2 deletions docs/AggregationTerms.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion docs/SearchRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions manticoresearch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions manticoresearch/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 29 additions & 3 deletions manticoresearch/model/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,33 @@ 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()
self.local_vars_configuration = local_vars_configuration

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):
Expand Down Expand Up @@ -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"""
Expand Down
148 changes: 148 additions & 0 deletions manticoresearch/model/aggregation_composite.py
Original file line number Diff line number Diff line change
@@ -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()
Loading
Loading