22
33use App ;
44use Config ;
5+ use File ;
56use Illuminate \Console \Command ;
67use Nqxcode \LuceneSearch \Locker \Locker ;
78use Nqxcode \LuceneSearch \Search ;
89use Symfony \Component \Console \Helper \ProgressBar ;
910use Symfony \Component \Console \Input \InputOption ;
1011use Symfony \Component \Console \Output \NullOutput ;
12+ use Queue ;
1113
1214class RebuildCommand extends Command
1315{
@@ -68,14 +70,28 @@ private function rebuild()
6870 continue ;
6971 }
7072
71- $ progress = new ProgressBar ($ this ->getOutput (), $ count );
73+ $ chunkCount = Config::get ('laravel-lucene-search::chunk ' );
74+ $ progress = new ProgressBar ($ this ->getOutput (), $ count / $ chunkCount );
7275 $ progress ->start ();
7376
74- $ modelRepository ->chunk (1000 , function ($ chunk ) use ($ progress ) {
75- foreach ($ chunk as $ model ) {
76- $ this ->search ->update ($ model );
77- $ progress ->advance ();
77+ $ modelRepository ->chunk ($ chunkCount , function ($ chunk ) use ($ progress ) {
78+ $ queue = Config::get ('laravel-lucene-search::queue ' );
79+ if ($ queue ) {
80+ Queue::push (
81+ 'Nqxcode\LuceneSearch\Job\MassUpdateSearchIndex ' ,
82+ [
83+ 'modelClass ' => get_class ($ chunk [0 ]),
84+ 'modelKeys ' => $ chunk ->lists ($ chunk [0 ]->getKeyName ()),
85+ ],
86+ $ queue );
87+
88+ } else {
89+ foreach ($ chunk as $ model ) {
90+ $ this ->search ->update ($ model );
91+ }
7892 }
93+
94+ $ progress ->advance ();
7995 });
8096
8197 $ progress ->finish ();
@@ -89,19 +105,20 @@ private function rebuild()
89105
90106 private function softRebuild ()
91107 {
92- $ oldIndexPath = \ Config::get ('laravel-lucene-search::index.path ' );
108+ $ oldIndexPath = Config::get ('laravel-lucene-search::index.path ' );
93109 $ newIndexPath = sys_get_temp_dir () . '/laravel-lucene-search/ ' . uniqid ('index- ' , true );
94110
95- \ Config::set ('laravel-lucene-search::index.path ' , $ newIndexPath );
111+ Config::set ('laravel-lucene-search::index.path ' , $ newIndexPath );
96112
97113 $ this ->rebuild ();
98114
99115 $ this ->search ->destroyConnection ();
100116
101- \File::cleanDirectory ($ oldIndexPath );
102- \File::copyDirectory ($ newIndexPath , $ oldIndexPath );
117+ File::cleanDirectory ($ oldIndexPath );
118+ File::copyDirectory ($ newIndexPath , $ oldIndexPath );
119+ File::cleanDirectory ($ newIndexPath );
103120
104- \ Config::set ('laravel-lucene-search::index.path ' , $ oldIndexPath );
121+ Config::set ('laravel-lucene-search::index.path ' , $ oldIndexPath );
105122
106123 }
107124
0 commit comments