From 071d81e8d3cbf43cd6c0b77d728f26c26df91a2a Mon Sep 17 00:00:00 2001 From: nick Date: Sat, 13 Apr 2024 17:36:35 +0700 Subject: [PATCH] Implemented composite aggregation --- docs/Aggregation.md | 1 + docs/AggregationComposite.md | 12 +++ docs/AggregationCompositeSourcesInnerValue.md | 11 +++ ...regationCompositeSourcesInnerValueTerms.md | 11 +++ docs/AggregationTerms.md | 4 +- docs/SearchRequest.md | 15 ++++ src/index.js | 21 ++++- src/model/Aggregation.js | 15 +++- src/model/AggregationComposite.js | 79 +++++++++++++++++++ .../AggregationCompositeSourcesInnerValue.js | 70 ++++++++++++++++ ...regationCompositeSourcesInnerValueTerms.js | 71 +++++++++++++++++ src/model/AggregationTerms.js | 4 +- test/api/Manual.spec.js | 51 +++++++----- 13 files changed, 334 insertions(+), 31 deletions(-) create mode 100644 docs/AggregationComposite.md create mode 100644 docs/AggregationCompositeSourcesInnerValue.md create mode 100644 docs/AggregationCompositeSourcesInnerValueTerms.md create mode 100644 src/model/AggregationComposite.js create mode 100644 src/model/AggregationCompositeSourcesInnerValue.js create mode 100644 src/model/AggregationCompositeSourcesInnerValueTerms.js diff --git a/docs/Aggregation.md b/docs/Aggregation.md index e38767b..70ab512 100644 --- a/docs/Aggregation.md +++ b/docs/Aggregation.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **terms** | [**AggregationTerms**](AggregationTerms.md) | | [optional] **sort** | **[{String: AggregationSortInnerValue}]** | | [optional] +**composite** | [**AggregationComposite**](AggregationComposite.md) | | [optional] [[Using in search requests]](SearchRequest.md#Aggregation) diff --git a/docs/AggregationComposite.md b/docs/AggregationComposite.md new file mode 100644 index 0000000..74a8e6a --- /dev/null +++ b/docs/AggregationComposite.md @@ -0,0 +1,12 @@ +# Manticoresearch.AggregationComposite + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**size** | **Number** | Maximum number of composite buckets in the result | [optional] +**sources** | **[{String: AggregationCompositeSourcesInnerValue}]** | | [optional] + + + + diff --git a/docs/AggregationCompositeSourcesInnerValue.md b/docs/AggregationCompositeSourcesInnerValue.md new file mode 100644 index 0000000..7726264 --- /dev/null +++ b/docs/AggregationCompositeSourcesInnerValue.md @@ -0,0 +1,11 @@ +# Manticoresearch.AggregationCompositeSourcesInnerValue + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**terms** | [**AggregationCompositeSourcesInnerValueTerms**](AggregationCompositeSourcesInnerValueTerms.md) | | [optional] + + + + diff --git a/docs/AggregationCompositeSourcesInnerValueTerms.md b/docs/AggregationCompositeSourcesInnerValueTerms.md new file mode 100644 index 0000000..c39c79b --- /dev/null +++ b/docs/AggregationCompositeSourcesInnerValueTerms.md @@ -0,0 +1,11 @@ +# Manticoresearch.AggregationCompositeSourcesInnerValueTerms + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**field** | **String** | Name of attribute to aggregate by | [optional] + + + + diff --git a/docs/AggregationTerms.md b/docs/AggregationTerms.md index 4e90a24..abe430f 100644 --- a/docs/AggregationTerms.md +++ b/docs/AggregationTerms.md @@ -4,8 +4,8 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**field** | **String** | Attribute Name to Aggregate | [optional] -**size** | **Number** | Maximum Number of Buckets in the Result | [optional] +**field** | **String** | Name of attribute to aggregate by | [optional] +**size** | **Number** | Maximum number of buckets in the result | [optional] diff --git a/docs/SearchRequest.md b/docs/SearchRequest.md index b8e48a3..7523fe0 100644 --- a/docs/SearchRequest.md +++ b/docs/SearchRequest.md @@ -147,6 +147,21 @@ var agg2 = new Manticoresearch.Aggregation(); agg2['terms'] = Manticoresearch.AggregationTerms.constructFromObject({field: 'rating'}); searchRequest.aggs['agg2'] = agg2; +async function(){ + var res = await searchApi.search(searchRequest); + console.log(JSON.stringify(res, null, 4)); +} + +// Composite aggregation example +var compAggTerms1 = Manticoresearch.AggregationCompositeSourcesInnerValueTerms.constructFromObject({field: '_year'}); +var compAgg1 = Manticoresearch.AggregationCompositeSourcesInnerValue.constructFromObject({'terms': compAggTerms1}) +var compAggTerms2 = Manticoresearch.AggregationCompositeSourcesInnerValueTerms.constructFromObject({field: 'rating'}); +var compAgg2 = Manticoresearch.AggregationCompositeSourcesInnerValue.constructFromObject({'terms': compAggTerms2}); +var compSources = [{'comp_agg_1': compAgg1}, {'comp_agg_2': compAgg2}]; +var compAgg = Manticoresearch.AggregationComposite.constructFromObject({'size': 5, 'sources': compSources}); +var agg = Manticoresearch.Aggregation.constructFromObject({'composite': compAgg}); +searchRequest.aggs = {'comp_agg': agg}; + async function(){ var res = await searchApi.search(searchRequest); console.log(JSON.stringify(res, null, 4)); diff --git a/src/index.js b/src/index.js index 16a337f..32e3f7d 100644 --- a/src/index.js +++ b/src/index.js @@ -8,12 +8,12 @@ (function(factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. - define(['ApiClient', 'model/Aggregation', 'model/AggregationSortInnerValue', 'model/AggregationTerms', 'model/BoolFilter', 'model/BulkResponse', 'model/DeleteDocumentRequest', 'model/DeleteResponse', 'model/EqualsFilter', 'model/ErrorResponse', 'model/Facet', 'model/FilterBoolean', 'model/FilterNumber', 'model/FilterString', 'model/GeoDistanceFilter', 'model/GeoDistanceFilterLocationAnchor', 'model/Highlight', 'model/HighlightField', 'model/InFilter', 'model/InsertDocumentRequest', 'model/KnnQueryByDocId', 'model/KnnQueryByVector', 'model/MatchFilter', 'model/MatchOp', 'model/MatchOpFilter', 'model/MatchPhraseFilter', 'model/NotFilterBoolean', 'model/NotFilterNumber', 'model/NotFilterString', 'model/PercolateRequest', 'model/PercolateRequestQuery', 'model/QueryFilter', 'model/RangeFilter', 'model/ReplaceDocumentRequest', 'model/SearchRequest', 'model/SearchRequestKnn', 'model/SearchResponse', 'model/SearchResponseHits', 'model/SortMVA', 'model/SortMultiple', 'model/SortOrder', 'model/SourceByRules', 'model/SuccessResponse', 'model/UpdateDocumentRequest', 'model/UpdateResponse', 'api/IndexApi', 'api/SearchApi', 'api/UtilsApi'], factory); + define(['ApiClient', 'model/Aggregation', 'model/AggregationComposite', 'model/AggregationCompositeSourcesInnerValue', 'model/AggregationCompositeSourcesInnerValueTerms', 'model/AggregationSortInnerValue', 'model/AggregationTerms', 'model/BoolFilter', 'model/BulkResponse', 'model/DeleteDocumentRequest', 'model/DeleteResponse', 'model/EqualsFilter', 'model/ErrorResponse', 'model/Facet', 'model/FilterBoolean', 'model/FilterNumber', 'model/FilterString', 'model/GeoDistanceFilter', 'model/GeoDistanceFilterLocationAnchor', 'model/Highlight', 'model/HighlightField', 'model/InFilter', 'model/InsertDocumentRequest', 'model/MatchFilter', 'model/MatchOp', 'model/MatchOpFilter', 'model/MatchPhraseFilter', 'model/NotFilterBoolean', 'model/NotFilterNumber', 'model/NotFilterString', 'model/PercolateRequest', 'model/PercolateRequestQuery', 'model/QueryFilter', 'model/RangeFilter', 'model/ReplaceDocumentRequest', 'model/SearchRequest', 'model/SearchResponse', 'model/SearchResponseHits', 'model/SortMVA', 'model/SortMultiple', 'model/SortOrder', 'model/SourceByRules', 'model/SuccessResponse', 'model/UpdateDocumentRequest', 'model/UpdateResponse', 'api/IndexApi', 'api/SearchApi', 'api/UtilsApi'], factory); } else if (typeof module === 'object' && module.exports) { // CommonJS-like environments that support module.exports, like Node. - module.exports = factory(require('./ApiClient'), require('./model/Aggregation'), require('./model/AggregationSortInnerValue'), require('./model/AggregationTerms'), require('./model/BoolFilter'), require('./model/BulkResponse'), require('./model/DeleteDocumentRequest'), require('./model/DeleteResponse'), require('./model/EqualsFilter'), require('./model/ErrorResponse'), require('./model/Facet'), require('./model/FilterBoolean'), require('./model/FilterNumber'), require('./model/FilterString'), require('./model/GeoDistanceFilter'), require('./model/GeoDistanceFilterLocationAnchor'), require('./model/Highlight'), require('./model/HighlightField'), require('./model/InFilter'), require('./model/InsertDocumentRequest'), require('./model/KnnQueryByDocId'), require('./model/KnnQueryByVector'), require('./model/MatchFilter'), require('./model/MatchOp'), require('./model/MatchOpFilter'), require('./model/MatchPhraseFilter'), require('./model/NotFilterBoolean'), require('./model/NotFilterNumber'), require('./model/NotFilterString'), require('./model/PercolateRequest'), require('./model/PercolateRequestQuery'), require('./model/QueryFilter'), require('./model/RangeFilter'), require('./model/ReplaceDocumentRequest'), require('./model/SearchRequest'), require('./model/SearchRequestKnn'), require('./model/SearchResponse'), require('./model/SearchResponseHits'), require('./model/SortMVA'), require('./model/SortMultiple'), require('./model/SortOrder'), require('./model/SourceByRules'), require('./model/SuccessResponse'), require('./model/UpdateDocumentRequest'), require('./model/UpdateResponse'), require('./api/IndexApi'), require('./api/SearchApi'), require('./api/UtilsApi')); + module.exports = factory(require('./ApiClient'), require('./model/Aggregation'), require('./model/AggregationComposite'), require('./model/AggregationCompositeSourcesInnerValue'), require('./model/AggregationCompositeSourcesInnerValueTerms'), require('./model/AggregationSortInnerValue'), require('./model/AggregationTerms'), require('./model/BoolFilter'), require('./model/BulkResponse'), require('./model/DeleteDocumentRequest'), require('./model/DeleteResponse'), require('./model/EqualsFilter'), require('./model/ErrorResponse'), require('./model/Facet'), require('./model/FilterBoolean'), require('./model/FilterNumber'), require('./model/FilterString'), require('./model/GeoDistanceFilter'), require('./model/GeoDistanceFilterLocationAnchor'), require('./model/Highlight'), require('./model/HighlightField'), require('./model/InFilter'), require('./model/InsertDocumentRequest'), require('./model/MatchFilter'), require('./model/MatchOp'), require('./model/MatchOpFilter'), require('./model/MatchPhraseFilter'), require('./model/NotFilterBoolean'), require('./model/NotFilterNumber'), require('./model/NotFilterString'), require('./model/PercolateRequest'), require('./model/PercolateRequestQuery'), require('./model/QueryFilter'), require('./model/RangeFilter'), require('./model/ReplaceDocumentRequest'), require('./model/SearchRequest'), require('./model/SearchResponse'), require('./model/SearchResponseHits'), require('./model/SortMVA'), require('./model/SortMultiple'), require('./model/SortOrder'), require('./model/SourceByRules'), require('./model/SuccessResponse'), require('./model/UpdateDocumentRequest'), require('./model/UpdateResponse'), require('./api/IndexApi'), require('./api/SearchApi'), require('./api/UtilsApi')); } -}(function(ApiClient, Aggregation, AggregationSortInnerValue, AggregationTerms, BoolFilter, BulkResponse, DeleteDocumentRequest, DeleteResponse, EqualsFilter, ErrorResponse, Facet, FilterBoolean, FilterNumber, FilterString, GeoDistanceFilter, GeoDistanceFilterLocationAnchor, Highlight, HighlightField, InFilter, InsertDocumentRequest, KnnQueryByDocId, KnnQueryByVector, MatchFilter, MatchOp, MatchOpFilter, MatchPhraseFilter, NotFilterBoolean, NotFilterNumber, NotFilterString, PercolateRequest, PercolateRequestQuery, QueryFilter, RangeFilter, ReplaceDocumentRequest, SearchRequest, SearchRequestKnn, SearchResponse, SearchResponseHits, SortMVA, SortMultiple, SortOrder, SourceByRules, SuccessResponse, UpdateDocumentRequest, UpdateResponse, IndexApi, SearchApi, UtilsApi) { +}(function(ApiClient, Aggregation, AggregationComposite, AggregationCompositeSourcesInnerValue, AggregationCompositeSourcesInnerValueTerms, AggregationSortInnerValue, AggregationTerms, BoolFilter, BulkResponse, DeleteDocumentRequest, DeleteResponse, EqualsFilter, ErrorResponse, Facet, FilterBoolean, FilterNumber, FilterString, GeoDistanceFilter, GeoDistanceFilterLocationAnchor, Highlight, HighlightField, InFilter, InsertDocumentRequest, MatchFilter, MatchOp, MatchOpFilter, MatchPhraseFilter, NotFilterBoolean, NotFilterNumber, NotFilterString, PercolateRequest, PercolateRequestQuery, QueryFilter, RangeFilter, ReplaceDocumentRequest, SearchRequest, SearchResponse, SearchResponseHits, SortMVA, SortMultiple, SortOrder, SourceByRules, SuccessResponse, UpdateDocumentRequest, UpdateResponse, IndexApi, SearchApi, UtilsApi) { 'use strict'; /** @@ -58,6 +58,21 @@ * @property {module:model/Aggregation} */ Aggregation: Aggregation, + /** + * The AggregationComposite model constructor. + * @property {module:model/AggregationComposite} + */ + AggregationComposite: AggregationComposite, + /** + * The AggregationCompositeSourcesInnerValue model constructor. + * @property {module:model/AggregationCompositeSourcesInnerValue} + */ + AggregationCompositeSourcesInnerValue: AggregationCompositeSourcesInnerValue, + /** + * The AggregationCompositeSourcesInnerValueTerms model constructor. + * @property {module:model/AggregationCompositeSourcesInnerValueTerms} + */ + AggregationCompositeSourcesInnerValueTerms: AggregationCompositeSourcesInnerValueTerms, /** * The AggregationSortInnerValue model constructor. * @property {module:model/AggregationSortInnerValue} diff --git a/src/model/Aggregation.js b/src/model/Aggregation.js index df090b2..629ce1a 100644 --- a/src/model/Aggregation.js +++ b/src/model/Aggregation.js @@ -8,18 +8,18 @@ (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. - define(['ApiClient', 'model/AggregationSortInnerValue', 'model/AggregationTerms'], factory); + define(['ApiClient', 'model/AggregationComposite', 'model/AggregationSortInnerValue', 'model/AggregationTerms'], factory); } else if (typeof module === 'object' && module.exports) { // CommonJS-like environments that support module.exports, like Node. - module.exports = factory(require('../ApiClient'), require('./AggregationSortInnerValue'), require('./AggregationTerms')); + module.exports = factory(require('../ApiClient'), require('./AggregationComposite'), require('./AggregationSortInnerValue'), require('./AggregationTerms')); } else { // Browser globals (root is window) if (!root.Manticoresearch) { root.Manticoresearch = {}; } - root.Manticoresearch.Aggregation = factory(root.Manticoresearch.ApiClient, root.Manticoresearch.AggregationSortInnerValue, root.Manticoresearch.AggregationTerms); + root.Manticoresearch.Aggregation = factory(root.Manticoresearch.ApiClient, root.Manticoresearch.AggregationComposite, root.Manticoresearch.AggregationSortInnerValue, root.Manticoresearch.AggregationTerms); } -}(this, function(ApiClient, AggregationSortInnerValue, AggregationTerms) { +}(this, function(ApiClient, AggregationComposite, AggregationSortInnerValue, AggregationTerms) { 'use strict'; @@ -57,6 +57,9 @@ if (data.hasOwnProperty('sort')) { obj['sort'] = ApiClient.convertToType(data['sort'], [{'String': AggregationSortInnerValue}]); } + if (data.hasOwnProperty('composite')) { + obj['composite'] = AggregationComposite.constructFromObject(data['composite']); + } } return obj; } @@ -69,6 +72,10 @@ * @member {Array.>} sort */ exports.prototype['sort'] = undefined; + /** + * @member {module:model/AggregationComposite} composite + */ + exports.prototype['composite'] = undefined; diff --git a/src/model/AggregationComposite.js b/src/model/AggregationComposite.js new file mode 100644 index 0000000..d2bc97a --- /dev/null +++ b/src/model/AggregationComposite.js @@ -0,0 +1,79 @@ +/* + * Manticore Search Client + * Copyright (c) 2020-2021, Manticore Software LTD (https://manticoresearch.com) + * + * All rights reserved + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['ApiClient', 'model/AggregationCompositeSourcesInnerValue'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + module.exports = factory(require('../ApiClient'), require('./AggregationCompositeSourcesInnerValue')); + } else { + // Browser globals (root is window) + if (!root.Manticoresearch) { + root.Manticoresearch = {}; + } + root.Manticoresearch.AggregationComposite = factory(root.Manticoresearch.ApiClient, root.Manticoresearch.AggregationCompositeSourcesInnerValue); + } +}(this, function(ApiClient, AggregationCompositeSourcesInnerValue) { + 'use strict'; + + + + /** + * The AggregationComposite model module. + * @module model/AggregationComposite + * @version 4.0.0 + */ + + /** + * Constructs a new AggregationComposite. + * Composite aggregation + * @alias module:model/AggregationComposite + * @class + */ + var exports = function() { + var _this = this; + + }; + + /** + * Constructs a AggregationComposite from a plain JavaScript object, optionally creating a new instance. + * Copies all relevant properties from data to obj if supplied or a new instance if not. + * @param {Object} data The plain JavaScript object bearing properties of interest. + * @param {module:model/AggregationComposite} obj Optional instance to populate. + * @return {module:model/AggregationComposite} The populated AggregationComposite instance. + */ + exports.constructFromObject = function(data, obj) { + if (data) { + obj = obj || new exports(); + if (data.hasOwnProperty('size')) { + obj['size'] = ApiClient.convertToType(data['size'], 'Number'); + } + if (data.hasOwnProperty('sources')) { + obj['sources'] = ApiClient.convertToType(data['sources'], [{'String': AggregationCompositeSourcesInnerValue}]); + } + } + return obj; + } + + /** + * Maximum number of composite buckets in the result + * @member {Number} size + */ + exports.prototype['size'] = undefined; + /** + * @member {Array.>} sources + */ + exports.prototype['sources'] = undefined; + + + + return exports; +})); + + diff --git a/src/model/AggregationCompositeSourcesInnerValue.js b/src/model/AggregationCompositeSourcesInnerValue.js new file mode 100644 index 0000000..a1609d5 --- /dev/null +++ b/src/model/AggregationCompositeSourcesInnerValue.js @@ -0,0 +1,70 @@ +/* + * Manticore Search Client + * Copyright (c) 2020-2021, Manticore Software LTD (https://manticoresearch.com) + * + * All rights reserved + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['ApiClient', 'model/AggregationCompositeSourcesInnerValueTerms'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + module.exports = factory(require('../ApiClient'), require('./AggregationCompositeSourcesInnerValueTerms')); + } else { + // Browser globals (root is window) + if (!root.Manticoresearch) { + root.Manticoresearch = {}; + } + root.Manticoresearch.AggregationCompositeSourcesInnerValue = factory(root.Manticoresearch.ApiClient, root.Manticoresearch.AggregationCompositeSourcesInnerValueTerms); + } +}(this, function(ApiClient, AggregationCompositeSourcesInnerValueTerms) { + 'use strict'; + + + + /** + * The AggregationCompositeSourcesInnerValue model module. + * @module model/AggregationCompositeSourcesInnerValue + * @version 4.0.0 + */ + + /** + * Constructs a new AggregationCompositeSourcesInnerValue. + * @alias module:model/AggregationCompositeSourcesInnerValue + * @class + */ + var exports = function() { + var _this = this; + + }; + + /** + * Constructs a AggregationCompositeSourcesInnerValue from a plain JavaScript object, optionally creating a new instance. + * Copies all relevant properties from data to obj if supplied or a new instance if not. + * @param {Object} data The plain JavaScript object bearing properties of interest. + * @param {module:model/AggregationCompositeSourcesInnerValue} obj Optional instance to populate. + * @return {module:model/AggregationCompositeSourcesInnerValue} The populated AggregationCompositeSourcesInnerValue instance. + */ + exports.constructFromObject = function(data, obj) { + if (data) { + obj = obj || new exports(); + if (data.hasOwnProperty('terms')) { + obj['terms'] = AggregationCompositeSourcesInnerValueTerms.constructFromObject(data['terms']); + } + } + return obj; + } + + /** + * @member {module:model/AggregationCompositeSourcesInnerValueTerms} terms + */ + exports.prototype['terms'] = undefined; + + + + return exports; +})); + + diff --git a/src/model/AggregationCompositeSourcesInnerValueTerms.js b/src/model/AggregationCompositeSourcesInnerValueTerms.js new file mode 100644 index 0000000..e3564e5 --- /dev/null +++ b/src/model/AggregationCompositeSourcesInnerValueTerms.js @@ -0,0 +1,71 @@ +/* + * Manticore Search Client + * Copyright (c) 2020-2021, Manticore Software LTD (https://manticoresearch.com) + * + * All rights reserved + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['ApiClient'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + module.exports = factory(require('../ApiClient')); + } else { + // Browser globals (root is window) + if (!root.Manticoresearch) { + root.Manticoresearch = {}; + } + root.Manticoresearch.AggregationCompositeSourcesInnerValueTerms = factory(root.Manticoresearch.ApiClient); + } +}(this, function(ApiClient) { + 'use strict'; + + + + /** + * The AggregationCompositeSourcesInnerValueTerms model module. + * @module model/AggregationCompositeSourcesInnerValueTerms + * @version 4.0.0 + */ + + /** + * Constructs a new AggregationCompositeSourcesInnerValueTerms. + * @alias module:model/AggregationCompositeSourcesInnerValueTerms + * @class + */ + var exports = function() { + var _this = this; + + }; + + /** + * Constructs a AggregationCompositeSourcesInnerValueTerms from a plain JavaScript object, optionally creating a new instance. + * Copies all relevant properties from data to obj if supplied or a new instance if not. + * @param {Object} data The plain JavaScript object bearing properties of interest. + * @param {module:model/AggregationCompositeSourcesInnerValueTerms} obj Optional instance to populate. + * @return {module:model/AggregationCompositeSourcesInnerValueTerms} The populated AggregationCompositeSourcesInnerValueTerms instance. + */ + exports.constructFromObject = function(data, obj) { + if (data) { + obj = obj || new exports(); + if (data.hasOwnProperty('field')) { + obj['field'] = ApiClient.convertToType(data['field'], 'String'); + } + } + return obj; + } + + /** + * Name of attribute to aggregate by + * @member {String} field + */ + exports.prototype['field'] = undefined; + + + + return exports; +})); + + diff --git a/src/model/AggregationTerms.js b/src/model/AggregationTerms.js index 0169e0c..cf3e99f 100644 --- a/src/model/AggregationTerms.js +++ b/src/model/AggregationTerms.js @@ -61,12 +61,12 @@ } /** - * Attribute Name to Aggregate + * Name of attribute to aggregate by * @member {String} field */ exports.prototype['field'] = undefined; /** - * Maximum Number of Buckets in the Result + * Maximum number of buckets in the result * @member {Number} size */ exports.prototype['size'] = undefined; diff --git a/test/api/Manual.spec.js b/test/api/Manual.spec.js index 87a9ac2..4569808 100755 --- a/test/api/Manual.spec.js +++ b/test/api/Manual.spec.js @@ -75,24 +75,24 @@ res = await searchApi.search(search_request); search_request.source = new Manticoresearch.SourceByRules(); - search_request.source.includes = ['title', '_year']; - search_request.source.excludes = ['code']; + search_request.source.includes = ['title', '_year']; + search_request.source.excludes = ['code']; - res = await searchApi.search(search_request); + res = await searchApi.search(search_request); search_request.sort = ['_year'] - let sort2 = new Manticoresearch.SortOrder('rating', 'asc'); - let sort3 = new Manticoresearch.SortMVA('code', 'desc', 'max'); - search_request.sort.push(...[sort2,sort3]); + let sort2 = new Manticoresearch.SortOrder('rating', 'asc'); + let sort3 = new Manticoresearch.SortMVA('code', 'desc', 'max'); + search_request.sort.push(...[sort2,sort3]); - res = await searchApi.search(search_request); + res = await searchApi.search(search_request); - search_request.expressions = {'expr': 'min(_year,2900)'}; - let expr2 = 'max(_year,2100)'; - search_request.expressions['expr2'] = expr2; - search_request.source.includes.push('expr', 'expr2'); + search_request.expressions = {'expr': 'min(_year,2900)'}; + let expr2 = 'max(_year,2100)'; + search_request.expressions['expr2'] = expr2; + search_request.source.includes.push('expr', 'expr2'); - res = await searchApi.search(search_request); + res = await searchApi.search(search_request); let terms = {}; Manticoresearch.AggregationTerms.constructFromObject({field: '_year', size: 10}, terms); @@ -102,18 +102,29 @@ search_request.aggs = {agg1: agg1}; let agg2 = new Manticoresearch.Aggregation(); agg2['terms'] = Manticoresearch.AggregationTerms.constructFromObject({field: 'rating'}); - search_request.aggs['agg2'] = agg2; + search_request.aggs['agg2'] = agg2; + + res = await searchApi.search(search_request); + + let compAggTerms1 = Manticoresearch.AggregationCompositeSourcesInnerValueTerms.constructFromObject({field: '_year'}); + let compAgg1 = Manticoresearch.AggregationCompositeSourcesInnerValue.constructFromObject({'terms': compAggTerms1}) + let compAggTerms2 = Manticoresearch.AggregationCompositeSourcesInnerValueTerms.constructFromObject({field: 'rating'}); + let compAgg2 = Manticoresearch.AggregationCompositeSourcesInnerValue.constructFromObject({'terms': compAggTerms2}); + let compSources = [{'comp_agg_1': compAgg1}, {'comp_agg_2': compAgg2}]; + let compAgg = Manticoresearch.AggregationComposite.constructFromObject({'size': 5, 'sources': compSources}); + let agg = Manticoresearch.Aggregation.constructFromObject({'composite': compAgg}); + search_request.aggs = {'comp_agg': agg}; - res = await searchApi.search(search_request); + res = await searchApi.search(search_request); let highlight = new Manticoresearch.Highlight(); - highlight.fieldnames = ['title']; - highlight.post_tags = ''; - highlight.encoder = 'default'; - highlight.snippet_boundary = 'sentence'; - search_request.highlight = highlight; + highlight.fieldnames = ['title']; + highlight.post_tags = ''; + highlight.encoder = 'default'; + highlight.snippet_boundary = 'sentence'; + search_request.highlight = highlight; - res = await searchApi.search(search_request); + res = await searchApi.search(search_request); let highlightField = new Manticoresearch.HighlightField('title'); let highlightField2 = new Manticoresearch.HighlightField('plot');