Skip to content

Commit a41666d

Browse files
64knlthessakockelkornThessa Kockelkorn
authored
feat: Version 0.20.0 (#228)
* chore: update requirements * feat: site url and clear option for indexer (#227) * feat: use full url if site domain is given * chore: add clear option --------- Co-authored-by: Thessa Kockelkorn <[email protected]> * fix: rename command to fresh * chore: rename clean => fresh * feat: allow document paths (#229) * fix: allow more file paths * feat: show file error in console * style: formatting * feat: tags in overview (#231) * fix: solr accents (#232) * fix: remove double encoding * fix: exclude from search --------- Co-authored-by: thessakockelkorn <[email protected]> Co-authored-by: Thessa Kockelkorn <[email protected]>
1 parent e630517 commit a41666d

File tree

9 files changed

+58
-29
lines changed

9 files changed

+58
-29
lines changed

composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
"spatie/laravel-honeypot": "^4.3.2",
2121
"illuminate/contracts": "^10.0|^11.0",
2222
"notfoundnl/siteboss-layout": "^1.6.1",
23-
"notfoundnl/siteboss-static": "^1.13",
23+
"notfoundnl/siteboss-static": "^1.15.0",
2424
"mcamara/laravel-localization": "^2.0",
2525
"xenolope/quahog": "^3.0",
2626
"firebase/php-jwt": "^6.3",
2727
"intervention/image": "^3.0",
28-
"php": "^8.1",
2928
"doctrine/dbal": "^3.6"
3029
},
3130
"require-dev": {

database/migrations/2023_01_12_122527_refactor_attr_menu.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private function legacyConveryBitToJSon($menuitem)
8181
'allowChangeParent' => (bool) (intval($menuitem->attr) & $ATTR_CHANGEPARENT),
8282
'allowDeleteChildren' => ! (intval($menuitem->attr) & $ATTR_NODELETECHILD),
8383
'allowEnabled' => ! (intval($menuitem->attr) & $ATTR_NOENABLE),
84-
'exludeFromSearch' => (bool) $excludeFromSearch,
84+
'excludeFromSearch' => (bool) $excludeFromSearch,
8585
];
8686
$menuitem->properties = ($newProperties);
8787
$menuitem->menu = (bool) (intval($menuitem->attr) & $ATTR_NODELETECHILD);

routes/console.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
use NotFound\Framework\Services\CmsExchange\ExchangeConsoleService;
66
use NotFound\Framework\Services\Indexer\IndexBuilderService;
77

8-
Artisan::command('siteboss:index-site {--debug : Whether debug messages should be displayed} {--clean : Truncate search table}', function ($debug, $clean) {
8+
Artisan::command('siteboss:index-site {--debug : Display debug messages} {--fresh : Empty local search table}', function ($debug, $fresh) {
99

10-
$indexer = new IndexBuilderService($debug, $clean);
10+
$indexer = new IndexBuilderService($debug, $fresh);
1111
$indexer->run();
1212

1313
return Command::SUCCESS;
1414
})->purpose('Index site for local search');
1515

16-
Artisan::command('siteboss:cms-import {--debug : Whether debug messages should be displayed} {--dry : Dry Run}', function ($debug, $dry) {
16+
Artisan::command('siteboss:cms-import {--debug : Display debug messages} {--dry : Dry Run}', function ($debug, $dry) {
1717

1818
$indexer = new ExchangeConsoleService($debug, $dry);
1919
$indexer->import();

src/Models/Indexes/SolrIndex.php

+13-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace NotFound\Framework\Models\Indexes;
44

55
use Illuminate\Support\Facades\Mail;
6-
use Illuminate\Support\Facades\Storage;
76
use NotFound\Framework\Mail\Indexer\FileIndexError;
87
use NotFound\Framework\Mail\Indexer\QueryError;
98
use NotFound\Framework\Models\BaseModel;
@@ -131,14 +130,14 @@ public function testSolrConnection()
131130
return false;
132131
}
133132

134-
public function upsertItem(SearchItem $indexItem, int $siteId = 1): bool
133+
public function upsertItem(SearchItem $indexItem, int $siteId = 1, ?string $domain = null): bool
135134
{
136135
$curl = $this->solrHandler();
137136
$doc = [
138137
sprintf('title_%s', $indexItem->language()) => $indexItem->title(),
139138
sprintf('content_%s', $indexItem->language()) => html_entity_decode(trim(preg_replace('/\s+/', ' ', preg_replace('#<[^>]+>#', ' ', $indexItem->content())))),
140139
'type' => $indexItem->type(),
141-
'url' => $this->siteUrl($indexItem->url(), $siteId),
140+
'url' => $this->siteUrl($indexItem->url(), $domain),
142141
'priority' => $indexItem->priority(),
143142
'site' => $siteId,
144143
'language' => $indexItem->language(),
@@ -197,19 +196,20 @@ public function removeItem($url)
197196
return false;
198197
}
199198

200-
public function upsertFile(SearchItem $indexItem, int $siteId = 1): string
199+
public function upsertFile(SearchItem $indexItem, int $siteId = 1, ?string $domain = null): string
201200
{
202201

203202
// find out of document exists
204203
$result = 0;
205-
$file = Storage::disk('private')->path($indexItem->file());
204+
// TODO: check if path is within allowed path
205+
$file = $indexItem->file();
206206

207207
if (file_exists($file)) {
208208
$curl = $this->solrHandler();
209209
$endpoint = sprintf(
210210
'%s/update/extract?literal.url=%s&literal.title_%s=%s&literal.type=%s&literal.site=%s&literal.language=%d&literal.solr_date=%s&uprefix=ignored_&fmap.content=content_%s&commit=true',
211211
$this->getSolrBaseUrl(),
212-
urlencode($this->siteUrl($indexItem->url(), $siteId)),
212+
urlencode($this->siteUrl($indexItem->url(), $domain)),
213213
$indexItem->language(),
214214
urlencode($indexItem->title()),
215215
$indexItem->type(),
@@ -257,6 +257,7 @@ public function upsertFile(SearchItem $indexItem, int $siteId = 1): string
257257
}
258258
} else {
259259
$this->mailFileError($indexItem->title(), $indexItem->url(), 'file bestaat niet');
260+
printf("\nFile not found: %s", $file);
260261

261262
return 'fileNotFound';
262263
}
@@ -441,8 +442,12 @@ public function checkConnection(): bool
441442
return false;
442443
}
443444

444-
public function siteUrl($url, $siteId): string
445+
public function siteUrl($url, ?string $domain): string
445446
{
446-
return sprintf('{{%d}}%s', $siteId, $url);
447+
if ($domain) {
448+
return sprintf('%s/%s', rtrim($domain, '/'), ltrim($url, '/'));
449+
}
450+
451+
return $url;
447452
}
448453
}

src/Models/Indexes/SolrItem.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct($solr, $q, $collate = false, private int $highlightL
6464
$this->error = isset($solr->error) ? $solr->error : null;
6565
}
6666

67-
public function isValid()
67+
public function isValid(): bool
6868
{
6969
return $this->header && $this->header->status == 0;
7070
}
@@ -183,21 +183,22 @@ public function predictions()
183183
return $queries;
184184
}
185185

186-
public function spellcheckList()
186+
public function spellcheckList(): array
187187
{
188188
$items = [];
189189
$query = $this->q;
190190

191191
if (isset($this->spellcheck)) {
192192
foreach ($this->spellcheck->suggestions as $suggestion) {
193+
193194
if (isset($suggestion->startOffset)) {
194195
$suggest = substr($query, 0, $suggestion->startOffset).'<em>'.$suggestion->suggestion[0].'</em>'.substr($query, $suggestion->endOffset);
195196
$suggestTerm = preg_replace('/^([a-zA-Z])+(_[a-zA-Z]{2})?:/', '', $suggest); // remove search field if necessary
196197

197198
$suggest_url = substr($query, 0, $suggestion->startOffset).$suggestion->suggestion[0].substr($query, $suggestion->endOffset);
198199
$suggest_url = preg_replace('/^([a-zA-Z])+(_[a-zA-Z]{2})?:/', '', $suggest_url); // remove search field if necessary
199200

200-
$items[] = (object) ['link' => '?q='.rawurlencode(urldecode($suggest_url)), 'text' => urldecode($suggestTerm)];
201+
$items[] = (object) ['link' => '?q='.rawurlencode(urldecode($suggest_url)), 'text' => $suggestTerm];
201202
}
202203
}
203204
}

src/Services/Assets/Components/ComponentTags.php

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Facades\DB;
66
use NotFound\Framework\Services\Legacy\StatusColumn;
77
use NotFound\Layout\Elements\AbstractLayout;
8+
use NotFound\Layout\Elements\Table\LayoutTableColumn;
89
use NotFound\Layout\Inputs\LayoutInputTags;
910

1011
class ComponentTags extends AbstractComponent
@@ -72,6 +73,19 @@ public function getCurrentValue()
7273
->get([$foreignTable.'.'.$p->foreignTagId.' AS id', $foreignTable.'.'.$p->foreignDisplayColumn.' AS label'])->toArray();
7374
}
7475

76+
/**
77+
* Gets the content for the table overview, this is usually a string.
78+
*/
79+
public function getTableOverviewContent(): LayoutTableColumn
80+
{
81+
// convert to array with only the value of the label
82+
$values = collect($this->getCurrentValue())->map(function ($item) {
83+
return $item->label;
84+
});
85+
86+
return new LayoutTableColumn(implode(', ', $values->toArray()));
87+
}
88+
7589
/**
7690
* This function is for doing additional actions while saving, or - when not using the
7791
* default storage mechanism - doing custom stuff.

src/Services/Indexer/AbstractIndexService.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ abstract class AbstractIndexService
1010

1111
public int $siteId;
1212

13+
public ?string $domain;
14+
1315
abstract public function __construct($debug = false);
1416

1517
abstract public function startUpdate(): bool;
@@ -29,7 +31,7 @@ public function clean(): bool
2931

3032
public function urlNeedsUpdate(string $url, $updated): bool
3133
{
32-
$searchItem = CmsSearch::whereUrl($url)->first();
34+
$searchItem = CmsSearch::whereUrl($this->siteUrl($url))->first();
3335
if ($searchItem && ($searchItem->updated_at !== null && $searchItem->updated_at->timestamp > $updated)) {
3436
CmsSearch::whereUrl($url)->update(['search_status' => 'SKIPPED']);
3537

@@ -41,6 +43,10 @@ public function urlNeedsUpdate(string $url, $updated): bool
4143

4244
protected function siteUrl($url): string
4345
{
44-
return sprintf('{{%d}}%s', $this->siteId, $url);
46+
if ($this->domain) {
47+
return sprintf('%s/%s', rtrim($this->domain, '/'), ltrim($url, '/'));
48+
}
49+
50+
return $url;
4551
}
4652
}

src/Services/Indexer/IndexBuilderService.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class IndexBuilderService
1212
{
1313
private bool $debug;
1414

15-
private bool $clean;
15+
private bool $fresh;
1616

1717
private $locales;
1818

@@ -22,11 +22,11 @@ class IndexBuilderService
2222

2323
private AbstractIndexService $searchServer;
2424

25-
public function __construct($debug = false, $clean = false)
25+
public function __construct($debug = false, $fresh = false)
2626
{
2727
$serverType = config('indexer.engine');
2828
$this->debug = $debug;
29-
$this->clean = $clean;
29+
$this->fresh = $fresh;
3030
$this->locales = Lang::all();
3131

3232
$this->domain = rtrim(env('APP_URL', ''), '/');
@@ -46,7 +46,7 @@ public function run()
4646

4747
return;
4848
}
49-
if ($this->clean) {
49+
if ($this->fresh) {
5050
$this->searchServer->clean();
5151
}
5252
$sites = CmsSite::whereIndex(1)->get();
@@ -69,6 +69,8 @@ public function run()
6969

7070
$siteId = $site->id;
7171
$this->searchServer->siteId = $siteId;
72+
$this->searchServer->domain = $site->domain ?? null;
73+
7274
$this->searchServer->languageId = 1;
7375

7476
// insert all pages, starting from the root
@@ -104,7 +106,7 @@ private function indexChildPages($parentId)
104106

105107
continue;
106108
}
107-
if (isset($page->properties->exludeFromSearch) && $page->properties->exludeFromSearch == true) {
109+
if (isset($page->properties->excludeFromSearch) && $page->properties->excludeFromSearch == true) {
108110
$this->writeDebug(" skipping, page not searchable\n");
109111

110112
continue;

src/Services/Indexer/SolrIndexService.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class SolrIndexService extends AbstractIndexService
1212

1313
public int $siteId;
1414

15+
public ?string $domain;
16+
1517
public $solrIndex;
1618

1719
public function __construct($debug = false)
@@ -26,7 +28,7 @@ public function upsertItem(SearchItem $searchItem): object
2628
$cmsSearchItemStatus = '';
2729

2830
if ($searchItem->type() === 'file') {
29-
$result = $this->solrIndex->upsertFile($searchItem, $this->siteId);
31+
$result = $this->solrIndex->upsertFile($searchItem, $this->siteId, $this->domain);
3032

3133
$return = $this->returnvalue();
3234
if ($result == 'success') {
@@ -37,7 +39,7 @@ public function upsertItem(SearchItem $searchItem): object
3739
$return->message = "failed: file not found \n";
3840
} else {
3941
$cmsSearchItemStatus = 'NOT_INDEXABLE';
40-
$result = $this->solrIndex->upsertItem($searchItem, $this->siteId);
42+
$result = $this->solrIndex->upsertItem($searchItem, $this->siteId, $this->domain);
4143
if ($result) {
4244
$cmsSearchItemStatus = 'UPDATED';
4345
} else {
@@ -46,7 +48,7 @@ public function upsertItem(SearchItem $searchItem): object
4648
}
4749
}
4850
} else {
49-
$result = $this->solrIndex->upsertItem($searchItem, $this->siteId);
51+
$result = $this->solrIndex->upsertItem($searchItem, $this->siteId, $this->domain);
5052

5153
if ($result) {
5254
$cmsSearchItemStatus = 'UPDATED';
@@ -57,9 +59,9 @@ public function upsertItem(SearchItem $searchItem): object
5759
}
5860
}
5961

60-
$cmsSearchItem = CmsSearch::firstOrNew(['url' => $this->solrIndex->siteUrl($searchItem->url(), $this->siteId)]);
62+
$cmsSearchItem = CmsSearch::firstOrNew(['url' => $this->solrIndex->siteUrl($searchItem->url(), $this->domain)]);
6163
$cmsSearchItem->setValues($searchItem, $cmsSearchItemStatus);
62-
$cmsSearchItem->url = $this->solrIndex->siteUrl($searchItem->url(), $this->siteId);
64+
$cmsSearchItem->url = $this->solrIndex->siteUrl($searchItem->url(), $this->domain);
6365
$cmsSearchItem->save();
6466
if ($cmsSearchItemStatus == 'FAILED') {
6567
$cmsSearchItem->updated_at = null;

0 commit comments

Comments
 (0)