Skip to content
This repository was archived by the owner on Jul 31, 2018. It is now read-only.

Commit d700911

Browse files
committed
Cleanup documentation
1 parent 3988deb commit d700911

File tree

1 file changed

+54
-57
lines changed

1 file changed

+54
-57
lines changed

README.md

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,38 @@
1-
Algolia Search for Laravel
2-
==================
1+
# Laravel Algolia Search
32

4-
This php package integrate the Algolia Search API to your favorite Laravel Eloquent ORM. It's based on the [algoliasearch-client-php](https://github.com/algolia/algoliasearch-client-php) package. Php 5.4+ is supported.
3+
This php package integrate the Algolia Search API to your favorite 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.
54

65
[![Build Status](https://img.shields.io/travis/algolia/algoliasearch-laravel/master.svg?style=flat)](https://travis-ci.org/algolia/algoliasearch-laravel)
76
[![Latest Version](https://img.shields.io/github/release/algolia/algoliasearch-laravel.svg?style=flat)](https://github.com/algolia/algoliasearch-laravel/releases)
87
[![License](https://img.shields.io/packagist/l/algolia/algoliasearch-laravel.svg?style=flat)](https://packagist.org/packages/algolia/algoliasearch-laravel)
98

10-
Table of Content
11-
-------------
12-
**Get started**
9+
## Table of Content
1310

1411
1. [Install](#install)
15-
1. [Configuration](#configuration)
16-
1. [Quick Start](#quick-start)
17-
1. [Ranking & Relevance](#ranking--relevance)
18-
1. [Options](#options)
19-
1. [Indexing](#indexing)
20-
1. [Master/Slave](#masterslave)
21-
1. [Target multiple indexes](#target-multiple-indexes)
22-
1. [Search](#search)
23-
24-
Install
25-
-------------
12+
2. [Configuration](#configuration)
13+
3. [Quick Start](#quick-start)
14+
4. [Ranking & Relevance](#ranking--relevance)
15+
5. [Options](#options)
16+
6. [Indexing](#indexing)
17+
7. [Master/Slave](#masterslave)
18+
8. [Target multiple indexes](#target-multiple-indexes)
19+
9. [Search](#search)
20+
21+
## Install
2622

2723
Add `algolia/algoliasearch-laravel` to your `composer.json` file:
2824

29-
```json
30-
"require": {
31-
"algolia/algoliasearch-laravel": "master"
32-
}
25+
```bash
26+
composer require algolia/algoliasearch-laravel
3327
```
3428

3529
Add the service provider to ```config/app.php``` in the `providers` array.
3630

3731
```php
38-
'AlgoliaSearch\Laravel\AlgoliaServiceProvider'
32+
AlgoliaSearch\Laravel\AlgoliaServiceProvider::class
3933
```
4034

41-
Configuration
42-
-------------
35+
## Configuration
4336

4437
Laravel Algolia requires connection configuration. To get started, you'll need to publish all vendor assets:
4538

@@ -49,15 +42,14 @@ php artisan vendor:publish
4942

5043
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 to the original config file in this package between releases.
5144

52-
53-
54-
Quick Start
55-
-------------
45+
## Quick Start
5646

5747
The following code will create a <code>Contact</code> add search capabilities to your <code>Contact</code> model:
5848

5949
```php
60-
class Contact extends \Illuminate\Database\Eloquent\Model
50+
use Illuminate\Database\Eloquent\Model;
51+
52+
class Contact extends Model
6153
{
6254
use AlgoliaEloquentTrait;
6355
}
@@ -68,7 +60,9 @@ By default all your visible attributes will be send
6860
If you want to send specific attributes you can do something like
6961

7062
```php
71-
class Contact extends \Illuminate\Database\Eloquent\Model
63+
use Illuminate\Database\Eloquent\Model;
64+
65+
class Contact extends Model
7266
{
7367
use AlgoliaEloquentTrait;
7468

@@ -88,14 +82,16 @@ class Contact extends \Illuminate\Database\Eloquent\Model
8882
We provide many ways to configure your index allowing you to tune your overall index relevancy. The most important ones are the **searchable attributes** and the attributes reflecting **record popularity**.
8983

9084
```php
91-
class Contact extends \Illuminate\Database\Eloquent\Model
85+
use Illuminate\Database\Eloquent\Model;
86+
87+
class Contact extends Model
9288
{
9389
use AlgoliaEloquentTrait;
9490

9591
public $algoliaSettings = [
9692
'attributesToIndex => ['id', 'name'],
97-
'customRanking => ['desc(popularity)'], 'asc(name)]'
98-
]
93+
'customRanking => ['desc(popularity)', 'asc(name)'],
94+
];
9995
}
10096
```
10197

@@ -129,10 +125,9 @@ You could also use `search` but it's not recommended. This method will search on
129125
Contact::search("jon doe");
130126
```
131127

132-
Options
133-
----------
128+
## Options
134129

135-
#### Auto-indexing & asynchronism
130+
#### Auto-indexing & Asynchronism
136131

137132
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.
138133

@@ -152,15 +147,16 @@ You can temporary disable auto-indexing. This is often used for performance reas
152147

153148
```php
154149
Contact::$autoIndex = false;
155-
Contact.clearIndices();
150+
Contact::clearIndices();
156151

157-
for ($i = 0; $i < 10000; $i++)
152+
for ($i = 0; $i < 10000; $i++) {
158153
$contact = Contact::firstOrCreate(['name' => 'Jean']);
154+
}
159155

160-
Contact::reindex() # will use batch operations
156+
Contact::reindex(); // Will use batch operations.
161157
```
162158

163-
#### Custom index name
159+
#### Custom Index Name
164160

165161
By default, the index name will be the class name pluriazed, e.g. "Contacts". You can customize the index name by using the `indices` option:
166162

@@ -173,7 +169,7 @@ class Contact extends \Illuminate\Database\Eloquent\Model
173169
}
174170
```
175171

176-
#### Per-environment indexes
172+
#### Per-environment Indexes
177173

178174
You can suffix the index name with the current Rails environment using the following option:
179175

@@ -199,7 +195,7 @@ class Contact extends \Illuminate\Database\Eloquent\Model
199195
}
200196
```
201197

202-
#### Restrict indexing to a subset of your data
198+
#### Restrict Indexing to a Subset of Your Data
203199

204200
You can add constraints controlling if a record must be indexed by defining indexOnly function.
205201

@@ -219,10 +215,9 @@ class Contact extends \Illuminate\Database\Eloquent\Model
219215
}
220216
```
221217

222-
Indexing
223-
---------
218+
## Indexing
224219

225-
#### Manual indexing
220+
#### Manual Indexing
226221

227222
You can trigger indexing using the <code>pushToindex</code> instance method.
228223

@@ -231,7 +226,7 @@ $c = Contact::firstOrCreate(['name' => 'Jean']);
231226
$c->pushToindex();
232227
```
233228

234-
#### Manual removal
229+
#### Manual Removal
235230

236231
And trigger index removing using the <code>removeFromIndex</code> instance method.
237232

@@ -253,16 +248,15 @@ To reindex all your records (in place, without deleting out-dated records):
253248
Contact::reindex(false)
254249
```
255250

256-
#### Clearing an index
251+
#### Clearing an Index
257252

258253
To clear an index, use the <code>clear_index!</code> class method:
259254

260255
```ruby
261256
Contact::clearIndices()
262257
```
263258

264-
Master/slave
265-
---------
259+
## Master/Slave
266260

267261
You can define slave indexes in the `$algolia_settings` variable:
268262

@@ -300,24 +294,22 @@ To search using a slave, use the following code:
300294
Book.search('foo bar', ['index' => 'contacts_desc']);
301295
```
302296

303-
Target multiple indexes
304-
---------
297+
## Target Multiple Indexes
305298

306299
You can index a record in several indexes using the <code>add_index</code> method:
307300

308301
```php
309-
class Contact extends \Illuminate\Database\Eloquent\Model
302+
use Illuminate\Database\Eloquent\Model;
303+
304+
class Contact extends Model
310305
{
311306
use AlgoliaEloquentTrait;
312307

313-
public $indices = ["contact_public", "contact_private"];
308+
public $indices = ['contact_public', 'contact_private'];
314309

315310
public function indexOnly($indexName)
316311
{
317-
if ($indexName == "contact_public")
318-
return $this->isPublic == 1;
319-
320-
return $this->isPublic == 0;
312+
return $indexName === 'contact_public';
321313
}
322314

323315
}
@@ -328,3 +320,8 @@ To search using an extra index, use the following code:
328320
```php
329321
Book::search('foo bar', ['index' => 'contacts_desc']);
330322
```
323+
324+
## License
325+
326+
Laravel Algolia Search is licensed under [The MIT License (MIT)](LICENSE).
327+

0 commit comments

Comments
 (0)