-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first refactorings,dependency injection, search controller
- Loading branch information
thomas-sc
committed
May 13, 2024
1 parent
65ccbe2
commit 6af58c5
Showing
8 changed files
with
170 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
namespace Slub\LisztBibliography\Interfaces; | ||
use Illuminate\Support\Collection; | ||
|
||
|
||
interface ElasticSearchServiceInterface | ||
{ | ||
public function init(): bool; | ||
|
||
public function getElasticInfo(): array; | ||
|
||
public function search(): Collection; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
|
||
namespace Slub\LisztBibliography\Services; | ||
|
||
use Elastic\Elasticsearch\Client; | ||
use Elastic\Elasticsearch\Response\Elasticsearch; | ||
use Http\Promise\Promise; | ||
use Illuminate\Support\Collection; | ||
use Slub\LisztCommon\Common\ElasticClientBuilder; | ||
use Slub\LisztBibliography\Interfaces\ElasticSearchServiceInterface; | ||
|
||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; | ||
|
||
|
||
|
||
class ElasticSearchService implements ElasticSearchServiceInterface | ||
{ | ||
|
||
protected ?Client $client = null; | ||
protected string $bibIndex; | ||
protected string $localeIndex; | ||
|
||
// Todo: Enable Elasticsearch Security: built-in security features are not enabled. | ||
public function init(): bool | ||
{ | ||
$this->client = ElasticClientBuilder::getClient(); | ||
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('liszt_bibliography'); | ||
$this->bibIndex = $extConf['elasticIndexName']; | ||
$this->localeIndex = $extConf['elasticLocaleIndexName']; | ||
return true; | ||
} | ||
|
||
public function getElasticInfo(): array | ||
{ | ||
$this->init(); | ||
return ($this->client->info()->asArray()); | ||
} | ||
|
||
public function search(): Collection | ||
{ | ||
$this->init(); | ||
$params = [ | ||
'index' => $this->bibIndex, | ||
'body' => [ | ||
'query' => [ | ||
'match_all' => new \stdClass() | ||
], | ||
'size' => 10, | ||
'_source' => ['itemType', 'title', 'creators', 'pages','date','language'], | ||
'aggs' => [ | ||
'itemType' => [ | ||
'terms' => [ | ||
'field' => 'itemType.keyword', | ||
] | ||
], | ||
'place' => [ | ||
'terms' => [ | ||
'field' => 'place.keyword', | ||
] | ||
] | ||
] | ||
] | ||
]; | ||
// ToDo: handle exceptions! | ||
$response = $this->client->search($params); | ||
return new Collection($response->asArray()); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> | ||
|
||
<f:debug>{_all}</f:debug> | ||
|
||
<div class="row" style="margin-top: 3rem;"> | ||
<div class="col-12 col-md-3 col-lg-2 "> | ||
<nav aria-label="Suchfilter" class="filter" > | ||
|
||
<h3 class="visually-hidden">Suchfilter</h3> | ||
|
||
<f:for each="{bibliographyList.aggregations}" key="key" as="filterGroup"> | ||
<f:if condition="{filterGroup.buckets}"> | ||
<div class="filter-block"> | ||
<h4 class="">{key}</h4> | ||
<ul> | ||
<f:for each="{filterGroup.buckets}" as="filter"> | ||
<li><span class="form-check"><input class="form-check-input" type="checkbox" id="{filter.key}" value="{filter.key}"><label class="form-check-label" for="{filter.key}">{filter.key}</label></span><span class="count">{filter.doc_count}</span></li> | ||
</f:for> | ||
</ul> | ||
</div> | ||
</f:if> | ||
</f:for> | ||
|
||
</nav> | ||
|
||
</div> | ||
<div class="col-12 col-md-9 col-lg-10 filter"> | ||
|
||
<f:for each="{bibliographyList.hits.hits}" as="hit"> | ||
<div class="search-result-item"> | ||
<h3>{hit._source.title}</h3> | ||
<p> | ||
<f:for each="{hit._source.creators}" as="creator"> | ||
{creator.firstName} {creator.lastName} | ||
</f:for> | ||
,{hit._source.date}, {hit._source.pages}, {hit._source.language}</p> | ||
</div> | ||
</f:for> | ||
|
||
|
||
|
||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters