Filter/Scope search results in frontend #5036
-
Hi, I want to display a frontend search form with additional filter options. I am pretty sure I can make this with Controllers and Entry Repositories, but by doing so I am not able to use search indexes. I like to have a search index on collection "posts" for a search query string, but also be able to filter the search results. Is something like that possible? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Not sure I understand what you're trying to do, can you give an example? |
Beta Was this translation helpful? Give feedback.
-
No I don't think this is possible without writing your own implementation. You can still use the Search Index to get the results yourself pretty easily with something like this: (Taken from the Search::index()
->ensureExists()
->search($request->query('q'))
->get()
->filter(function ($item) {
// Implement your own custom filtering here, for example based on publish_date
})
->take(10)
->map(function ($item) {
return $item->toAugmentedCollection([
'title', 'edit_url',
'collection', 'is_entry',
'taxonomy', 'is_term',
'container', 'is_asset',
])->withShallowNesting();
}) |
Beta Was this translation helpful? Give feedback.
-
Have you tried adding condition parameters to the search tag just like the collection tag allows?
|
Beta Was this translation helpful? Give feedback.
No I don't think this is possible without writing your own implementation. You can still use the Search Index to get the results yourself pretty easily with something like this:
(Taken from the
Statamic\Http\Controllers\CP\SearchController
)