Advanced
Model Configuration
Index Name
By default, Magnify uses the table name of your model as the index name. You can change this behavior by overriding the $indexName
getter function.
Depending on your Search engine, you might as well have to change your index
configuration in config/magnify.ts
to match your new index name.
Model Searchable Data
By default, Magnify uses model.serialize()
to store your model in the index. You can change this behavior by overriding the toSearchableObject
method.
Model Search Engine
If you have configured multiple engine, you can define the use Search engine per model.
Commands
magnify:import
If you are installing Magnify into an existing project, you may already have database records you need to import into your indexes. Magnify provides a magnify:import Ace command that you may use to import all of your existing records into your search indexes:
magnify:flush
Flush is the opposite of the magnify:import
command, it will delete all the documents of the index.
magnify:sync-index-settings
For the Search engines that require prior index configuration, you will need to use the magnify:sync-index-settings
command.
Search
You may begin searching a model using the search
method. The search method accepts a single string that will be used to search your models. You should then chain the get
method onto the search query to retrieve the Lucid models that match the given search query:
Where Clauses
Magnify allows you to add simple "where" clauses to your search queries. Currently, these clauses only support basic numeric equality checks and are primarily useful for scoping search queries by an owner ID:
In addition, the whereIn
method may be used to verify that a given column's value is contained within the given array:
If your application is using Meilisearch, you must configure your application's filterable attributes before utilizing Magnify's "where" clauses.
Pagination
In addition to retrieving a collection of models, you may paginate your search results using the paginate method. This method will return a SimplePaginator
instance just as if you had paginated a traditional Lucid query:
Once you have retrieved the results, you may display the results and render the page links using Edge just as if you had paginated a traditional Lucid query:
You can find more informations about pagination on the Official Lucid Documentation