When considering the boosted area settings and logic, the query logic in query.php/get_query() function utilises the PHP array_merge function to combine multiple boosted areas, however this function has been used incorrectly by not assigning the result of the merge back to the query data (i.e. it has been used as if the array being merged is passed by reference).
This issue can be recreated/checked as follows:
- Enable query logging
- Confgure multiple boosted areas
- Run a search, inspect the query - this will show only a single boosted area in the
should match array
- Apply the fix below
- Run the same search, inspect the query - the
should match array will contain multiple elements, i.e. for each boosted area
This issue occurrs in 2 places:
if ($filters->context->contextlevel !== CONTEXT_COURSE) {
// If it's a block or activity, also add a boost for the specific context id.
$contextid = $filters->context->id;
$contextboost = $this->consruct_location_boosting('contextid', $contextid, self::CONTEXT_BOOST);
if (count($query['query']['bool']['should'])) {
array_merge ($query['query']['bool']['should'], $contextboost);
} else {
$query['query']['bool']['should'] = $contextboost;
}
}
if ($boostedareas) {
$boosting = $this->consruct_boosting($boostedareas);
if (count($query['query']['bool']['should'])) {
array_merge ($query['query']['bool']['should'], $boosting);
} else {
$query['query']['bool']['should'] = $boosting;
}
}
The fix is to simply change the affected lines to:
$query['query']['bool']['should'] = array_merge ($query['query']['bool']['should'], $contextboost);
$query['query']['bool']['should'] = array_merge ($query['query']['bool']['should'], $boosting);
When considering the boosted area settings and logic, the query logic in
query.php/get_query()function utilises the PHParray_mergefunction to combine multiple boosted areas, however this function has been used incorrectly by not assigning the result of the merge back to the query data (i.e. it has been used as if the array being merged is passed by reference).This issue can be recreated/checked as follows:
shouldmatch arrayshouldmatch array will contain multiple elements, i.e. for each boosted areaThis issue occurrs in 2 places:
The fix is to simply change the affected lines to: