Skip to content

Commit cb529b8

Browse files
committed
Merge branch 'release/3.0.0'
# Conflicts: # tntsearch.php
2 parents 69a5354 + 787d9d5 commit cb529b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+692
-279
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# v3.0.0
2+
## 04/14/2018
3+
4+
1. [](#new)
5+
* Added new Grav Scheduler integration
6+
* Added new Multi-Language Support
7+
1. [](#improved)
8+
* Switched to latest TNTSearch version 2.0 (PHP 7.1+)
9+
* Added a new `onFlexObjecSave()` event
10+
* Simplified indexing logic
11+
* Code cleanup
12+
* Minor CSS improvements for search field
13+
* Implemented a unified indexer process that always uses the CLI command for consistency
14+
* Use Grav YAML handler
15+
1. [](#bugfix)
16+
* Use custom search object in query [#63](https://github.com/trilbymedia/grav-plugin-tntsearch/issues/63)
17+
* Fixed issue with Ajax results escaping
18+
* Fixed issues when updating search index
19+
* Set the db index file as a property of `GravTNTSearch` to allow for better overriding
20+
* Put better type checking around `onTNTSearchIndex()` example that indexes `page.header.author`
21+
122
# v2.0.4
223
## 09/21/2018
324

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
The **TNTSearch** Plugin is for [Grav CMS](http://github.com/getgrav/grav). Powerful indexed-based full text search engine powered by the [TNTSearch library](https://github.com/teamtnt/tntsearch) that provides fast Ajax-based Grav content searches. This plugin is highly flexible allowing indexes of arbitrary content data as well as custom Twig templates to provide the opportunity to index modular and other dynamic page types. TNTSearch provides CLI as well as Admin based administration and re-indexing, as well as a built-in Ajax-powered front-end search tool.
44

5+
> NOTE: TNTSearch version 3.0.0 now requires Grav 1.6.0 or newer to function as it makes use of new functionality not available in previous versions.
6+
57
![](assets/tntsearch-ajax.gif)
68

79
## Installation
@@ -63,8 +65,10 @@ query_route: '/s'
6365
built_in_css: true
6466
built_in_js: true
6567
built_in_search_page: true
68+
enable_admin_page_events: true
6669
search_type: auto
6770
fuzzy: false
71+
phrases: true
6872
stemmer: default
6973
display_route: true
7074
display_hits: true
@@ -74,10 +78,15 @@ limit: 20
7478
min: 3
7579
snippet: 300
7680
index_page_by_default: true
81+
scheduled_index:
82+
enabled: false
83+
at: '0 */3 * * *'
84+
logs: 'logs/tntsearch-index.out'
7785
filter:
7886
items:
79-
taxonomy@:
80-
category: [news]
87+
88+
powered_by: true
89+
search_object_type: Grav
8190
```
8291
8392
The configuration options are as follows:
@@ -88,11 +97,13 @@ The configuration options are as follows:
8897
* `built_in_css` - enable or disable the built-in css styling
8998
* `built_in_js` - enable or disable the built-in javascript
9099
* `built_in_search_page` - enable or disable the built-in search page
100+
* `enable_admin_page_events` - enable or disable the page events which occur `on-save` to add/update/remove page in index
91101
* `search_type` - can be one of these types:
92102
* `basic` - standard string matching
93103
* `boolean` - supports `or` or `minus`. e.g. `foo -bar`
94104
* `auto` - automatically detects whether to use `basic` or `boolean`
95105
* `fuzzy` - matches if the words are 'close' but not necessarily exact matches
106+
* `phrases` - automatically handle phrases support
96107
* `stemmer` - can be one of these types:
97108
* `default` - no stemmer
98109
* `arabic` - Arabic language
@@ -109,7 +120,10 @@ The configuration options are as follows:
109120
* `min` - mininum amount of characters typed before performing search
110121
* `snippet` - amount of characters for previewing a result item
111122
* `index_page_by_default` - should all pages be indexed by default unless frontmatter overrides
123+
* `scheduled_index` - New scheduled index job. Disabled by default, when enabled defaulted to run every 3 hours, and output results to `logs/tntsearch-index.out`
112124
* `filter` - a [Page Collections filter](https://learn.getgrav.org/content/collections#summary-of-collection-options) that lets you pick specific pages to index via a collection query
125+
* `powered_by` - Display the **powered-by TNTSearch** text
126+
* `search_object_type` - Allows custom classes to override the default **Grav Page** support. This allows completely custom searching capabilities for any data type.
113127

114128
## Usage
115129

@@ -168,6 +182,20 @@ tntsearch:
168182
index: false
169183
```
170184

185+
#### Multi-Language Support
186+
187+
With the new 3.0 version of TNTSearch, support has been added for multiple languages (Grav 1.6 required). Internally, this means that rather that store the index as `user:://data/tntsearch/grav.index`, multiple indexes are created per language configured in Grav. For example if you have set the supported languages to `['en', 'fr', 'de']`, then when you perform an index, you will get three files: `en.index`, `fr.index`, and `de.index`. When querying the appropriate **active language** determines which index is queried. For example, performing the search on a page called `/fr/search` will result in the `fr.index` database to be used, and French results to be returned.
188+
189+
Note Indexing will take longer depending on the number of languages you support as TNTSearch has to index each page in each language.
190+
191+
> NOTE: While accented characters is supported in this release, there is currently no support in the underlying TNTSearch library to match non-accented characters to accented ones, so exact matches are required.
192+
193+
#### Scheduler Support
194+
195+
One of the great new features of Grav 1.6 is the built in **Scheduler** that allows plugin-provided functionality to be run periodically. TNTSearch is a great use-case for this capability as it allows an indexing job to be scheduled to be run every few hours without the need to manually keep things in sync. There are a few options that allow you to configure this capability.
196+
197+
First note, that this scheduler functionality is disable by default, so you first have to enable the scheduler functionality in the TNTSearch plugin settings. After that you can configure how often the indexing job should run. The default is every 3 hours. Lastly, you can configure where any indexing output is logged to.
198+
171199
#### Admin Page CrUD Events
172200

173201
Once you have an index, TNTSearch makes use of admin events to **C**reate, **U**pdate, and **D**elete index entries when you edit pages. If your index ever looks like it's out of sync, you can simply reindex your whole site.

assets/tntsearch.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
.tntsearch-form .form-input {
2+
height: 2.4rem;
3+
padding-left: 1rem;
4+
}
5+
16
#tntsearch-wrapper {
27
position: relative;
38
}

blueprints.yaml

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: TNT Search
2-
version: 2.0.4
2+
version: 3.0.0
3+
testing: false
34
description: Powerful indexed-based full text search engine powered by TNTSearch
45
icon: binoculars
56
author:
@@ -12,7 +13,7 @@ docs: https://github.com/trilbymedia/grav-plugin-tntsearch/blob/develop/README.m
1213
license: MIT
1314

1415
dependencies:
15-
- { name: grav, version: '>=1.3.2' }
16+
- { name: grav, version: '>=1.6.3' }
1617

1718
form:
1819
validation: strict
@@ -30,13 +31,18 @@ form:
3031
validate:
3132
type: bool
3233

34+
index_title:
35+
type: spacer
36+
title: Indexer Settings
37+
3338
index_status:
3439
type: indexstatus
3540
label: Search Index Status
3641

37-
built_in_css:
42+
enable_admin_page_events:
3843
type: toggle
39-
label: Built-in CSS
44+
label: Enable Admin Page Events
45+
help: Disable this if you are having problems with timeouts during page saving
4046
highlight: 1
4147
default: 1
4248
options:
@@ -45,9 +51,39 @@ form:
4551
validate:
4652
type: bool
4753

48-
built_in_js:
54+
scheduled_index.enabled:
4955
type: toggle
50-
label: Built-in Javascript
56+
label: Enable Index Scheduled Job
57+
help: Use the Grav Scheduler to kick off a background index job
58+
highlight: 0
59+
default: 0
60+
options:
61+
1: Enabled
62+
0: Disabled
63+
validate:
64+
type: bool
65+
66+
scheduled_index.at:
67+
type: cron
68+
label: Scheduled Job Frequency
69+
size: medium
70+
help: Use 'cron' format
71+
default: '0 */3 * * *'
72+
placeholder: '0 */3 * * *'
73+
74+
scheduled_index.logs:
75+
type: text
76+
label: Scheduled Job Log File
77+
placeholder: 'logs/tntsearch-index.out'
78+
size: medium
79+
80+
ui_title:
81+
type: spacer
82+
title: UI Settings
83+
84+
built_in_css:
85+
type: toggle
86+
label: Built-in CSS
5187
highlight: 1
5288
default: 1
5389
options:
@@ -56,9 +92,9 @@ form:
5692
validate:
5793
type: bool
5894

59-
built_in_search_page:
95+
built_in_js:
6096
type: toggle
61-
label: Built-in Search Page
97+
label: Built-in Javascript
6298
highlight: 1
6399
default: 1
64100
options:
@@ -67,10 +103,13 @@ form:
67103
validate:
68104
type: bool
69105

70-
enable_admin_page_events:
106+
search_title:
107+
type: spacer
108+
title: Search Settings
109+
110+
built_in_search_page:
71111
type: toggle
72-
label: Enable Admin Page Events
73-
help: Disable this if you are having problems with timeouts during page saving
112+
label: Built-in Search Page
74113
highlight: 1
75114
default: 1
76115
options:
@@ -79,6 +118,8 @@ form:
79118
validate:
80119
type: bool
81120

121+
122+
82123
search_route:
83124
type: text
84125
size: medium
@@ -202,7 +243,7 @@ form:
202243
index_page_by_default:
203244
type: toggle
204245
label: Index Every Page
205-
help: Index every page by default unless a page specifically declares `tntsearch: process: false`. Disabling this requires a `process: true` declartion to be added to each page that should be indexed.
246+
help: 'Index every page by default unless a page specifically declares `tntsearch: process: false`. Disabling this requires a `process: true` declartion to be added to each page that should be indexed.'
206247
highlight: 1
207248
default: 1
208249
options:

classes/GravConnector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
namespace Grav\Plugin\TNTSearch;
33

44
use Grav\Common\Grav;
5+
use Grav\Common\Yaml;
56
use Grav\Common\Page\Page;
6-
use Symfony\Component\Yaml\Yaml;
77

88
class GravConnector extends \PDO
99
{
@@ -25,8 +25,7 @@ public function query($query)
2525
$config = Grav::instance()['config'];
2626
$filter = $config->get('plugins.tntsearch.filter');
2727
$default_process = $config->get('plugins.tntsearch.index_page_by_default');
28-
$gtnt = new GravTNTSearch();
29-
28+
$gtnt = \Grav\Plugin\TNTSearchPlugin::getSearchObjectType();
3029

3130

3231
if ($filter && array_key_exists('items', $filter)) {
@@ -61,7 +60,8 @@ public function query($query)
6160
try {
6261
$fields = $gtnt->indexPageData($page);
6362
$results[] = (array) $fields;
64-
echo("Added $counter $route\n");
63+
$display_route = isset($fields->display_route) ? $fields->display_route : $route;
64+
echo("Added $counter $display_route\n");
6565
} catch (\Exception $e) {
6666
echo("Skipped $counter $route - {$e->getMessage()}\n");
6767
continue;

classes/GravTNTSearch.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
namespace Grav\Plugin\TNTSearch;
33

44
use Grav\Common\Grav;
5+
use Grav\Common\Language\Language;
6+
use Grav\Common\Yaml;
57
use Grav\Common\Page\Collection;
68
use Grav\Common\Page\Page;
79
use RocketTheme\Toolbox\Event\Event;
8-
use Symfony\Component\Yaml\Yaml;
910
use TeamTNT\TNTSearch\Exceptions\IndexNotFoundException;
1011
use TeamTNT\TNTSearch\TNTSearch;
1112

@@ -15,6 +16,7 @@ class GravTNTSearch
1516
protected $options;
1617
protected $bool_characters = ['-', '(', ')', 'or'];
1718
protected $index = 'grav.index';
19+
protected $language;
1820

1921
public function __construct($options = [])
2022
{
@@ -24,6 +26,15 @@ public function __construct($options = [])
2426
$snippet = Grav::instance()['config']->get('plugins.tntsearch.snippet', 300);
2527
$data_path = Grav::instance()['locator']->findResource('user://data', true) . '/tntsearch';
2628

29+
/** @var Language $language */
30+
$language = Grav::instance()['language'];
31+
32+
if ($language->enabled()) {
33+
$active = $language->getActive();
34+
$default = $language->getDefault();
35+
$this->language = $active ? $active : $default;
36+
$this->index = $this->language . '.index';
37+
}
2738

2839
if (!file_exists($data_path)) {
2940
mkdir($data_path);
@@ -44,6 +55,7 @@ public function __construct($options = [])
4455
$this->tnt->loadConfig([
4556
"storage" => $data_path,
4657
"driver" => 'sqlite',
58+
'charset' => 'utf8'
4759
]);
4860
}
4961

@@ -131,7 +143,7 @@ public static function getCleanContent($page)
131143

132144
if (isset($header->tntsearch['template'])) {
133145
$processed_page = $twig->processTemplate($header->tntsearch['template'] . '.html.twig', ['page' => $page]);
134-
$content =$processed_page;
146+
$content = $processed_page;
135147
} else {
136148
$content = $page->content();
137149
}
@@ -232,11 +244,17 @@ public function indexPageData($page)
232244
throw new \RuntimeException('redirect only...');
233245
}
234246

247+
$route = $page->route();
248+
235249
$fields = new \stdClass();
236-
$fields->id = $page->route();
250+
$fields->id = $route;
237251
$fields->name = $page->title();
238252
$fields->content = $this->getCleanContent($page);
239253

254+
if ($this->language) {
255+
$fields->display_route = '/' . $this->language . $route;
256+
}
257+
240258
Grav::instance()->fireEvent('onTNTSearchIndex', new Event(['page' => $page, 'fields' => $fields]));
241259

242260
return $fields;

0 commit comments

Comments
 (0)