Skip to content

Commit d6fc079

Browse files
committed
handle terms seperately
1 parent 4897dbf commit d6fc079

1 file changed

Lines changed: 31 additions & 21 deletions

File tree

app/Libraries/Search/BeatmapsetSearch.php

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,34 +66,44 @@ public function getQuery()
6666
$includeString = implode(' ', $this->tokens['include']);
6767

6868
// the subscoping is not necessary but prevents unintentional accidents when combining other matchers
69-
$query->must(new BoolQuery()
69+
$boolQuery = new BoolQuery()
7070
// results must contain at least one of the terms and boosted by containing all of them,
7171
// or match the id of the beatmapset.
7272
->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-
]));
73+
->should(['term' => ['_id' => ['value' => $includeString, 'boost' => 100]]]);
74+
75+
foreach ($this->tokens['include'] as $include) {
76+
$isQuoted = static::isQuoted($include);
77+
$boolQuery
78+
->should([
79+
'multi_match' => [
80+
'fields' => $isQuoted ? $fullMatchFields : $partialMatchFields,
81+
'type' => $isQuoted ? 'phrase' : 'most_fields',
82+
'query' => $include,
83+
],
84+
])
85+
->should([
86+
'nested' => [
87+
'path' => 'beatmaps',
88+
'query' => ['match' => ['beatmaps.top_tags' => ['query' => $include, 'operator' => 'and', 'boost' => 0.5]]],
89+
],
90+
]);
91+
}
92+
93+
$query->must($boolQuery);
8794
}
8895

8996
// exclusion should be full matches only, and only on the main beatmapset fields.
9097
if (!empty($this->tokens['exclude'])) {
91-
$query->mustNot([
92-
'multi_match' => [
93-
'fields' => $fullMatchFields,
94-
'query' => implode(' ', $this->tokens['exclude']),
95-
],
96-
]);
98+
foreach ($this->tokens['exclude'] as $exclude) {
99+
$query->mustNot([
100+
'multi_match' => [
101+
'fields' => $fullMatchFields,
102+
'type' => static::isQuoted($exclude) ? 'phrase' : 'most_fields',
103+
'query' => $exclude,
104+
],
105+
]);
106+
}
97107
}
98108

99109
$this->addBlockedUsersFilter($query);

0 commit comments

Comments
 (0)