Skip to content

Commit b1f6935

Browse files
committed
Fixed rebuild index command: MassUpdateSearchIndex job run with custom index path now instead of default path.
1 parent 0b7473b commit b1f6935

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

src/Nqxcode/LuceneSearch/Console/RebuildCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ private function rebuild()
8282
[
8383
'modelClass' => get_class($chunk[0]),
8484
'modelKeys' => $chunk->lists($chunk[0]->getKeyName()),
85+
'indexPath' => Config::get('laravel-lucene-search::index.path'),
8586
],
8687
$queue);
8788

src/Nqxcode/LuceneSearch/Job/MassUpdateSearchIndex.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ public function fire($job, array $jobData)
1111
{
1212
$modelClass = $jobData['modelClass'];
1313
$modelKeys = $jobData['modelKeys'];
14+
$indexPath = $jobData['indexPath'];
1415

1516
foreach ($modelKeys as $modelKey) {
1617
$model = $modelClass::find($modelKey);
1718
if (!is_null($model)) {
18-
app('search')->update($model);
19+
app('search')->useIndexPath($indexPath)->update($model);
1920
}
2021
}
2122

src/Nqxcode/LuceneSearch/Search.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class Search
2828
*/
2929
protected $connection;
3030

31+
/**
32+
* @var string
33+
*/
34+
protected $indexPath;
35+
3136
/**
3237
* Get descriptor for open index.
3338
*
@@ -38,6 +43,19 @@ public function index()
3843
return $this->makeConnection()->getIndex();
3944
}
4045

46+
/**
47+
* Use index path for connection.
48+
*
49+
* @param $indexPath
50+
* @return $this
51+
*/
52+
public function useIndexPath($indexPath)
53+
{
54+
$this->indexPath = $indexPath;
55+
56+
return $this;
57+
}
58+
4159
/**
4260
* Model configurator.
4361
*
@@ -79,7 +97,7 @@ public function __destruct()
7997
private function makeConnection()
8098
{
8199
if (null === $this->connection) {
82-
$this->connection = call_user_func($this->connectionBuilder);
100+
$this->connection = call_user_func($this->connectionBuilder, $this->indexPath);
83101
}
84102

85103
return $this->connection;

src/Nqxcode/LuceneSearch/ServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public function register()
5151
QueryParser::setDefaultEncoding('utf-8');
5252

5353
return new Search(
54-
function () {
54+
function ($indexPath = null) {
5555
return new Connection(
56-
$this->app['search.index.path'],
56+
$indexPath ?: $this->app['search.index.path'],
5757
$this->app->make('Nqxcode\LuceneSearch\Analyzer\Config')
5858
);
5959
},

0 commit comments

Comments
 (0)