Skip to content

Commit beb2264

Browse files
committed
Registration of events for partial updating of an index is simplified.
1 parent 0f20a01 commit beb2264

File tree

6 files changed

+39
-51
lines changed

6 files changed

+39
-51
lines changed

README.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Laravel 5 Lucene search
1+
Laravel 5.0 Lucene search
22
==============
33

44
[![Latest Stable Version](https://poser.pugx.org/nqxcode/laravel-lucene-search/v/stable.png)](https://packagist.org/packages/nqxcode/laravel-lucene-search)
@@ -7,7 +7,7 @@ Laravel 5 Lucene search
77
[![Build Status](https://travis-ci.org/nqxcode/laravel-lucene-search.svg?branch=master)](https://travis-ci.org/nqxcode/laravel-lucene-search)
88

99

10-
Laravel 5 package for full-text search over Eloquent models based on ZendSearch Lucene.
10+
Laravel 5.0 package for full-text search over Eloquent models based on ZendSearch Lucene.
1111

1212
## Installation
1313

@@ -16,11 +16,8 @@ Require this package in your composer.json and run composer update:
1616
```json
1717
{
1818
"require": {
19-
"nqxcode/laravel-lucene-search": "dev-master"
20-
},
21-
22-
"prefer-stable" : true,
23-
"minimum-stability": "dev"
19+
"nqxcode/laravel-lucene-search": "2.0.*"
20+
}
2421
}
2522
```
2623

@@ -172,7 +169,7 @@ class Dummy extends Model implements Searchable
172169
```
173170

174171
### Partial updating of search index
175-
For register models events (save/update/delete) `use Nqxcode\LuceneSearch\Model\Search` and call `registerEventsForSearchIndexUpdate` method of trait in `boot` method of model:
172+
For register of necessary events (save/update/delete) `use Nqxcode\LuceneSearch\Model\SearchTrait` in target model:
176173

177174
```php
178175

@@ -185,12 +182,6 @@ For register models events (save/update/delete) `use Nqxcode\LuceneSearch\Model\
185182
use SearchTrait;
186183

187184
// ...
188-
189-
public static function boot()
190-
{
191-
parent::boot();
192-
self::registerEventsForSearchIndexUpdate();
193-
}
194185
}
195186

196187
```

composer.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nqxcode/laravel-lucene-search",
3-
"description": "Laravel 5 package for full-text search over Eloquent models based on ZendSearch Lucene.",
3+
"description": "Laravel 5.0 package for full-text search over Eloquent models based on ZendSearch Lucene.",
44
"keywords": ["laravel", "lucene", "zendsearch", "eloquent", "search", "fulltext"],
55
"license": "MIT",
66
"authors": [
@@ -12,7 +12,7 @@
1212
"require": {
1313
"php": ">=5.4.0",
1414
"illuminate/support": "5.0.*",
15-
"nqxcode/zendsearch": "dev-master",
15+
"nqxcode/zendsearch": "2.*",
1616
"nqxcode/lucene-stemmer-en-ru": "1.*"
1717
},
1818
"require-dev": {
@@ -29,7 +29,5 @@
2929
"tests\\": "tests/"
3030
}
3131
},
32-
33-
"prefer-stable" : true,
34-
"minimum-stability": "dev"
32+
"minimum-stability": "stable"
3533
}

src/Nqxcode/LuceneSearch/Console/RebuildCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function fire()
1818
$this->output = new NullOutput;
1919
}
2020

21-
if (is_dir(Config::get('laravel-lucene-search.index.path'))) {
21+
if (is_dir(Config::get('laravel-lucene-search.index.path'))) {
2222
$this->call('search:clear');
2323
}
2424

src/Nqxcode/LuceneSearch/Model/Search.php

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php namespace Nqxcode\LuceneSearch\Model;
2+
3+
use App;
4+
5+
/**
6+
* Class Search
7+
* @package Nqxcode\LuceneSearch\Model
8+
*/
9+
trait SearchTrait
10+
{
11+
/**
12+
* Set event handlers for updating of search index.
13+
*/
14+
public static function bootSearchTrait()
15+
{
16+
self::saved(
17+
function ($model) {
18+
App::offsetGet('search')->update($model);
19+
}
20+
);
21+
22+
self::deleting(
23+
function ($model) {
24+
App::offsetGet('search')->delete($model);
25+
}
26+
);
27+
}
28+
}

tests/models/Product.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Illuminate\Database\Eloquent\Model;
44
use Illuminate\Database\Eloquent\Builder;
55
use Nqxcode\LuceneSearch\Model\Searchable;
6-
use Nqxcode\LuceneSearch\Model\Search;
6+
use Nqxcode\LuceneSearch\Model\SearchTrait;
77

88
/**
99
* Class Product
@@ -15,7 +15,7 @@
1515
*/
1616
class Product extends Model implements Searchable
1717
{
18-
use Search;
18+
use SearchTrait;
1919

2020
/**
2121
* @inheritdoc
@@ -25,11 +25,6 @@ public function isSearchable()
2525
return $this->publish;
2626
}
2727

28-
public static function boot()
29-
{
30-
self::registerEventsForSearchIndexUpdate();
31-
}
32-
3328
public function getOptionalAttributesAttribute()
3429
{
3530
return ['optional_attribute1' => "optional_value1"];

0 commit comments

Comments
 (0)