Skip to content

Commit

Permalink
Merge branch 'release/3.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Feb 25, 2021
2 parents 8897097 + 9723759 commit f28ca5d
Show file tree
Hide file tree
Showing 20 changed files with 245 additions and 102 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
# v3.3.1
## 02/25/2021

1. [](#improved)
* Upgraded to TNTSearch version `2.6.0`
* Added German (de) language [#103](https://github.com/trilbymedia/grav-plugin-tntsearch/pull/103)
1. [](#bugfix)
* Fixed `query` truncation when containing a hash (`#`) and preventing proper search results [#110](https://github.com/trilbymedia/grav-plugin-tntsearch/pull/110)
* Fixed `q` query parameter not working [#111](https://github.com/trilbymedia/grav-plugin-tntsearch/pull/111)
* Fix default stemmer and description [#105](https://github.com/trilbymedia/grav-plugin-tntsearch/pull/105)
* Fixed PHP 8 compatibility issues

# v3.3.0
## 12/02/2020

1. [](#new)
* Upgraded to TNTSearch version 2.5
1. [](#improved)
* Upgraded to TNTSearch version `2.5.0`
* Pass phpstan level 7 tests
1. [](#bugfix)
* Fixed FlexPages events for add+delete
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ The configuration options are as follows:
* `fuzzy` - matches if the words are 'close' but not necessarily exact matches
* `phrases` - automatically handle phrases support
* `stemmer` - can be one of these types:
* `default` - no stemmer
* `default` - Porter stemmer for English language
* `no` - no stemmer
* `arabic` - Arabic language
* `german` - German language
* `italian` - Italian language
* `porter` - Porter language
* `porter` - Porter stemmer for English language
* `russian` - Russian language
* `ukrainian` - Ukrainian language
* `display_route` - display the route in the search results
Expand Down Expand Up @@ -236,11 +237,11 @@ For example, say we have a homepage that is built from a few modular sub-pages w
```twig
{% for module in page.collection() %}
<p>
{{ module.content }}
{{ module.content|raw }}
</p>
{% endfor %}
{{ page.content }}
{{ page.content|raw }}
```

As you can see this simply ensures the module pages as defined in the page's collection are displayed, then the actual page content is displayed.
Expand Down
2 changes: 1 addition & 1 deletion app/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const throttling = throttle(async ({ input, results, historyValue = false } = {}
}

const params = {
q: value,
q: encodeURIComponent(value),
l: data.limit,
sl: data.snippet,
search_type: data.search_type,
Expand Down
2 changes: 1 addition & 1 deletion assets/tntsearch.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: TNT Search
type: plugin
slug: tntsearch
version: 3.3.0
version: 3.3.1
testing: false
description: Powerful indexed-based full text search engine powered by TNTSearch
icon: binoculars
Expand Down Expand Up @@ -173,13 +173,14 @@ form:
size: small
classes: fancy
label: Stemmer
help: An automated process which produces a base string in an attempt to represent related words
help: An automated process which produces a base string in an attempt to represent related words. If your content is not in the language listed, for best search results it is recommended to disable the stemmer.
options:
default: Default
default: Default (English)
no: Disabled
arabic: Arabic
porter: English
german: German
italian: Italian
porter: Porter
russian: Russian
ukrainian: Ukrainian

Expand Down
12 changes: 7 additions & 5 deletions classes/GravConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
use Grav\Common\Yaml;
use Grav\Common\Page\Page;
use Grav\Plugin\TNTSearchPlugin;
use PDO;

class GravConnector extends \PDO
class GravConnector extends PDO
{
public function __construct()
{

}

/**
Expand All @@ -23,11 +23,13 @@ public function getAttribute($attribute): bool
return false;
}

/**
* @param string $query
/***
* @param string $statement
* @param int|null $fetch_style
* @param mixed ...$extra
* @return GravResultObject
*/
public function query($query)
public function query(string $statement, ?int $fetch_style = null, ...$extra): GravResultObject
{
$counter = 0;
$results = [];
Expand Down
2 changes: 1 addition & 1 deletion classes/GravTNTSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static function getCleanContent($page)
}

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

// Restore active page in Grav.
unset($grav['page']);
Expand Down
17 changes: 8 additions & 9 deletions cli/TNTSearchIndexerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@
*/
class TNTSearchIndexerCommand extends ConsoleCommand
{
/**
* @var array
*/
/** @var array */
protected $options = [];
/**
* @var array
*/
/** @var array */
protected $colors = [
'DEBUG' => 'green',
'INFO' => 'cyan',
Expand All @@ -33,7 +29,7 @@ class TNTSearchIndexerCommand extends ConsoleCommand
/**
* @return void
*/
protected function configure()
protected function configure(): void
{
$this
->setName('index')
Expand All @@ -54,10 +50,11 @@ protected function configure()
}

/**
* @return void
* @return int
*/
protected function serve()
protected function serve(): int
{
/** @var string|null $langCode */
$langCode = $this->input->getOption('language');

error_reporting(1);
Expand All @@ -82,6 +79,8 @@ protected function serve()
$this->output->writeln('');
$this->output->writeln('Indexed in ' . $end . 's');
}

return 0;
}

/**
Expand Down
35 changes: 15 additions & 20 deletions cli/TNTSearchQueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@
*/
class TNTSearchQueryCommand extends ConsoleCommand
{
/**
* @var array
*/
/** @var array */
protected $options = [];

/**
* @var array
*/
/** @var array */
protected $colors = [
'DEBUG' => 'green',
'INFO' => 'cyan',
Expand Down Expand Up @@ -56,24 +51,24 @@ protected function configure()
}

/**
* @return void
* @return int
*/
protected function serve()
protected function serve(): int
{
$this->setLanguage($this->input->getOption('language'));
$this->initializePages();
/** @var string|null $langCode */
$langCode = $this->input->getOption('language');
/** @var string $query */
$query = $this->input->getArgument('query');

$this->doQuery();
$this->output->writeln('');
}
$this->setLanguage($langCode);
$this->initializePages();

/**
* @return void
*/
private function doQuery()
{
$gtnt = TNTSearchPlugin::getSearchObjectType(['json' => true]);
print_r($gtnt->search($this->input->getArgument('query')));
print_r($gtnt->search($query));

$this->output->newLine();

return 0;
}
}

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"require": {
"php": ">=7.1.3",
"ext-json": "*",
"ext-pdo": "*",
"teamtnt/tntsearch": "^2.0"
},
"autoload": {
Expand Down
19 changes: 10 additions & 9 deletions composer.lock

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

7 changes: 6 additions & 1 deletion languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ en:
FOUND_RESULTS: "Found %s results"
FOUND_IN: "in <span>%s</span>"
POWERED_BY: "Powered by %s"
de:
PLUGIN_TNTSEARCH:
FOUND_RESULTS: "Es wurden %s Resultate gefunden"
FOUND_IN: "(<span>%s</span>)"
POWERED_BY: "Powered by %s"
ru:
PLUGIN_TNTSEARCH:
FOUND_RESULTS: "Результатов: %s"
FOUND_IN: "(<span>%s</span>)"
POWERED_BY: "Работает на %s"
POWERED_BY: "Работает на %s"
2 changes: 1 addition & 1 deletion tntsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function onPagesInitialized(): void
}
}

$this->query = (string)($uri->param('q', null) ?? $uri->query('q') ?: '');
$this->query = (string)($uri->param('q', null) ?: $uri->query('q') ?: '');

if ($this->query) {
$snippet = $this->getFormValue('sl');
Expand Down
32 changes: 32 additions & 0 deletions vendor/composer/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
*/
class ClassLoader
{
private $vendorDir;

// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
Expand All @@ -57,6 +59,13 @@ class ClassLoader
private $missingClasses = array();
private $apcuPrefix;

private static $registeredLoaders = array();

public function __construct($vendorDir = null)
{
$this->vendorDir = $vendorDir;
}

public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
Expand Down Expand Up @@ -300,6 +309,15 @@ public function getApcuPrefix()
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);

if (null === $this->vendorDir) {
//no-op
} elseif ($prepend) {
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
} else {
unset(self::$registeredLoaders[$this->vendorDir]);
self::$registeredLoaders[$this->vendorDir] = $this;
}
}

/**
Expand All @@ -308,6 +326,10 @@ public function register($prepend = false)
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));

if (null !== $this->vendorDir) {
unset(self::$registeredLoaders[$this->vendorDir]);
}
}

/**
Expand Down Expand Up @@ -367,6 +389,16 @@ public function findFile($class)
return $file;
}

/**
* Returns the currently registered loaders indexed by their corresponding vendor directories.
*
* @return self[]
*/
public static function getRegisteredLoaders()
{
return self::$registeredLoaders;
}

private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
Expand Down
Loading

0 comments on commit f28ca5d

Please sign in to comment.