Skip to content

Commit

Permalink
Merge branch 'release/3.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Dec 2, 2020
2 parents 75e382b + f001ae1 commit 8897097
Show file tree
Hide file tree
Showing 37 changed files with 648 additions and 183 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# v3.3.0
## 12/02/2020

1. [](#new)
* Upgraded to TNTSearch version 2.5
* Pass phpstan level 7 tests
1. [](#bugfix)
* Fixed FlexPages events for add+delete
* Fixed running scheduled index job [#104](https://github.com/trilbymedia/grav-plugin-tntsearch/pull/104)

# v3.2.1
## 09/04/2020

Expand Down
4 changes: 2 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: TNT Search
slug: tntsearch
type: plugin
version: 3.2.1
slug: tntsearch
version: 3.3.0
testing: false
description: Powerful indexed-based full text search engine powered by TNTSearch
icon: binoculars
Expand Down
8 changes: 8 additions & 0 deletions classes/GravConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ public function __construct()

}

/**
* @param int $attribute
* @return bool
*/
public function getAttribute($attribute): bool
{
return false;
}

/**
* @param string $query
* @return GravResultObject
*/
public function query($query)
{
$counter = 0;
Expand Down
11 changes: 11 additions & 0 deletions classes/GravResultObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@

class GravResultObject
{
/** @var array */
protected $items;
/** @var int */
protected $counter;

/**
* GravResultObject constructor.
* @param array $items
*/
public function __construct($items)
{
$this->counter = 0;
$this->items = $items;
}

/**
* @param array $options
* @return array
*/
public function fetch($options)
{
return $this->items[$this->counter++];
Expand Down
28 changes: 23 additions & 5 deletions classes/GravTNTSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@

class GravTNTSearch
{
/** @var TNTSearch */
public $tnt;
/** @var array */
protected $options;
/** @var string[] */
protected $bool_characters = ['-', '(', ')', 'or'];
/** @var string */
protected $index = 'grav.index';
/** @var false|string */
protected $language;

/**
Expand Down Expand Up @@ -78,7 +83,7 @@ public function __construct($options = [])
}

/**
* @param $query
* @param string $query
* @return object|string
* @throws IndexNotFoundException
*/
Expand All @@ -97,6 +102,7 @@ public function search($query)
$limit = (int)$this->options['limit'];
$type = $type ?? $this->options['search_type'];

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

switch ($type) {
case 'basic':
$results = $this->tnt->search($query, $limit, $multiword);
$results = $this->tnt->search($query, $limit);
break;
case 'boolean':
$results = $this->tnt->searchBoolean($query, $limit);
Expand Down Expand Up @@ -170,7 +176,7 @@ protected function processResults($res, $query)
}

if ($this->options['json']) {
return json_encode($data, JSON_PRETTY_PRINT);
return json_encode($data, JSON_PRETTY_PRINT) ?: '';
}

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

// @phpstan-ignore-next-line
if (isset($header->tntsearch['template'])) {
$processed_page = $twig->processTemplate($header->tntsearch['template'] . '.html.twig', ['page' => $page]);
$content = $processed_page;
} else {
$content = $page->content();
}

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

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

/**
* @return void
*/
public function createIndex()
{
$this->tnt->setDatabaseHandle(new GravConnector);
Expand All @@ -222,13 +233,18 @@ public function createIndex()
$indexer->run();
}

/**
* @return void
* @throws IndexNotFoundException
*/
public function selectIndex()
{
$this->tnt->selectIndex($this->index);
}

/**
* @param object $object
* @return void
*/
public function deleteIndex($object)
{
Expand All @@ -251,6 +267,7 @@ public function deleteIndex($object)

/**
* @param object $object
* @return void
*/
public function updateIndex($object)
{
Expand Down Expand Up @@ -282,7 +299,8 @@ public function updateIndex($object)
/** @var Collection $collection */
$collection = $apage->collection($filter, false);

if (array_key_exists($object->path(), $collection->toArray())) {
$path = $object->path();
if ($path && array_key_exists($path, $collection->toArray())) {
$fields = $this->indexPageData($object);
$document = (array) $fields;

Expand Down
4 changes: 2 additions & 2 deletions cli/TNTSearchIndexerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TNTSearchIndexerCommand extends ConsoleCommand
];

/**
*
* @return void
*/
protected function configure()
{
Expand All @@ -54,7 +54,7 @@ protected function configure()
}

/**
* @return int|null|void
* @return void
*/
protected function serve()
{
Expand Down
9 changes: 5 additions & 4 deletions cli/TNTSearchQueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class TNTSearchQueryCommand extends ConsoleCommand
'EMERGENCY' => 'magenta'
];

protected $tnt;

/**
*
* @return void
*/
protected function configure()
{
Expand All @@ -58,7 +56,7 @@ protected function configure()
}

/**
* @return int|null|void
* @return void
*/
protected function serve()
{
Expand All @@ -69,6 +67,9 @@ protected function serve()
$this->output->writeln('');
}

/**
* @return void
*/
private function doQuery()
{
$gtnt = TNTSearchPlugin::getSearchObjectType(['json' => true]);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "grav-plugin-tntsearch",
"name": "trilbymedia/grav-plugin-tntsearch",
"type": "grav-plugin",
"description": "TNTSearch plugin for Grav CMS",
"keywords": ["tntsearch","search"],
Expand Down
44 changes: 36 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8897097

Please sign in to comment.