Skip to content

Commit c4665c7

Browse files
author
James Cori
committed
Merge branch 'develop'
2 parents 9333c26 + 9d49bb5 commit c4665c7

File tree

2 files changed

+58
-15
lines changed

2 files changed

+58
-15
lines changed

Diff for: src/init-es.js

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ const initES = async () => {
3434
id: { type: 'keyword' },
3535
name: {
3636
type: 'keyword',
37+
fields: {
38+
text: {
39+
type: 'text'
40+
}
41+
},
3742
normalizer: 'custom_sort_normalizer'
3843
},
3944
prizeSets: {

Diff for: src/services/ChallengeService.js

+53-15
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,48 @@ async function searchChallenges (currentUser, criteria) {
226226
})
227227
}
228228

229+
const multiMatchQuery = []
229230
if (criteria.search) {
230-
boolQuery.push({
231-
bool: {
232-
should: [
233-
{ match_phrase_prefix: { 'name': criteria.search } },
234-
{ match_phrase_prefix: { 'description': criteria.search } },
235-
{ match_phrase_prefix: { 'tags': criteria.search } }
236-
]
231+
multiMatchQuery.push({
232+
// exact match
233+
multi_match: {
234+
query: criteria.search,
235+
fields: [
236+
'name.text^7',
237+
'tags^3',
238+
'description^2'
239+
],
240+
type: 'phrase_prefix',
241+
boost: 5
242+
}
243+
})
244+
multiMatchQuery.push({
245+
// match 100% words
246+
multi_match: {
247+
query: criteria.search,
248+
fields: [
249+
'name.text^3.0',
250+
'tags^2.5',
251+
'description^1.0'
252+
],
253+
type: 'most_fields',
254+
minimum_should_match: '100%',
255+
boost: 2.5
256+
}
257+
})
258+
multiMatchQuery.push({
259+
// fuzzy match
260+
multi_match: {
261+
query: criteria.search,
262+
fields: [
263+
'name.text^2.5',
264+
'tags^1.5',
265+
'description^1.0'
266+
],
267+
type: 'most_fields',
268+
minimum_should_match: '50%',
269+
fuzziness: 'AUTO',
270+
boost: 1
237271
}
238272
})
239273
} else {
@@ -538,6 +572,14 @@ async function searchChallenges (currentUser, criteria) {
538572
})
539573
}
540574

575+
if (multiMatchQuery) {
576+
mustQuery.push({
577+
bool: {
578+
should: multiMatchQuery
579+
}
580+
})
581+
}
582+
541583
if (boolQuery.length > 0) {
542584
mustQuery.push({
543585
bool: {
@@ -872,9 +914,7 @@ async function createChallenge (currentUser, challenge) {
872914
const { billingAccountId, markup } = await helper.getProjectBillingInformation(_.get(challenge, 'projectId'))
873915
if (billingAccountId && _.isUndefined(_.get(challenge, 'billing.billingAccountId'))) {
874916
_.set(challenge, 'billing.billingAccountId', billingAccountId)
875-
}
876-
if (markup && _.isUndefined(_.get(challenge, 'billing.markup'))) {
877-
_.set(challenge, 'billing.markup', markup)
917+
_.set(challenge, 'billing.markup', markup || 0)
878918
}
879919
if (_.get(type, 'isTask')) {
880920
_.set(challenge, 'task.isTask', true)
@@ -1066,7 +1106,7 @@ createChallenge.schema = {
10661106
value: Joi.number().min(0).required()
10671107
})).min(1).required()
10681108
})),
1069-
tags: Joi.array().items(Joi.string().required()), // tag names
1109+
tags: Joi.array().items(Joi.string()), // tag names
10701110
projectId: Joi.number().integer().positive().required(),
10711111
legacyId: Joi.number().integer().positive(),
10721112
startDate: Joi.date(),
@@ -1252,9 +1292,7 @@ async function update (currentUser, challengeId, data, isFull) {
12521292
const { billingAccountId, markup } = await helper.getProjectBillingInformation(_.get(challenge, 'projectId'))
12531293
if (billingAccountId && _.isUndefined(_.get(challenge, 'billing.billingAccountId'))) {
12541294
_.set(data, 'billing.billingAccountId', billingAccountId)
1255-
}
1256-
if (markup && _.isUndefined(_.get(challenge, 'billing.markup'))) {
1257-
_.set(data, 'billing.markup', markup)
1295+
_.set(data, 'billing.markup', markup || 0)
12581296
}
12591297
if (data.status) {
12601298
if (data.status === constants.challengeStatuses.Active) {
@@ -1853,7 +1891,7 @@ fullyUpdateChallenge.schema = {
18531891
url: Joi.string(),
18541892
options: Joi.array().items(Joi.object())
18551893
})),
1856-
tags: Joi.array().items(Joi.string().required()), // tag names
1894+
tags: Joi.array().items(Joi.string()), // tag names
18571895
projectId: Joi.number().integer().positive().required(),
18581896
legacyId: Joi.number().integer().positive(),
18591897
startDate: Joi.date(),

0 commit comments

Comments
 (0)