Search
You're browsing the documentation for an old version of MoonShine. Consider upgrading your project to MoonShine 2.x.
-
Sections
# Основы
Everything is simple here! For a full-text search, you need to specify which fields will be included into the search.
To do this, you need to list them in the return array in the search()
method
If the method is missing or returns an empty array, the search string will not be displayed
namespace MoonShine\Resources; use MoonShine\Models\MoonshineUser; class PostResource extends Resource{ //... public function search(): array { return ['id', 'title']; } //...}
If a fulltext search is required, you must use the MoonShine\Attributes\SearchUsingFullText
namespace MoonShine\Resources; use MoonShine\Attributes\SearchUsingFullText; class PostResource extends Resource { //... #[SearchUsingFullText(['title', 'text'])] public function search(): array { return ['id']; } //... }
Don't forget to add the fulltext index
# Global search
To organize a global search, you can use the package Algolias search for MoonShine
This package uses the Algolia
search engine, which takes context and query type into account,
possible typos, synonyms and word forms, entering a query in different languages and much more.