Skip to content

Commit 8897097

Browse files
committed
Merge branch 'release/3.3.0'
2 parents 75e382b + f001ae1 commit 8897097

37 files changed

+648
-183
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# v3.3.0
2+
## 12/02/2020
3+
4+
1. [](#new)
5+
* Upgraded to TNTSearch version 2.5
6+
* Pass phpstan level 7 tests
7+
1. [](#bugfix)
8+
* Fixed FlexPages events for add+delete
9+
* Fixed running scheduled index job [#104](https://github.com/trilbymedia/grav-plugin-tntsearch/pull/104)
10+
111
# v3.2.1
212
## 09/04/2020
313

blueprints.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: TNT Search
2-
slug: tntsearch
32
type: plugin
4-
version: 3.2.1
3+
slug: tntsearch
4+
version: 3.3.0
55
testing: false
66
description: Powerful indexed-based full text search engine powered by TNTSearch
77
icon: binoculars

classes/GravConnector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@ public function __construct()
1414

1515
}
1616

17+
/**
18+
* @param int $attribute
19+
* @return bool
20+
*/
1721
public function getAttribute($attribute): bool
1822
{
1923
return false;
2024
}
2125

26+
/**
27+
* @param string $query
28+
* @return GravResultObject
29+
*/
2230
public function query($query)
2331
{
2432
$counter = 0;

classes/GravResultObject.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,25 @@
33

44
class GravResultObject
55
{
6+
/** @var array */
67
protected $items;
8+
/** @var int */
79
protected $counter;
810

11+
/**
12+
* GravResultObject constructor.
13+
* @param array $items
14+
*/
915
public function __construct($items)
1016
{
1117
$this->counter = 0;
1218
$this->items = $items;
1319
}
20+
21+
/**
22+
* @param array $options
23+
* @return array
24+
*/
1425
public function fetch($options)
1526
{
1627
return $this->items[$this->counter++];

classes/GravTNTSearch.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@
1818

1919
class GravTNTSearch
2020
{
21+
/** @var TNTSearch */
2122
public $tnt;
23+
/** @var array */
2224
protected $options;
25+
/** @var string[] */
2326
protected $bool_characters = ['-', '(', ')', 'or'];
27+
/** @var string */
2428
protected $index = 'grav.index';
29+
/** @var false|string */
2530
protected $language;
2631

2732
/**
@@ -78,7 +83,7 @@ public function __construct($options = [])
7883
}
7984

8085
/**
81-
* @param $query
86+
* @param string $query
8287
* @return object|string
8388
* @throws IndexNotFoundException
8489
*/
@@ -97,6 +102,7 @@ public function search($query)
97102
$limit = (int)$this->options['limit'];
98103
$type = $type ?? $this->options['search_type'];
99104

105+
// TODO: Multiword parameter has been removed from $tnt->search(), please check if this works
100106
$multiword = null;
101107
if (isset($this->options['phrases']) && $this->options['phrases']) {
102108
if (strlen($query) > 2) {
@@ -111,7 +117,7 @@ public function search($query)
111117

112118
switch ($type) {
113119
case 'basic':
114-
$results = $this->tnt->search($query, $limit, $multiword);
120+
$results = $this->tnt->search($query, $limit);
115121
break;
116122
case 'boolean':
117123
$results = $this->tnt->searchBoolean($query, $limit);
@@ -170,7 +176,7 @@ protected function processResults($res, $query)
170176
}
171177

172178
if ($this->options['json']) {
173-
return json_encode($data, JSON_PRETTY_PRINT);
179+
return json_encode($data, JSON_PRETTY_PRINT) ?: '';
174180
}
175181

176182
return $data;
@@ -193,14 +199,16 @@ public static function getCleanContent($page)
193199
$twig = $grav['twig'];
194200
$header = $page->header();
195201

202+
// @phpstan-ignore-next-line
196203
if (isset($header->tntsearch['template'])) {
197204
$processed_page = $twig->processTemplate($header->tntsearch['template'] . '.html.twig', ['page' => $page]);
198205
$content = $processed_page;
199206
} else {
200207
$content = $page->content();
201208
}
202209

203-
$content = preg_replace('/[ \t]+/', ' ', preg_replace('/\s*$^\s*/m', "\n", strip_tags($content)));
210+
$content = strip_tags($content);
211+
$content = preg_replace('/[ \t]+/', ' ', preg_replace('/\s*$^\s*/m', "\n", $content));
204212

205213
// Restore active page in Grav.
206214
unset($grav['page']);
@@ -209,6 +217,9 @@ public static function getCleanContent($page)
209217
return $content;
210218
}
211219

220+
/**
221+
* @return void
222+
*/
212223
public function createIndex()
213224
{
214225
$this->tnt->setDatabaseHandle(new GravConnector);
@@ -222,13 +233,18 @@ public function createIndex()
222233
$indexer->run();
223234
}
224235

236+
/**
237+
* @return void
238+
* @throws IndexNotFoundException
239+
*/
225240
public function selectIndex()
226241
{
227242
$this->tnt->selectIndex($this->index);
228243
}
229244

230245
/**
231246
* @param object $object
247+
* @return void
232248
*/
233249
public function deleteIndex($object)
234250
{
@@ -251,6 +267,7 @@ public function deleteIndex($object)
251267

252268
/**
253269
* @param object $object
270+
* @return void
254271
*/
255272
public function updateIndex($object)
256273
{
@@ -282,7 +299,8 @@ public function updateIndex($object)
282299
/** @var Collection $collection */
283300
$collection = $apage->collection($filter, false);
284301

285-
if (array_key_exists($object->path(), $collection->toArray())) {
302+
$path = $object->path();
303+
if ($path && array_key_exists($path, $collection->toArray())) {
286304
$fields = $this->indexPageData($object);
287305
$document = (array) $fields;
288306

cli/TNTSearchIndexerCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TNTSearchIndexerCommand extends ConsoleCommand
3131
];
3232

3333
/**
34-
*
34+
* @return void
3535
*/
3636
protected function configure()
3737
{
@@ -54,7 +54,7 @@ protected function configure()
5454
}
5555

5656
/**
57-
* @return int|null|void
57+
* @return void
5858
*/
5959
protected function serve()
6060
{

cli/TNTSearchQueryCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ class TNTSearchQueryCommand extends ConsoleCommand
3232
'EMERGENCY' => 'magenta'
3333
];
3434

35-
protected $tnt;
36-
3735
/**
38-
*
36+
* @return void
3937
*/
4038
protected function configure()
4139
{
@@ -58,7 +56,7 @@ protected function configure()
5856
}
5957

6058
/**
61-
* @return int|null|void
59+
* @return void
6260
*/
6361
protected function serve()
6462
{
@@ -69,6 +67,9 @@ protected function serve()
6967
$this->output->writeln('');
7068
}
7169

70+
/**
71+
* @return void
72+
*/
7273
private function doQuery()
7374
{
7475
$gtnt = TNTSearchPlugin::getSearchObjectType(['json' => true]);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "grav-plugin-tntsearch",
2+
"name": "trilbymedia/grav-plugin-tntsearch",
33
"type": "grav-plugin",
44
"description": "TNTSearch plugin for Grav CMS",
55
"keywords": ["tntsearch","search"],

composer.lock

Lines changed: 36 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)