File tree Expand file tree Collapse file tree 2 files changed +54
-7
lines changed Expand file tree Collapse file tree 2 files changed +54
-7
lines changed Original file line number Diff line number Diff 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 : {
Original file line number Diff line number Diff line change @@ -217,14 +217,48 @@ async function searchChallenges (currentUser, criteria) {
217217 } )
218218 }
219219
220+ const multiMatchQuery = [ ]
220221 if ( criteria . search ) {
221- boolQuery . push ( {
222- bool : {
223- should : [
224- { match_phrase_prefix : { 'name' : criteria . search } } ,
225- { match_phrase_prefix : { 'description' : criteria . search } } ,
226- { match_phrase_prefix : { 'tags' : criteria . search } }
227- ]
222+ multiMatchQuery . push ( {
223+ // exact match
224+ multi_match : {
225+ query : criteria . search ,
226+ fields : [
227+ 'name.text^7' ,
228+ 'tags^3' ,
229+ 'description^2'
230+ ] ,
231+ type : 'phrase_prefix' ,
232+ boost : 5
233+ }
234+ } )
235+ multiMatchQuery . push ( {
236+ // match 100% words
237+ multi_match : {
238+ query : criteria . search ,
239+ fields : [
240+ 'name.text^3.0' ,
241+ 'tags^2.5' ,
242+ 'description^1.0'
243+ ] ,
244+ type : 'most_fields' ,
245+ minimum_should_match : '100%' ,
246+ boost : 2.5
247+ }
248+ } )
249+ multiMatchQuery . push ( {
250+ // fuzzy match
251+ multi_match : {
252+ query : criteria . search ,
253+ fields : [
254+ 'name.text^2.5' ,
255+ 'tags^1.5' ,
256+ 'description^1.0'
257+ ] ,
258+ type : 'most_fields' ,
259+ minimum_should_match : '50%' ,
260+ fuzziness : 'AUTO' ,
261+ boost : 1
228262 }
229263 } )
230264 } else {
@@ -529,6 +563,14 @@ async function searchChallenges (currentUser, criteria) {
529563 } )
530564 }
531565
566+ if ( multiMatchQuery ) {
567+ mustQuery . push ( {
568+ bool : {
569+ should : multiMatchQuery
570+ }
571+ } )
572+ }
573+
532574 if ( boolQuery . length > 0 ) {
533575 mustQuery . push ( {
534576 bool : {
You can’t perform that action at this time.
0 commit comments