Skip to content

Commit 3dc441c

Browse files
committed
improve commands and output
1 parent 10182b4 commit 3dc441c

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# Release Notes for Elasticsearch Plugin
22

3-
## Unreleased
3+
## 1.1.0 - 2022-04-27
44

55
### Added
66

77
- Added console command to list all aliases and indexes of the configured Elasticsearch cluster.
88
- Added workflow to switch back to Craft's database index.
99
- Added console command to truncate Craft's database index table.
10+
- Field boosting.
1011

1112
### Fixed
1213

1314
- Utility page handles not existing index.
15+
- Let Elasticsearch filter and tokenize the keywords.
1416

15-
## 1.0.0 - 2022-4-08
17+
## 1.0.0 - 2022-04-08
1618

1719
### Added
1820

src/console/controllers/ElementsController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
class ElementsController extends Controller
1515
{
1616
/**
17-
* Reindex elements to current index.
17+
* Index elements to current index.
1818
*
1919
* @param string $siteHandle The site to index. Default '*' to reindex elements of all sites.
20-
* @param string $channel The queue channel to use.
20+
* @param string $queue The queue to use.
2121
* @param int $priority The queue priority to use.
2222
*/
23-
public function actionReindex(string $siteHandle = '*', string $channel = 'queue', int $priority = 2048)
23+
public function actionIndex(string $siteHandle = '*', string $queue = 'queue', int $priority = 2048)
2424
{
25-
$queue = Craft::$app->$channel;
25+
$queue = Craft::$app->$queue;
2626
$elementsTable = Table::ELEMENTS;
2727

2828
/**
@@ -39,7 +39,7 @@ public function actionReindex(string $siteHandle = '*', string $channel = 'queue
3939
'type' => $elementType,
4040
])->count();
4141

42-
if ($this->confirm("Reindex all $count elements of type '$elementType'? ")) {
42+
if ($this->confirm("Index all $count elements of type '$elementType'? ")) {
4343
$elementTypesToIndex[] = $elementType;
4444
}
4545
}
@@ -55,7 +55,7 @@ public function actionReindex(string $siteHandle = '*', string $channel = 'queue
5555
$total = $query->count();
5656
$counter = 0;
5757

58-
$this->stdout("Reindex $total elements of type '$type' ..." . PHP_EOL);
58+
$this->stdout("Index $total elements of type '$type' ..." . PHP_EOL);
5959

6060
Console::startProgress(0, $total);
6161
foreach ($query->batch() as $rows) {

src/console/controllers/IndexController.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function actionStats(string $siteHandle = '*')
5656
$this->stdout('":' . PHP_EOL);
5757
$this->stdout('Current index in use: ' . $indexName . PHP_EOL);
5858
$this->stdout('Elements in index: ' . $result['indices'][$indexName]['total']['docs']['count'] . PHP_EOL);
59-
$this->stdout('Stored data: ' . Craft::$app->getFormatter()->asShortSize($result['indices'][$indexName]['total']['store']['size_in_bytes']) . PHP_EOL);
59+
$this->stdout('Stored data: ' . Craft::$app->getFormatter()->asShortSize($result['indices'][$indexName]['total']['store']['size_in_bytes']) . PHP_EOL . PHP_EOL);
6060
} catch (Missing404Exception $e) {
6161
$this->stderr('Index for site "');
6262
$this->stderr($site->handle, BaseConsole::FG_YELLOW);
@@ -83,17 +83,26 @@ public function actionSource(int $elementId, string $siteHandle = '*')
8383

8484
$indexService = Elastic::$plugin->getIndexes();
8585
$sites = $this->_getSites($siteHandle);
86+
$table = new Table();
87+
$table->setHeaders([
88+
'Field handle',
89+
'Source',
90+
]);
91+
8692
foreach ($sites as $site) {
93+
$element = Craft::$app->getElements()->getElementById($elementId, null, $site->id);
94+
$rows = [];
8795
$this->stdout('Index source of element "');
8896
$this->stdout($element, BaseConsole::FG_YELLOW);
8997
$this->stdout('" for site "');
9098
$this->stdout($site->handle, BaseConsole::FG_YELLOW);
9199
$this->stdout('":' . PHP_EOL);
92100
try {
93101
$mappings = Elastic::$plugin->getIndexes()->source($elementId, $site);
94-
foreach ($mappings as $field => $mapping) {
95-
$this->stdout($indexService->mapFieldToAttribute($field) . ': ' . $mapping . PHP_EOL);
102+
foreach ($mappings as $field => $source) {
103+
$rows[] = [$indexService->mapFieldToAttribute($field), $source];
96104
}
105+
echo $table->setRows($rows)->run() . PHP_EOL . PHP_EOL;
97106
} catch (Missing404Exception $e) {
98107
$this->stdout('Element not indexed!' . PHP_EOL, BaseConsole::FG_RED);
99108
}
@@ -170,7 +179,7 @@ public function actionReindex(string $siteHandle = null)
170179
$this->stdout('Old index: ' . $result['oldIndexName'] . PHP_EOL);
171180
$this->stdout('New index: ' . $result['newIndexName'] . PHP_EOL);
172181
$this->stdout('Finished after: ' . $timeTook . PHP_EOL);
173-
$this->stdout('Total of ' . $result['total'] . ' elements migrated.' . PHP_EOL);
182+
$this->stdout('Total of ' . $result['total'] . ' elements migrated.' . PHP_EOL . PHP_EOL);
174183
}
175184
}
176185

src/console/controllers/MigrationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function actionReindex(string $date, bool $toDatabase = true, bool $toEla
5454
return;
5555
}
5656

57-
if (!$this->confirm('Reindex all elements created or updated since ' . $startDate->format(DATE_ISO8601) . '?')) {
57+
if (!$this->confirm('Re-index all elements created or updated since ' . $startDate->format(DATE_ISO8601) . '?')) {
5858
return;
5959
}
6060

src/jobs/ReindexUpdatedElements.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function execute($queue)
4040
$total = count($elements);
4141

4242
foreach ($elements as $i => $element) {
43-
$this->setProgress($queue, ($i + 1) / $total);
43+
$this->setProgress($queue, ($i + 1) / $total, ($i + 1) . ' / ' . $total);
4444
if ($this->toDatabaseIndex) {
4545
Craft::$app->getQueue()->push(new UpdateDatabaseIndex([
4646
'elementType' => $element['type'],

src/templates/settings.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<blockquote class="note warning">
1818
<p>Deactivate the transition mode only if you are sure that you have re-indexed all existing elements to the Elastisearch index. From then on, only the Elasticsearch index will be used and the database index will become outdated.</p>
1919
<p>You can switch back to transition mode at any time.</p>
20-
<p><a href="#">Check the documentation</a></p>
20+
<p><a href="https://plugins.codemonauts.com/plugins/elasticsearch/Migration.html">Check the documentation</a></p>
2121
</blockquote>
2222
</div>
2323
{% endif %}
@@ -26,7 +26,7 @@
2626
<div id="modeOn" class="readable hidden">
2727
<blockquote class="note tip">
2828
<p>When you reactivate the transition mode, all new and updated elements since the last deactivation ({{ settings.lastSwitch|datetime('short') }}) are automatically re-indexed. This will get the outdated database index up to date.</p>
29-
<p><a href="#">Check the documentation</a></p>
29+
<p><a href="https://plugins.codemonauts.com/plugins/elasticsearch/Migration.html">Check the documentation</a></p>
3030
</blockquote>
3131
</div>
3232
{% endif %}

0 commit comments

Comments
 (0)