Explorar o código

查询总数量

zs hai 8 meses
pai
achega
0cd29f655b
Modificáronse 2 ficheiros con 48 adicións e 0 borrados
  1. 6 0
      src/controller/search.controller.ts
  2. 42 0
      src/service/search.service.ts

+ 6 - 0
src/controller/search.controller.ts

@@ -13,6 +13,12 @@ export class SearchController {
   @Inject()
   sbService: SearchBehaviorService;
 
+  @Get('/total')
+  async total(@Query('keyword') keyword: string) {
+    const res = await this.searchService.total(keyword);
+    return res;
+  }
+
   @Get('/company')
   async company(@Query('keyword') keyword: string, @Query('skip') skip: number, @Query('limit') limit: number) {
     const query = this.ctx.query;

+ 42 - 0
src/service/search.service.ts

@@ -13,6 +13,48 @@ export class SearchService {
     const esClient = new Client(this.esConfig);
     this.esClient = esClient;
   }
+
+  /**信息检索-总数查看 */
+  async total(keyword: string) {
+    const list = [
+      { key: '1', tab: '企业', index: 'company', skip: 0, limit: 1, others: { status: '1' }, fields: ['industry', 'tags', 'name', 'pattern', 'scale', 'type', 'area', 'email', 'address', 'brief', 'products'] },
+      {
+        key: '2',
+        tab: '项目',
+        index: 'project',
+        skip: 0,
+        limit: 1,
+        others: { status: '1', is_use: '0' },
+        fields: ['tags', 'name', 'maturity', 'skill', 'type', 'area', 'field', 'cooperate', 'brief', 'main', 'progress', 'track_unit', 'source', 'industry'],
+      },
+      {
+        key: '3',
+        tab: '需求',
+        index: 'demand',
+        skip: 0,
+        limit: 1,
+        others: { status: '1', is_use: '0' },
+        fields: ['industry', 'tags', 'name', 'field', 'urgent', 'method', 'area', 'brief', 'demand_status', 'company', 'company_brief', 'contacts', 'tec_name', 'question'],
+      },
+      { key: '4', tab: '供给', index: 'supply', skip: 0, limit: 1, others: { status: '1', is_use: '0' }, fields: ['industry', 'tags', 'name', 'field', 'urgent', 'method', 'area', 'brief', 'demand_status'] },
+      {
+        key: '5',
+        tab: '成果',
+        index: 'achievement',
+        skip: 0,
+        limit: 1,
+        others: { status: '1', is_use: '0' },
+        fields: ['industry', 'tags', 'name', 'patent', 'attribute', 'sell', 'mature', 'field', 'technology', 'area', 'brief', 'achievement_status', 'source'],
+      },
+    ];
+    for (const val of list) {
+      const result = await this.oneIndexSearch(keyword, val.index, val.fields, val.skip, val.limit, val.others);
+      const total = get(result, 'total', 0);
+      val.tab = `${val.tab}(${total})`;
+    }
+    return list;
+  }
+
   /**信息检索-企业查询 */
   async company(keyword: string, skip = 0, limit = 10, others: object) {
     const index = 'company';