Skip to content

Commit c58137b

Browse files
committed
Fix and minor rework
1 parent 7186316 commit c58137b

21 files changed

+17
-168
lines changed

Config/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<language>en_US</language>
1414
<language>fr_FR</language>
1515
</languages>
16-
<version>2.1.1</version>
16+
<version>2.1.2</version>
1717
<authors>
1818
<author>
1919
<name>Nicolas Barbey</name>

Controller/Front/SearchOpenApiController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function apiSearch(Search $search, Request $request, ModelFactory $modelF
8181
continue;
8282
}
8383

84-
$model = $search->buildPropelModelFromIndex($index);
84+
$model = $search->buildPropelQueryFromIndex($index);
8585
$modelTableMap = $search->buildPropelTableMapFromIndex($index);
8686

8787
$rows = $model->filterById($ids, Criteria::IN);

EventListener/IndexUpdateListener.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function updateCustomerIndex(CustomerEvent $event): void
7171
*/
7272
public function updateProductIndex(ProductEvent $event): void
7373
{
74-
if ($event->hasProduct()) {
74+
if ($event->getProduct()) {
7575
$deleteMode = $event instanceof ProductDeleteEvent;
7676

7777
$this->itemIndexation->deleteItemOnIndexes($event->getProduct()->getId(), 'product');
@@ -88,7 +88,7 @@ public function updateProductIndex(ProductEvent $event): void
8888
*/
8989
public function updateCategoryIndex(CategoryEvent $event): void
9090
{
91-
if ($event->hasCategory()) {
91+
if ($event->getCategory()) {
9292
$deleteMode = $event instanceof CategoryDeleteEvent;
9393

9494
$this->itemIndexation->deleteItemOnIndexes($event->getCategory()->getId(), 'category');
@@ -105,7 +105,7 @@ public function updateCategoryIndex(CategoryEvent $event): void
105105
*/
106106
public function updateFolderIndex(FolderEvent $event): void
107107
{
108-
if ($event->hasFolder()) {
108+
if ($event->getFolder()) {
109109
$deleteMode = $event instanceof FolderDeleteEvent;
110110

111111
$this->itemIndexation->deleteItemOnIndexes($event->getFolder()->getId(), 'folder');
@@ -122,7 +122,7 @@ public function updateFolderIndex(FolderEvent $event): void
122122
*/
123123
public function updateContentIndex(ContentEvent $event): void
124124
{
125-
if ($event->hasContent()) {
125+
if ($event->getContent()) {
126126
$deleteMode = $event instanceof ContentDeleteEvent;
127127

128128
$this->itemIndexation->deleteItemOnIndexes($event->getContent()->getId(), 'content');

Index/BaseIndex.php

+1-24
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,19 @@ abstract class BaseIndex implements TntSearchIndexInterface
1818
public function __construct(
1919
protected EventDispatcherInterface $disptacher,
2020
protected TntSearchProvider $tntSearchProvider
21-
)
22-
{
23-
24-
}
21+
) {}
2522

26-
/**
27-
* @return string
28-
*/
2923
public function getTokenizer(): string
3024
{
3125
return Tokenizer::class;
3226
}
3327

34-
/**
35-
* @return string
36-
*/
3728
public function getIndexName(): string
3829
{
3930
$reflectionClass = new ReflectionClass(get_called_class());
4031
return strtolower($reflectionClass->getShortName());
4132
}
4233

43-
/**
44-
* @param string|null $locale
45-
* @return string
46-
*/
4734
public function getIndexFileName(string $locale = null): string
4835
{
4936
$indexName = $this->getIndexName();
@@ -56,9 +43,6 @@ public function getIndexFileName(string $locale = null): string
5643
return $indexFileName;
5744
}
5845

59-
/**
60-
* @return void
61-
*/
6246
public function index(): void
6347
{
6448
if (!$this->isTranslatable()) {
@@ -69,10 +53,6 @@ public function index(): void
6953
$this->indexTranslatableIndexes();
7054
}
7155

72-
/**
73-
* @param string|null $locale
74-
* @return void
75-
*/
7656
protected function indexOneIndex(string $locale = null): void
7757
{
7858
$indexFileName = $this->getIndexFileName($locale);
@@ -102,9 +82,6 @@ protected function indexOneIndex(string $locale = null): void
10282
}
10383
}
10484

105-
/**
106-
* @return void
107-
*/
10885
protected function indexTranslatableIndexes(): void
10986
{
11087
$langs = LangQuery::create()

Index/Brand.php

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ public function isTranslatable(): bool
99
return true;
1010
}
1111

12-
/**
13-
* @param int|null $itemId
14-
* @param string|null $locale
15-
* @return string
16-
*/
1712
public function buildSqlQuery(int $itemId = null, string $locale = null): string
1813
{
1914
return '

Index/Category.php

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ public function isTranslatable(): bool
99
return true;
1010
}
1111

12-
/**
13-
* @param int|null $itemId
14-
* @param string|null $locale
15-
* @return string
16-
*/
1712
public function buildSqlQuery(int $itemId = null, string $locale = null): string
1813
{
1914
return '

Index/Content.php

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ public function isTranslatable(): bool
99
return true;
1010
}
1111

12-
/**
13-
* @param int|null $itemId
14-
* @param string|null $locale
15-
* @return string
16-
*/
1712
public function buildSqlQuery(int $itemId = null, string $locale = null): string
1813
{
1914
return '

Index/Customer.php

-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ public function getTokenizer(): string
1414
return \TntSearch\Tokenizer\CustomerTokenizer::class;
1515
}
1616

17-
/**
18-
* @param int|null $itemId
19-
* @param string|null $locale
20-
* @return string
21-
*/
2217
public function buildSqlQuery(int $itemId = null, string $locale = null): string
2318
{
2419
return '

Index/Folder.php

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ public function isTranslatable(): bool
99
return true;
1010
}
1111

12-
/**
13-
* @param int|null $itemId
14-
* @param string|null $locale
15-
* @return string
16-
*/
1712
public function buildSqlQuery(int $itemId = null, string $locale = null): string
1813
{
1914
return '

Index/Order.php

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ public function isTranslatable(): bool
99
return false;
1010
}
1111

12-
/**
13-
* @param int|null $itemId
14-
* @param string|null $locale
15-
* @return string
16-
*/
1712
public function buildSqlQuery(int $itemId = null, string $locale = null): string
1813
{
1914
return '

Index/Product.php

-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ public function isTranslatable(): bool
1313
return true;
1414
}
1515

16-
/**
17-
* @param int|null $itemId
18-
* @param string|null $locale
19-
* @return string
20-
*/
2116
public function buildSqlQuery(int $itemId = null, string $locale = null): string
2217
{
2318
if (!$locale && $this->isTranslatable()) {

Index/TntSearchIndexInterface.php

-9
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,9 @@
66

77
interface TntSearchIndexInterface
88
{
9-
/** @return bool */
109
public function isTranslatable(): bool;
1110

12-
/**
13-
* @return void
14-
*/
1511
public function index(): void;
1612

17-
/**
18-
* @param int|null $itemId
19-
* @param string|null $locale
20-
* @return string
21-
*/
2213
public function buildSqlQuery(int $itemId = null, string $locale = null): string;
2314
}

Loop/SearchLoop.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function buildArray(): array
5151
if (!$locale = $this->getLocale()) {
5252
$locale = $session->getLang()->getLocale();
5353
if ($this->getBackendContext()) {
54-
$locale = $session->getAdminEditionLang()->getLocale();
54+
$locale = $session->getAdminLang()->getLocale();
5555
}
5656
}
5757

Service/ItemIndexation.php

+1-14
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,8 @@ public function __construct(
2020
protected IndexationProvider $indexationProvider,
2121
protected TntSearchProvider $tntSearchProvider,
2222
protected EventDispatcherInterface $dispatcher
23-
)
24-
{
25-
}
23+
) {}
2624

27-
/**
28-
* @param int $itemId
29-
* @param string $itemIndexType
30-
* @return void
31-
*/
3225
public function indexOneItemOnIndexes(int $itemId, string $itemIndexType): void
3326
{
3427
$index = $this->indexationProvider->getIndex($itemIndexType);
@@ -57,11 +50,6 @@ public function indexOneItemOnIndexes(int $itemId, string $itemIndexType): void
5750
}
5851
}
5952

60-
/**
61-
* @param int $itemId
62-
* @param string $itemIndexType
63-
* @return void
64-
*/
6553
public function deleteItemOnIndexes(int $itemId, string $itemIndexType): void
6654
{
6755
$index = $this->indexationProvider->getIndex($itemIndexType);
@@ -72,7 +60,6 @@ public function deleteItemOnIndexes(int $itemId, string $itemIndexType): void
7260
}
7361

7462
/**
75-
* @param TntSearchIndexInterface $index
7663
* @return TNTIndexer[]
7764
*/
7865
public function buildTNTIndexers(TntSearchIndexInterface $index): array

Service/Provider/IndexationProvider.php

-10
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class IndexationProvider
1212
protected array $indexes;
1313

1414
/**
15-
* @param $index
16-
* @return void
1715
* @throws ReflectionException
1816
*/
1917
public function addIndex($index): void
@@ -24,20 +22,13 @@ public function addIndex($index): void
2422
$this->indexes[$indexType] = $index;
2523
}
2624

27-
/**
28-
* @return void
29-
*/
3025
public function indexAll(): void
3126
{
3227
foreach ($this->indexes as $index) {
3328
$index->index();
3429
}
3530
}
3631

37-
/**
38-
* @param string $indexType
39-
* @return TntSearchIndexInterface
40-
*/
4132
public function getIndex(string $indexType): TntSearchIndexInterface
4233
{
4334
return $this->indexes[$indexType];
@@ -52,7 +43,6 @@ public function getIndexes(): array
5243
}
5344

5445
/**
55-
* @param array $indexTypes
5646
* @return TntSearchIndexInterface[]
5747
*/
5848
public function findIndexes(array $indexTypes): array

Service/Provider/TntSearchProvider.php

+3-16
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,13 @@
99

1010
class TntSearchProvider
1111
{
12-
/** @var string */
1312
const INDEXES_DIR = THELIA_LOCAL_DIR . "TNTIndexes";
1413

1514
public function __construct(
1615
protected Stemmer $stemmer,
1716
protected StopWord $stopWord
18-
)
19-
{
20-
}
17+
) {}
2118

22-
/**
23-
* @param string|null $locale
24-
* @param string|null $tokenizer
25-
* @return TntSearch
26-
*/
2719
public function getTntSearch(string $tokenizer = null , string $locale = null): TntSearch
2820
{
2921
return $this->buildTntSearch(
@@ -33,12 +25,6 @@ public function getTntSearch(string $tokenizer = null , string $locale = null):
3325
);
3426
}
3527

36-
/**
37-
* @param string $stemmer
38-
* @param array $stopWords
39-
* @param string|null $tokenizer
40-
* @return TntSearch
41-
*/
4228
public function buildTntSearch(string $stemmer, array $stopWords = [], string $tokenizer = null): TntSearch
4329
{
4430
if (!is_dir(self::INDEXES_DIR)) {
@@ -51,7 +37,8 @@ public function buildTntSearch(string $stemmer, array $stopWords = [], string $t
5137
'storage' => self::INDEXES_DIR,
5238
'modes' => [''],
5339
'stemmer' => $stemmer,
54-
'tokenizer' => $tokenizer
40+
'tokenizer' => $tokenizer,
41+
'driver' => ''
5542
]);
5643

5744
$tnt = new TntSearch($config);

Service/Search.php

+2-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Exception;
66
use Propel\Runtime\ActiveQuery\ModelCriteria;
7-
use Propel\Runtime\Map\TableMap;
87
use TeamTNT\TNTSearch\Exceptions\IndexNotFoundException;
98
use Thelia\Log\Tlog;
109
use TntSearch\Service\Provider\IndexationProvider;
@@ -15,18 +14,8 @@ class Search
1514
public function __construct(
1615
protected IndexationProvider $indexationProvider,
1716
protected TntSearchProvider $tntSearchProvider
18-
)
19-
{
20-
}
17+
) {}
2118

22-
/**
23-
* @param string $searchWords
24-
* @param ?array $indexes
25-
* @param ?string $locale
26-
* @param ?int $offset
27-
* @param ?int $limit
28-
* @return array
29-
*/
3019
public function search(
3120
string $searchWords,
3221
?array $indexes,
@@ -67,7 +56,7 @@ public function search(
6756
return $result;
6857
}
6958

70-
public function buildPropelModelFromIndex(string $indexName): ModelCriteria
59+
public function buildPropelQueryFromIndex(string $indexName): ModelCriteria
7160
{
7261
/** @var ModelCriteria $modelQuery */
7362
$modelQuery = 'Thelia\\Model\\'.ucwords($indexName) . 'Query';

0 commit comments

Comments
 (0)