Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions app/Libraries/Search/BeatmapsetSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@ public function getQuery()

$query = new BoolQuery();

if (present($this->params->queryString)) {
$terms = explode(' ', $this->params->queryString);
$queryString = $this->params->queryString;
if (present($queryString)) {
// force exclusion even in `or` query
$queryString = preg_replace('/(^|\s)-/u', ' +-', $queryString);
$terms = explode(' ', $queryString);

// the subscoping is not necessary but prevents unintentional accidents when combining other matchers
$query->must(
(new BoolQuery())
// results must contain at least one of the terms and boosted by containing all of them,
// or match the id of the beatmapset.
->shouldMatch(1)
->should(['term' => ['_id' => ['value' => $this->params->queryString, 'boost' => 100]]])
->should(QueryHelper::queryString($this->params->queryString, $partialMatchFields, 'or', 1 / count($terms)))
->should(QueryHelper::queryString($this->params->queryString, [], 'and'))
->should(['term' => ['_id' => ['value' => $queryString, 'boost' => 100]]])
->should(QueryHelper::queryString($queryString, $partialMatchFields, 'or', 1 / count($terms)))
->should(QueryHelper::queryString($queryString, [], 'and'))
);
}

Expand Down