cms
cms copied to clipboard
Search Improvements
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 get SearchResult
objects. You'll also be able to make any class implement Searchable
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.
There should be a separate index for each site. v2 did this as per Algolia's recommendation.
There would be a indexname_en
, indexname_fr
, etc.
Fixes #2699
Terms
At the moment, Term
s are the things that get indexed. Not LocalizedTerm
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
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.
It's probably worth disabling drafts from the index in the first place. Or make it configurable.
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. - Entries etc will implement
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. - Term queries will return multiple localized terms.
Todo
- [ ] Make term queries return LocalizedTerms, and avoid de-duplicating them.
- [ ] Fix the localized index issue
- [ ] Avoid indexing drafts.
- [ ] Saving terms should update the appropriate indexes
I'd also love to be able to exclude entries from the index, like here: https://github.com/statamic/cms/pull/6552.
Our use case would be a toggle on the entry to indicate not to search.
@jasonvarga For the filter situation I wanted to bring up in https://github.com/statamic/cms/pull/6552 I've already created a new Draft I will complete when this PR was merged. I hope to help you a little with this.
I'd love to see this in the core :)