-
-
Notifications
You must be signed in to change notification settings - Fork 561
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 Improvements #6318
Merged
Merged
Search Improvements #6318
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- refactor to result classes - providers are responsible for finding their corresponding items instead of doing Data::find - added a generic result class for the 90% use case - registering a provider needs to be newed up instead of passing the string - clean up search tag class. - search:results paginate no longer needs "as" parameter. breaking change - algolia adds search_score which is are just decrementing numbers
I'd also love to be able to exclude entries from the index, like here: #6552. Our use case would be a toggle on the entry to indicate not to search. |
# Conflicts: # src/Assets/Asset.php # src/Auth/User.php # src/Entries/Entry.php # tests/Search/SearchablesTest.php
3 tasks
- Indexes accept a locale - Searchable providers can handle filtering by site where appropriate (eg. entries and terms, but not assets or users) - Removed the `Search::clearIndex` and `Search::indexExists` methods. - Rework searchable tests so that it checks that provide/contains are called on the provider, and then move tests into each provider
…tentially add their own data to templates. e.g. algolia highlighting
This was referenced Jan 24, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR will target
master
since there are some minor breaking changes.Searchables
The plan here is to make search deal with dedicated classes and interfaces to make extending it simpler.
e.g. When you perform a search, instead of getting back the models (like an
Entry
) directly, you'd getSearchResult
objects. You'll also be able to make any class implementSearchable
which will know how to convert itself to a result.Then each "type" would have a
Provider
class that provides Searchables that can be indexed. It would know how to do the opposite too: take an indexed item (which is just an array of values) and get the actual item (e.g. an Entry).Replaces #5179
Fixes: statamic/ideas#519
Localization
At the moment localization and search doesn't play so well together.
You can now opt to have localized indexes by specifying the sites.
'myindex' => [ 'driver' => 'local', 'searchables' => 'all', + 'sites' => ['en', 'fr'], // or 'sites' => 'all' ]
Doing this will result in multiple indexes (
myindex_en
,myindex_fr
), and localized content will go into the appropriate one. This is how Algolia suggests to do it. If an index contains non-localizable items (e.g. assets or users), they'll be available in all of them.Fixes #2699
Terms
At the moment,
Term
s are the things that get indexed. NotLocalizedTerm
s. When you save a localized version of a term, it doesn't update anything. Goes along with the localization improvement mentioned above.In order to fix this, querying terms will need to change a bit. Right now if you were to do Term::all(), you'd get LocalizedTerms, but only from one site. It'll need to change to include terms from all sites.
Fixes #3274
Filtering searchables (and drafts)
It's probably not a great idea to have drafts be indexed. Yes the
search:results
tag filters them out, but if you're pushing them to Algolia then using JavaScript to get the results directly from them, you'll need to filter them out yourself.Draft entries will now be filtered out by default.
You can also configure what items are indexed.
Setting a custom filter will override the default filter (for entries, that's where the drafts are filtered out). In the above example, we make sure to continue to filter out drafts, plus an
is_searchable
field - maybe that's atoggle
.Fixes #5239
Breaking Changes
Result
classes will be returned from search queries instead of the actual objects. This won't have any differences within templates, but could if you're doing searches in PHP and relying on Entry objects, etc.Searchable
, which will require anyone with custom Entry classes that don't extend our Entry class to implement it too. If they extend our classes (which seems to be the majority) no changes will be needed.LocalizedTerm@reference
now includes the site handle. e.g.term::tags::foo
becomesterm::tags::foo::english
. Theid
doesn't change.Todo