@@ -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}
0 commit comments