Skip to content

Commit 9db355d

Browse files
committed
Search Support Collapse
1 parent c05dfbf commit 9db355d

File tree

8 files changed

+43
-692
lines changed

8 files changed

+43
-692
lines changed

README-EN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414

1515
## Version Feature Updates
16+
- Version: 5.2.2
17+
- Search Support Collapse
1618
- Version: 5.2.1
1719
- SQL use default SQLPayloadVersion SQL_FLAT_BUFFERS
1820
- Version: 5.2.0

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414

1515
## 版本特性
16+
- 版本:5.2.2
17+
- Search 支持折叠功能
1618
- 版本:5.2.1
1719
- SQL使用默认序列化协议SQL_FLAT_BUFFERS
1820
- 版本:5.2.0

lib/protocol/encoder.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,9 @@ TableStore.encoder = {
737737
if (aSearchQuery.groupBys) {
738738
properties.groupBys = TableStore.encoder._makeGroupBys(aSearchQuery.groupBys)
739739
}
740+
if (aSearchQuery.collapse) {
741+
properties.collapse = TableStore.encoder._makeCollapse(aSearchQuery.collapse)
742+
}
740743
var searchQuery = tsSearchProtos.SearchQuery.create(properties);
741744
var writer = tsSearchProtos.SearchQuery.encode(searchQuery);
742745

@@ -755,6 +758,13 @@ TableStore.encoder = {
755758

756759
return query;
757760
},
761+
_makeCollapse(aCollapse) {
762+
const properties = {};
763+
if (aCollapse.fieldName) {
764+
properties.fieldName = aCollapse.fieldName;
765+
}
766+
return tsSearchProtos.Collapse.create(properties);
767+
},
758768
_makeAggregations(aggs) {
759769
let aggArray = [];
760770
for (let agg of aggs.aggs) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "tablestore",
33
"main": "index.js",
44
"description": "TableStore SDK for JavaScript",
5-
"version": "5.2.1",
5+
"version": "5.2.2",
66
"devDependencies": {
77
"mocha": "^3.2.0",
88
"coveralls": "^2.13.1",

samples/search.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ client.search({
264264
// }
265265
}
266266
]
267-
}
267+
},
268+
// collapse: {
269+
// fieldName: "col_keyword",
270+
// },
268271
},
269272
columnToGet: {
270273
returnType: TableStore.ColumnReturnType.RETURN_NONE,

test/search.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,30 @@ describe('Search Query', () => {
371371
return otsTestUtils.emptyPromise
372372
});
373373

374+
it('collapse test ', async function () {
375+
this.timeout(160000);
376+
const tableName = "js_agg_and_group_by"
377+
const indexName = tableName + "_index"
378+
let searchResp = await otsTestUtils.search(tableName, indexName, {
379+
offset: 0,
380+
limit: 100,
381+
query: {
382+
queryType: TableStore.QueryType.MATCH_ALL_QUERY,
383+
},
384+
getTotalCount: true,
385+
collapse: {
386+
fieldName: "col_keyword",
387+
},
388+
},
389+
{
390+
returnType: TableStore.ColumnReturnType.RETURN_ALL_FROM_INDEX,
391+
})
392+
console.log(JSON.stringify(searchResp))
393+
// 本case复用上述case索引,因此需要先运行上面case,让索引创建出来
394+
assert.equal(12, searchResp.rows.length)
395+
return otsTestUtils.emptyPromise
396+
});
397+
374398
it("weight", async function () {
375399
this.timeout(30000);
376400
const tableName = "js_weight"

test/searchIndexCreateAndInsert.test.js

Lines changed: 0 additions & 267 deletions
This file was deleted.

0 commit comments

Comments
 (0)