|
@@ -28,6 +28,18 @@ export class AccurateMatchingService {
|
|
|
return this.search(keyword, config, skip, limit);
|
|
|
}
|
|
|
|
|
|
+ async forDemandSearch(keyword: string, skip = 0, limit = 10) {
|
|
|
+ const fields = ['name', 'tags', 'area', 'brief'];
|
|
|
+ const config = { index: ['supply', 'achievement'], fields };
|
|
|
+ return await this.manyIndexsSearch(keyword, config, skip, limit);
|
|
|
+ }
|
|
|
+
|
|
|
+ async forSupplySearch(keyword: string, skip = 0, limit = 10){
|
|
|
+ const fields = ['name', 'tags', 'area', 'brief'];
|
|
|
+ const config = { index: ['demand', 'achievement'], fields };
|
|
|
+ return await this.manyIndexsSearch(keyword, config, skip, limit);
|
|
|
+ }
|
|
|
+
|
|
|
/**精准匹配统一查询,使用简单的form+size分页模式.如果数据量大于1w,此处的分页模式应该修改,不过就会影响资源的占用及数据的实时性 */
|
|
|
async search(keyword: string, config: object, skip: number, limit: number) {
|
|
|
const index = get(config, 'index');
|
|
@@ -49,7 +61,31 @@ export class AccurateMatchingService {
|
|
|
size: limit,
|
|
|
from: skip,
|
|
|
});
|
|
|
- const returnData = this.dealResponses(result)
|
|
|
+ const returnData = this.dealResponses(result);
|
|
|
+ return returnData;
|
|
|
+ }
|
|
|
+
|
|
|
+ async manyIndexsSearch(keyword: string, config: object, skip: number, limit: number) {
|
|
|
+ const index = get(config, 'index');
|
|
|
+ const fields = get(config, 'fields', []);
|
|
|
+ const result = await this.esClient.search({
|
|
|
+ index,
|
|
|
+ query: {
|
|
|
+ bool: {
|
|
|
+ must: [
|
|
|
+ {
|
|
|
+ multi_match: {
|
|
|
+ query: keyword,
|
|
|
+ fields,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ size: limit,
|
|
|
+ from: skip,
|
|
|
+ });
|
|
|
+ const returnData = this.dealResponses(result);
|
|
|
return returnData;
|
|
|
}
|
|
|
|
|
@@ -59,12 +95,14 @@ export class AccurateMatchingService {
|
|
|
const list = [];
|
|
|
for (const ol of hits) {
|
|
|
const _score = get(ol, '_score', 0);
|
|
|
+ const _source = get(ol, '_index');
|
|
|
const data = get(ol, '_source', {});
|
|
|
let recommend = 0;
|
|
|
/**推荐星数计算:超过5,就都是5颗星.未超过5的都向下取整 */
|
|
|
if (_score >= 5) recommend = 5;
|
|
|
else recommend = floor(_score);
|
|
|
data._recommend = recommend;
|
|
|
+ data._source = _source;
|
|
|
list.push(data);
|
|
|
}
|
|
|
return { total, data: list };
|