Skip to content

Query generation ignores multiple boosted areas. #141

@js-its

Description

@js-its

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:

  1. Enable query logging
  2. Confgure multiple boosted areas
  3. Run a search, inspect the query - this will show only a single boosted area in the should match array
  4. Apply the fix below
  5. 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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions