|
@@ -1,6 +1,6 @@
|
|
|
import { Client } from '@elastic/elasticsearch';
|
|
|
import { Config, Init, Provide } from '@midwayjs/core';
|
|
|
-import { floor, get } from 'lodash';
|
|
|
+import { floor, get, isArray } from 'lodash';
|
|
|
|
|
|
@Provide()
|
|
|
export class SearchService {
|
|
@@ -117,9 +117,26 @@ export class SearchService {
|
|
|
|
|
|
if (Object.keys(params).length > 0) {
|
|
|
for (const key in params) {
|
|
|
- const val = params[key];
|
|
|
- const obj = { match_phrase: { [key]: val } };
|
|
|
- must.push(obj);
|
|
|
+ if (key === 'status') {
|
|
|
+ const status = get(params, 'status');
|
|
|
+ must.push({ term: { status } });
|
|
|
+ } else {
|
|
|
+ const val = params[key];
|
|
|
+ let arrVal = [];
|
|
|
+ if (isArray(val)) arrVal = val;
|
|
|
+ else arrVal.push(val);
|
|
|
+ const should = [];
|
|
|
+ for (const i of arrVal) {
|
|
|
+ should.push({ term: { [key]: i } });
|
|
|
+ }
|
|
|
+ const obj = {
|
|
|
+ bool: {
|
|
|
+ should,
|
|
|
+ minimum_should_match: 1,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ must.push(obj);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|