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

Search results missing "search_snippets" #11398

Open
ivang76 opened this issue Jan 28, 2025 · 4 comments
Open

Search results missing "search_snippets" #11398

ivang76 opened this issue Jan 28, 2025 · 4 comments
Labels

Comments

@ivang76
Copy link

ivang76 commented Jan 28, 2025

Bug description

I noticed that if I search for two words, the search_snippets array is populated only when the item found contains both words (even if they aren't on the same line). However, if the search result contains only one of the searched words, the search_snippets array remains empty.
I'm using the the native local driver, not algolia.

Is this some kind of limitation, a bug, or could I be missing some configuration parameters in the indexes?

Thanks!

How to reproduce

Simply create an index, for example my pages below, on the collection of static pages, and then run a search using two or more words to find (choosing them knowing that only one is present on a specific target page).

'pages' => [ 'driver' => 'local', 'searchables' => 'collection:*', 'fields' => ['title','main_body','description_block'], ],

Then dump the results and look into the structure, checking the search_snippets array, you will find an empty one.

Logs

Environment

Environment
Application Name: BAAM
Laravel Version: 11.34.2
PHP Version: 8.3.9
Composer Version: 2.2.7
Environment: local
Debug Mode: ENABLED
URL: localhost:8000
Maintenance Mode: OFF
Timezone: Europe/Zurich
Locale: it

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Livewire
Livewire: v3.5.16

Sentry
Enabled: MISSING DSN
Environment: local
Laravel SDK Version: 4.10.1
PHP SDK Version: 4.10.0
Release: NOT SET
Sample Rate Errors: 100%
Sample Rate Performance Monitoring: NOT SET
Sample Rate Profiling: NOT SET
Send Default PII: DISABLED

Statamic
Addons: 7
Sites: 2 (it, en)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.46.0 PRO

Statamic Addons
alt-design/alt-redirect: 1.6.1
anakadote/statamic-recaptcha: 1.0.16
eminos/statamic-tabs: 1.2.0
jacksleight/statamic-bard-texstyle: 3.4.1
ryanmitchell/statamic-translation-manager: 1.6.0
sortarad/extraextra: 1.0.1
statamic-rad-pack/runway: 7.13.4

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

@ivang76
Copy link
Author

ivang76 commented Jan 30, 2025

I found a possible workaround in this file vendor/statamic/cms/src/Search/Comb/Comb.php, in this part of code (around line 608)

 if ($matched && $j === 0) {
     $snippets[$name] = $this->extractSnippets($property, $params['chunks']);
     $snippets[$name][] = "gif";
 }

and by removing the check on $j, the search_snippets now correctly include matches that have only one searched item.
Does that make sense? It seems strange to me that no one else has encountered this issue before.

@ryanmitchell
Copy link
Contributor

I'm guessing the issue is your first chunk isnt setting $matched to true.

it probably needs changed to

if ($matched && ! isset($snippets[$name]))

@ivang76
Copy link
Author

ivang76 commented Jan 30, 2025

Hi @ryanmitchell, yes it seems working in this way. 👍
Let's way that someone of the admins check it as well, and let's hope a fix will be released soon.

@duncanmcclean
Copy link
Member

If you have a potential fix, feel free to open a pull request and we can take a look when we have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants