You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 31, 2018. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+31-25Lines changed: 31 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,16 @@
1
+
<!--NO_HTML-->
1
2
# Laravel Algolia Search
3
+
<!--/NO_HTML-->
2
4
3
5
This PHP package integrates the Algolia Search API to the Laravel Eloquent ORM. It's based on the [algoliasearch-client-php](https://github.com/algolia/algoliasearch-client-php) package. PHP 5.5.9+ is supported.
Laravel Algolia requires a connection configuration. To get started, you'll need to publish all vendor assets:
41
45
@@ -47,7 +51,7 @@ You can add the ```--provider="Vinkla\Algolia\AlgoliaServiceProvider"``` option
47
51
48
52
This will create a `config/algolia.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes compared to the original config file after an upgrade.
49
53
50
-
##Quick Start
54
+
# Quick Start
51
55
52
56
The following code adds search capabilities to your `Contact` model creating a `Contact` index:
53
57
@@ -79,7 +83,7 @@ class Contact extends Model
79
83
}
80
84
```
81
85
82
-
####Ranking & Relevance
86
+
## Ranking & Relevance
83
87
84
88
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:
85
89
@@ -109,7 +113,7 @@ You can propagate (save) the settings to algolia using the `setSetting` method:
109
113
Contact::setSettings();
110
114
```
111
115
112
-
####Frontend Search (realtime experience)
116
+
## Frontend Search (realtime experience)
113
117
114
118
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.
You could also use the `search` method but it's not recommended to implement instant/realtime search experience:
131
135
132
136
```php
133
137
Contact::search('jon doe');
134
138
```
135
139
136
-
##Options
140
+
# Options
137
141
138
-
####Auto-indexing & Asynchronism
142
+
## Auto-indexing & Asynchronism
139
143
140
144
Each time a record is saved; it will be - asynchronously - indexed. On the other hand, each time a record is destroyed, it will be - asynchronously - removed from the index.
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:
172
176
@@ -181,7 +185,7 @@ class Contact extends Model
181
185
}
182
186
```
183
187
184
-
####Per-environment Indexes
188
+
## Per-environment Indexes
185
189
186
190
You can suffix the index name with the current App environment using the following option:
187
191
@@ -196,7 +200,7 @@ class Contact extends Model
196
200
}
197
201
```
198
202
199
-
####Custom `objectID`
203
+
## Custom `objectID`
200
204
201
205
By default, the `objectID` is based on your record's `keyName` (`id` by default). You can change this behavior specifying the `objectIdKey` option (be sure to use a uniq field).
202
206
@@ -211,7 +215,7 @@ class Contact extends Model
211
215
}
212
216
```
213
217
214
-
####Restrict Indexing to a Subset of Your Data
218
+
## Restrict Indexing to a Subset of Your Data
215
219
216
220
You can add constraints controlling if a record must be indexed by defining the `indexOnly()` method.
217
221
@@ -229,7 +233,7 @@ class Contact extends Model
229
233
}
230
234
```
231
235
232
-
###Relationships
236
+
# Relationships
233
237
234
238
By default the Algolia package will fetch the **loaded** relationships.
235
239
@@ -270,9 +274,9 @@ public function getAlgoliaRecord()
270
274
271
275
272
276
273
-
##Indexing
277
+
# Indexing
274
278
275
-
####Manual Indexing
279
+
## Manual Indexing
276
280
277
281
You can trigger indexing using the `pushToIndex` instance method.
To *safely* reindex all your records (index to a temporary index + move the temporary index to the current one atomically), use the `reindex` class method:
295
300
@@ -303,15 +308,15 @@ To reindex all your records (in place, without deleting out-dated records):
303
308
Contact::reindex(false);
304
309
```
305
310
306
-
####Clearing an Index
311
+
## Clearing an Index
307
312
308
313
To clear an index, use the `clearIndices` class method:
309
314
310
315
```ruby
311
316
Contact::clearIndices();
312
317
```
313
318
314
-
##Master/Slave
319
+
# Master/Slave
315
320
316
321
You can define slave indexes using the `$algolia_settings` variable:
317
322
@@ -359,7 +364,7 @@ To search using a slave use the following code:
0 commit comments