-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3353 from ProcessMaker/feature/FOUR-1725
Indexed Search
- Loading branch information
Showing
16 changed files
with
669 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
/public/js | ||
/public/css | ||
/storage/*.key | ||
/storage/*.index | ||
/vendor | ||
/.idea | ||
/.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace ProcessMaker\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use ProcessMaker\Models\Setting; | ||
use ProcessMaker\Traits\SupportsNonInteraction; | ||
|
||
class IndexedSearchDisable extends Command | ||
{ | ||
use SupportsNonInteraction; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'indexed-search:disable'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Disable indexed search'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
if ($this->interactive()) { | ||
$confirmed = $this->confirm("Are you sure you wish to disable indexed search?"); | ||
} else { | ||
$confirmed = true; | ||
} | ||
|
||
if ($confirmed) { | ||
$setting = Setting::updateOrCreate( | ||
[ 'key' => 'indexed-search' ], | ||
[ 'config' => [ 'enabled' => false ], ] | ||
); | ||
|
||
if ($setting->config['enabled'] === false) { | ||
$this->line('Indexed search has been disabled.'); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace ProcessMaker\Console\Commands; | ||
|
||
use App; | ||
use Illuminate\Console\Command; | ||
use ProcessMaker\Managers\IndexManager; | ||
use ProcessMaker\Models\Setting; | ||
use ProcessMaker\Traits\SupportsNonInteraction; | ||
|
||
class IndexedSearchEnable extends Command | ||
{ | ||
use SupportsNonInteraction; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'indexed-search:enable'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Enable faster searches'; | ||
|
||
private $manager; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->manager = App::make(IndexManager::class); | ||
$this->setCommandDescription(); | ||
parent::__construct(); | ||
} | ||
|
||
private function setCommandDescription() | ||
{ | ||
$items = $this->manager->list()->pluck('name')->implode(', '); | ||
return $this->description = "{$this->description} of {$items}"; | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
if ($this->interactive()) { | ||
$confirmed = $this->confirm( | ||
"Running this command will index data from Requests, Tasks, and packages that support indexed search. " . | ||
"This may take a very long time and consume system resources on large datasets.\n\n " . | ||
"Are you sure you wish to proceed?" | ||
); | ||
} else { | ||
$confirmed = true; | ||
} | ||
|
||
if ($confirmed) { | ||
$this->line("The indexer will occasionally display its status."); | ||
|
||
foreach ($this->manager->list() as $index) { | ||
$this->info("\nBeginning index of {$index->name}..."); | ||
if ($index->callback && is_callable($index->callback)) { | ||
call_user_func($index->callback); | ||
$this->info("All {$index->name} records have been imported."); | ||
} else { | ||
$this->call("scout:import", ['model' => $index->model]); | ||
} | ||
} | ||
|
||
$setting = Setting::updateOrCreate( | ||
[ 'key' => 'indexed-search' ], | ||
[ 'config' => [ 'enabled' => true ], ] | ||
); | ||
|
||
if ($setting->config['enabled'] === true) { | ||
$this->line("\nIndexed search has been enabled."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace ProcessMaker\Managers; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
class IndexManager | ||
{ | ||
private $indexes; | ||
|
||
public function __construct() | ||
{ | ||
$this->indexes = new Collection([]); | ||
} | ||
|
||
/** | ||
* Register index | ||
* | ||
* @param $name string name of index | ||
* @param $model string path of model | ||
* @param $callback callback function to perform indexing | ||
*/ | ||
public function add($name, $model, $callback = null) | ||
{ | ||
$this->indexes->push((object) [ | ||
'name' => $name, | ||
'model' => $model, | ||
'callback' => $callback, | ||
]); | ||
} | ||
|
||
/** | ||
* Get an index by name | ||
* | ||
* @param $name string name of index | ||
*/ | ||
public function get($name) | ||
{ | ||
return $this->indexes->where('name', $name)->first(); | ||
} | ||
|
||
/** | ||
* List indexes | ||
* | ||
*/ | ||
public function list() | ||
{ | ||
return $this->indexes; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.