Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10618 - Order of modules in unified search results does not correspond to order in settings (Elasticsearch) #10619

Open
wants to merge 1 commit into
base: hotfix
Choose a base branch
from

Conversation

ZizOsher
Copy link

Modified the parseHits function in /lib/Search/ElasticSearch/ElasticSearchEngine.php so that the search results are parsed based on the order given in Search Settings.

Description

I added a loop before the loop over initialResults which sets the keys of the array to be the enabled modules which are set in Admin->'Search Settings'
'''
private function parseHits(array $hits): array
{
$hitsArray = $hits['hits']['hits'];

    $initialResults = [];

    foreach ($hitsArray as $hit) {
        $recordModule = $hit['_index'];
        $initialResults[$recordModule][] = $hit['_id'];
    }

    $searchResults = [];

    // This is my code:
    $enabledModules = SearchModules::getEnabledModules();
    foreach ($enabledModules as $enabledModule) {
        $searchResults[$enabledModule] = [];
    }
    foreach ($initialResults as $index => $hit) {
        $params = ['index' => $index];
        $meta = $this->client->indices()->getMapping($params);
        $moduleName = $meta[$index]['mappings']['_meta']['module_name'];
        $searchResults[$moduleName] = $hit;
    }

    return $searchResults;
}

'''

Motivation and Context

Clients have complained that the order of the results of the unified search doesn't match the order they defined in Admin->'Search Settings'.

How To Test This

This is a bugfix for issue #10618, so to test this you can simply try to reproduce the bug as described in the bug report.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Final checklist

  • My code follows the code style of this project found here.
  • My change requires a change to the documentation.
  • I have read the How to Contribute guidelines.

…oes not correspond to order in settings (Elasticsearch)
@SuiteBot
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@mattlorimer mattlorimer added Status: Requires Updates Issues & PRs which requires input or update from the author PR 1-3 Complexity Score given to PRs once assessed labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR 1-3 Complexity Score given to PRs once assessed Status: Requires Updates Issues & PRs which requires input or update from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants