Skip to content

Commit

Permalink
Updated docs to reflect api changes.
Browse files Browse the repository at this point in the history
Behaviour of against has changed, and the docs now reflect that.
  • Loading branch information
sciku1 authored Dec 18, 2017
1 parent 99e9274 commit 774b64d
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ You're done!
You must register the service provider in your `config/app.php`

```
'providers' => [
...
Sciku1/LaravelMatchAgainst/Providers/MatchAgainstServiceProvider::class
]
'providers' => [
...
Sciku1/LaravelMatchAgainst/Providers/MatchAgainstServiceProvider::class
]
```

## Usage
Expand All @@ -29,14 +29,33 @@ To run match against queries, the field must have a fulltext index, currently th
DB::statement('ALTER TABLE `table_name` ADD FULLTEXT index_name(col1, col2)');
```

Now you can run your query!
### Order
The default behaviour is to order. Example:

```
Model::match(['col1', 'col2'])->against('search terms')->get();
```

You can also order by the aggregate of the scores, although right now it must be the last term.
will generate

```
Model::match(['col1', 'col2'])->against('search terms')->totalScore('DESC')->get() // or 'ASC'
SELECT * FROM models ORDER BY (MATCH (col1) AGAINST ('search terms')) DESC, (MATCH (col2) AGAINST ('search terms')) DESC
```

### Where

To limit the results, you must use `whereAgainst()`

```
Model::match(['col1', 'col2'])->whereAgainst('search terms')->get();
```

will generate

```
SELECT * FROM models WHERE (MATCH (col1) AGAINST ('search terms')) > 0, (MATCH (col2) AGAINST ('search terms')) > 0
```

### TotalScore (deprecated)
You can get the sum of all results using totalScore(), but this will be removed in a later release.

0 comments on commit 774b64d

Please sign in to comment.