@@ -63,37 +63,45 @@ public function getQuery()
6363 $ query = new BoolQuery ();
6464
6565 if (!empty ($ this ->tokens ['include ' ])) {
66- $ includeString = implode (' ' , $ this ->tokens ['include ' ]);
67-
6866 // the subscoping is not necessary but prevents unintentional accidents when combining other matchers
69- $ query -> must ( new BoolQuery ()
67+ $ boolQuery = new BoolQuery ()
7068 // results must contain at least one of the terms and boosted by containing all of them,
7169 // or match the id of the beatmapset.
7270 ->shouldMatch (1 )
73- ->should (['term ' => ['_id ' => ['value ' => $ includeString , 'boost ' => 100 ]]])
74- ->should ([
75- 'multi_match ' => [
76- 'fields ' => $ partialMatchFields ,
77- 'type ' => 'most_fields ' ,
78- 'query ' => $ includeString ,
79- ],
80- ])
81- ->should ([
82- 'nested ' => [
83- 'path ' => 'beatmaps ' ,
84- 'query ' => ['match ' => ['beatmaps.top_tags ' => ['query ' => $ includeString , 'operator ' => 'and ' , 'boost ' => 0.5 ]]],
85- ],
86- ]));
71+ ->should (['term ' => ['_id ' => ['value ' => implode (' ' , $ this ->tokens ['include ' ]), 'boost ' => 100 ]]]);
72+
73+ foreach ($ this ->tokens ['include ' ] as $ include ) {
74+ $ isQuoted = static ::isQuoted ($ include );
75+ $ boolQuery
76+ ->should ([
77+ 'multi_match ' => [
78+ 'fields ' => $ isQuoted ? $ fullMatchFields : $ partialMatchFields ,
79+ 'type ' => $ isQuoted ? 'phrase ' : 'most_fields ' ,
80+ 'query ' => $ include ,
81+ ],
82+ ])
83+ ->should ([
84+ 'nested ' => [
85+ 'path ' => 'beatmaps ' ,
86+ 'query ' => ['match ' => ['beatmaps.top_tags ' => ['query ' => $ include , 'operator ' => 'and ' , 'boost ' => 0.5 ]]],
87+ ],
88+ ]);
89+ }
90+
91+ $ query ->must ($ boolQuery );
8792 }
8893
8994 // exclusion should be full matches only, and only on the main beatmapset fields.
9095 if (!empty ($ this ->tokens ['exclude ' ])) {
91- $ query ->mustNot ([
92- 'multi_match ' => [
93- 'fields ' => $ fullMatchFields ,
94- 'query ' => implode (' ' , $ this ->tokens ['exclude ' ]),
95- ],
96- ]);
96+ foreach ($ this ->tokens ['exclude ' ] as $ exclude ) {
97+ $ query ->mustNot ([
98+ 'multi_match ' => [
99+ 'fields ' => $ fullMatchFields ,
100+ 'type ' => static ::isQuoted ($ exclude ) ? 'phrase ' : 'most_fields ' ,
101+ 'query ' => $ exclude ,
102+ ],
103+ ]);
104+ }
97105 }
98106
99107 $ this ->addBlockedUsersFilter ($ query );
0 commit comments