|
@@ -31,18 +31,18 @@ export class AccurateMatchingService {
|
|
|
const config = { index: 'achievement', fields: ['name', 'tags', 'area', 'brief'] };
|
|
|
return this.search(keyword, config, skip, limit);
|
|
|
}
|
|
|
-
|
|
|
+ //由供给信息查询
|
|
|
async forDemandSearch(keyword: string, skip = 0, limit = 10, id) {
|
|
|
const fields = ['name', 'tags', 'brief'];
|
|
|
- const config = { index: ['supply', 'achievement'], fields };
|
|
|
- const origin_index = 'demand';
|
|
|
+ const config = { index: ['demand', 'achievement'], fields };
|
|
|
+ const origin_index = 'supply';
|
|
|
return await this.manyIndexsSearch(keyword, config, skip, limit, origin_index, id);
|
|
|
}
|
|
|
-
|
|
|
+ // 由需求信息查询
|
|
|
async forSupplySearch(keyword: string, skip = 0, limit = 10, id) {
|
|
|
const fields = ['name', 'tags', 'brief'];
|
|
|
- const config = { index: ['demand', 'achievement'], fields };
|
|
|
- const origin_index = 'supply';
|
|
|
+ const config = { index: ['supply', 'achievement'], fields };
|
|
|
+ const origin_index = 'demand';
|
|
|
return await this.manyIndexsSearch(keyword, config, skip, limit, origin_index, id);
|
|
|
}
|
|
|
|
|
@@ -73,26 +73,41 @@ export class AccurateMatchingService {
|
|
|
|
|
|
async manyIndexsSearch(keyword: string, config: object, skip: number, limit: number, origin_index: string, id?: number) {
|
|
|
const index = get(config, 'index');
|
|
|
- const fields = get(config, 'fields', []);
|
|
|
+ // const fields = get(config, 'fields', []);
|
|
|
const user_id = get(this.ctx, 'user.id');
|
|
|
- const must: any = [
|
|
|
+ // const must: any = [
|
|
|
+ // {
|
|
|
+ // match: {
|
|
|
+ // name: {
|
|
|
+ // query: keyword,
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+ // ];
|
|
|
+ const must_not = [
|
|
|
{
|
|
|
- multi_match: {
|
|
|
- query: keyword,
|
|
|
- fields,
|
|
|
- type: 'best_fields',
|
|
|
- tie_breaker: 0.5,
|
|
|
+ match: {
|
|
|
+ user: user_id,
|
|
|
},
|
|
|
},
|
|
|
];
|
|
|
- const must_not = [
|
|
|
+ const should: any = [
|
|
|
{
|
|
|
- match: {
|
|
|
- user: user_id,
|
|
|
+ constant_score: {
|
|
|
+ filter: {
|
|
|
+ bool: {
|
|
|
+ must: {
|
|
|
+ match: { name: keyword },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ boost: 3,
|
|
|
},
|
|
|
},
|
|
|
];
|
|
|
- const filter = [];
|
|
|
+ const queries = [];
|
|
|
+ queries.push({ bool: { must_not, should: { match: { name: keyword } } } });
|
|
|
+ let fieldValue, industryValue;
|
|
|
if (id) {
|
|
|
const res = await this.esClient.search({
|
|
|
index: origin_index,
|
|
@@ -100,33 +115,70 @@ export class AccurateMatchingService {
|
|
|
});
|
|
|
const originResult = this.dealResponses(res);
|
|
|
const industry = get(head(get(originResult, 'data')), 'industry');
|
|
|
+ // 产业
|
|
|
if (industry && industry !== '') {
|
|
|
- filter.push({ term: { industry } });
|
|
|
+ industryValue = industry;
|
|
|
+ should.push({
|
|
|
+ constant_score: {
|
|
|
+ filter: {
|
|
|
+ bool: {
|
|
|
+ must: {
|
|
|
+ term: { industry },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ boost: 1,
|
|
|
+ },
|
|
|
+ });
|
|
|
}
|
|
|
+ // 技术领域
|
|
|
+ const field = get(head(get(originResult, 'data')), 'field');
|
|
|
+ if (field && field !== '') {
|
|
|
+ fieldValue = field;
|
|
|
+ should.push({
|
|
|
+ constant_score: {
|
|
|
+ filter: {
|
|
|
+ bool: {
|
|
|
+ must: {
|
|
|
+ match: { field },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ boost: 1,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fieldValue) {
|
|
|
+ queries.push({ match: { field: fieldValue } });
|
|
|
+ }
|
|
|
+ if (industryValue) {
|
|
|
+ queries.push({ term: { industry: industryValue } });
|
|
|
}
|
|
|
+
|
|
|
const result = await this.esClient.search({
|
|
|
index,
|
|
|
+ // constant_score方式
|
|
|
+ // query: {
|
|
|
+ // bool: {
|
|
|
+ // must_not,
|
|
|
+ // should,
|
|
|
+ // minimum_should_match: 1,
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+ // dis_max方式
|
|
|
query: {
|
|
|
- bool: {
|
|
|
- must,
|
|
|
- must_not,
|
|
|
- filter,
|
|
|
+ dis_max: {
|
|
|
+ queries,
|
|
|
+ tie_breaker: 0.3,
|
|
|
+ boost: 0.7,
|
|
|
},
|
|
|
},
|
|
|
- // highlight: {
|
|
|
- // fields: {
|
|
|
- // name: {
|
|
|
- // pre_tags: ['<em>'],
|
|
|
- // post_tags: ['</em>'],
|
|
|
- // },
|
|
|
- // brief: {
|
|
|
- // pre_tags: ['<em>'],
|
|
|
- // post_tags: ['</em>'],
|
|
|
- // },
|
|
|
- // },
|
|
|
- // },
|
|
|
+ // min_score: 3,
|
|
|
size: limit,
|
|
|
from: skip,
|
|
|
+ explain: true,
|
|
|
});
|
|
|
const returnData = this.dealResponses(result);
|
|
|
return returnData;
|