Skip to content

Commit b2b2786

Browse files
committed
Fixed incorrect full rebuild of search index.
1 parent 8da9df9 commit b2b2786

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/Nqxcode/LuceneSearch/Console/RebuildCommand.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ private function rebuild()
6666

6767
$this->searchIndexRotator = App::make('search.index.rotator');
6868
$queue = Config::get('laravel-lucene-search::queue');
69-
$indexPath = Config::get('laravel-lucene-search::index.path');
7069

7170
$modelRepositories = $this->search->config()->repositories();
72-
7371
if (count($modelRepositories) > 0) {
72+
73+
$originalIndexPath = Config::get('laravel-lucene-search::index.path');
74+
$newIndexPath = $this->searchIndexRotator->getNewIndexPath();
75+
76+
Config::set('laravel-lucene-search::index.path', $newIndexPath);
77+
7478
foreach ($modelRepositories as $modelRepository) {
7579
$this->info('Creating index for model: "' . get_class($modelRepository) . '"');
7680

@@ -85,8 +89,7 @@ private function rebuild()
8589
$progress = new ProgressBar($this->getOutput(), $count / $chunkCount);
8690
$progress->start();
8791

88-
$modelRepository->chunk($chunkCount, function ($chunk) use ($progress, $queue) {
89-
$newIndexPath = $this->searchIndexRotator->getNewIndexPath();
92+
$modelRepository->chunk($chunkCount, function ($chunk) use ($progress, $queue, $newIndexPath) {
9093

9194
if ($queue) {
9295
Queue::push(
@@ -99,7 +102,6 @@ private function rebuild()
99102
$queue);
100103

101104
} else {
102-
Config::set('laravel-lucene-search::index.path', $newIndexPath);
103105
foreach ($chunk as $model) {
104106
$this->search->update($model);
105107
}
@@ -111,7 +113,11 @@ private function rebuild()
111113
$progress->finish();
112114
$this->info(PHP_EOL);
113115
}
116+
117+
Config::set('laravel-lucene-search::index.path', $originalIndexPath);
118+
114119
$this->info(PHP_EOL . 'Operation is fully complete!');
120+
115121
} else {
116122
$this->error('No models found in config.php file..');
117123
}
@@ -124,7 +130,5 @@ private function rebuild()
124130
} else {
125131
$this->searchIndexRotator->rotate();
126132
}
127-
128-
Config::set('laravel-lucene-search::index.path', $indexPath);
129133
}
130134
}

src/Nqxcode/LuceneSearch/Job/MassUpdateSearchIndex.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function fire($job, array $jobData)
1414
$modelKeys = $jobData['modelKeys'];
1515
$indexPath = $jobData['indexPath'];
1616

17+
$originalIndexPath = Config::get('laravel-lucene-search::index.path');
1718
Config::set('laravel-lucene-search::index.path', $indexPath);
1819

1920
foreach ($modelKeys as $modelKey) {
@@ -23,6 +24,8 @@ public function fire($job, array $jobData)
2324
}
2425
}
2526

27+
Config::set('laravel-lucene-search::index.path', $originalIndexPath);
28+
2629
$job->delete();
2730
}
2831
}

0 commit comments

Comments
 (0)