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

[10.x] Add search engine meta data to results #780

Merged
merged 7 commits into from
Nov 21, 2023

Conversation

tobz-nz
Copy link
Contributor

@tobz-nz tobz-nz commented Nov 15, 2023

When adding extra options to search queries, xtra data may be return in the raw result - this PR adds the relevant details to the resulting Models via the withScoutMetadata() method.

Example:

$products = Product::search(
    $request->term,
    fn ($e, $q, $o) => $e->search($q, array_merge($o, [
        'attributesToHighlight' => ['title'],
        'showRankingScore' => true,
    ]))
)->paginate(48);

dd($products->first()->scoutMetadata());

// output
array:2 [
  "_formatted" => array:31 [
    "title" => "<em>HP</em> <em>Elitebook</em> 1040 G10 14 Inch i5-1335U 4.6GHz 16GB RAM 256GB SSD Laptop with Windows 10/11 Pro"
    ...
  ]
  "_rankingScore" => 0.86111111111111
]

add result meta data to the return models with `withScoutMetadata`
@driesvints driesvints changed the title Add meilisearch meta data to results [10.x] Add meilisearch meta data to results Nov 16, 2023
@mmachatschek
Copy link
Contributor

@tobz-nz there is a higher chance to get this merged if you could add tests + implement the equivalent code for the algolia search driver

@tobz-nz
Copy link
Contributor Author

tobz-nz commented Nov 16, 2023

@mmachatschek I've added the same functionality to AgloliaEngine and added some assertions into the test_map_correctly_maps_results_to_models tests for both engines (I hope this is ok and a separate test is not required - it makes so me putting it there)

I've also added the same functionality to the lazyMap methods as well.

@tobz-nz tobz-nz changed the title [10.x] Add meilisearch meta data to results [10.x] Add search engine meta data to results Nov 18, 2023
@taylorotwell taylorotwell merged commit f2bbeb3 into laravel:10.x Nov 21, 2023
7 checks passed
@tobz-nz tobz-nz deleted the patch-1 branch November 21, 2023 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants