After setting up your model, you need to manually do an initial import of your data. You can do this by calling reindex on your model class. Using our previous example, this would be:

Contact::reindex();

Ranking & Relevance

We provide many ways to configure your index settings to tune the overall relevancy, but the most important ones are the searchable attributes and the attributes reflecting the record popularity. You can configure them with the following code:

You can propagate (save) the settings to algolia using the setSetting method:

Contact::setSettings();

Frontend Search (realtime experience)

Traditional search implementations tend to have search logic and functionality on the backend. This made sense when the search experience consisted of a user entering a search query, executing that search, and then being redirected to a search result page.

Implementing search on the backend is no longer necessary. In fact, in most cases it is harmful to performance because of the extra network and processing latency. We highly recommend the usage of our JavaScript API Client issuing all search requests directly from the end user's browser, mobile device, or client. It will reduce the overall search latency while offloading your servers at the same time.

Be careful to define those two methods in AlgoliaEloquentTrait.
When putting those methods in a parent class they will be "erased" by AlgoliaEloquentTrait if used in a child class
(because of php inheritance).

Custom Index Name

By default, the index name will be the pluralized class name, e.g. "Contacts". You can customize the index name by using the $indices option:

Indexing

Visibility

By default, Algolia will only be able to access visible attributes of your model. So, for example, you will receive a No content in PUT request exception when using this example code, because invisible_attribute key returns an empty/null variable.

Before Indexing, be sure to have correctly listed your visible attributes. To bypass this safety mask imposed by Laravel, you may use $this->attributes['invisible_attribute'] to access directly to the attribute even if is not visible, but the recommendation is to avoid this type of access to attributes in your Model.