Skip to content

Commit

Permalink
Merge pull request #48 from slub/28-multiple-facettes-selectable-bib
Browse files Browse the repository at this point in the history
28 multiple facettes selectable bib
  • Loading branch information
dikastes authored Jan 24, 2025
2 parents 4bf7f7e + a216635 commit 961e611
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 31 deletions.
12 changes: 9 additions & 3 deletions Classes/Command/IndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ protected function versionedSync(int $version): void
protected function sync(int $cursor = 0, int $version = 0): void
{
$this->fetchBibliography($cursor, $version);
$this->fetchCitations($cursor, $version);
$this->fetchTeiData($cursor, $version);
// $this->fetchCitations($cursor, $version);
// $this->fetchTeiData($cursor, $version);
$this->buildDataSets();
$this->commitBibliography();
}
Expand Down Expand Up @@ -361,7 +361,13 @@ protected function buildDataSets(): void
{
$this->dataSets = $this->bibliographyItems->
map(function($bibliographyItem) {
return BibEntryProcessor::process($bibliographyItem, $this->localizedCitations, $this->teiDataSets);
return BibEntryProcessor::process(
$bibliographyItem,
new Collection(),
new Collection()
// $this->localizedCitations,
// $this->teiDataSets
);
});
}

Expand Down
33 changes: 22 additions & 11 deletions Classes/Processing/BibElasticMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ public static function getMappingParams(string $index): array
'mappings' => [
'dynamic' => false,
'properties' => [
'itemType' => [ 'type' => 'keyword' ],
'itemType' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'version' => [ 'type' => 'long' ],
'title' => [ 'type' => 'text'],
'university' => [ 'type' => 'text'],
'bookTitle' => [ 'type' => 'text'],
'series' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'publicationTitle' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'language' => [ 'type' => 'keyword' ],
'language' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'place' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'date' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'archiveLocation' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'journalTitle' => [ 'type' => 'keyword'],
'journalTitle' => [ 'type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword', 'ignore_above' => 256 ] ] ],
'creators' => [
'type' => 'nested',
'properties' => [
Expand All @@ -40,7 +40,6 @@ public static function getMappingParams(string $index): array
'type' => 'keyword', 'ignore_above' => 256
],
],
'copy_to' => 'creators.fullName'
],
'lastName' => [
'type' => 'text',
Expand All @@ -49,17 +48,29 @@ public static function getMappingParams(string $index): array
'type' => 'keyword', 'ignore_above' => 256
]
],
'copy_to' => 'creators.fullName'
],
'fullName' => ['type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword'] ] ],
BibEntryProcessor::FULLNAME_KEY => ['type' => 'text', 'fields' => [ 'keyword' => [ 'type' => 'keyword'] ] ],
]
],
'fulltext' => [ 'type' => 'text' ],
'tx_lisztcommon_header' => [ 'type' => 'text' ],
'tx_lisztcommon_body' => [ 'type' => 'text' ],
'tx_lisztcommon_footer' => [ 'type' => 'text' ],
'tx_lisztcommon_searchable' => ['type' => 'text', 'copy_to' => 'fulltext'],
'tx_lisztcommon_boosted' => ['type' => 'text'],
BibEntryProcessor::HEADER_FIELD => [ 'type' => 'text' ],
BibEntryProcessor::BODY_FIELD => [ 'type' => 'text' ],
BibEntryProcessor::FOOTER_FIELD => [ 'type' => 'text' ],
BibEntryProcessor::SEARCHABLE_FIELD => ['type' => 'text', 'copy_to' => 'fulltext'],
BibEntryProcessor::BOOSTED_FIELD => ['type' => 'text'],
BibEntryProcessor::CREATORS_FIELD => [
'type' => 'nested',
'properties' => [
BibEntryProcessor::FULLNAME_KEY => [
'type' => 'text',
'fields' => [
'keyword' => [
'type' => 'keyword', 'ignore_above' => 256
],
],
],
]
],
]
]
]
Expand Down
23 changes: 23 additions & 0 deletions Classes/Processing/BibEntryConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,29 @@ class BibEntryConfig
[ 'field' => 'date' ]
];

const CREATORS_FIELD = [
[
'compoundArray' => [
'fields' => [
[
'field' => 'firstName',
'conditionField' => 'creatorType',
'conditionValue' => 'translator',
'conditionRelation' => 'neq'
],
[
'field' => 'lastName',
'conditionField' => 'creatorType',
'conditionValue' => 'translator',
'conditionRelation' => 'neq'
]
],
'field' => 'creators',
'separator' => ' '
]
]
];

public static function getAuthorHeader(): array
{
return [ self::AUTHOR ];
Expand Down
77 changes: 73 additions & 4 deletions Classes/Processing/BibEntryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

class BibEntryProcessor extends IndexProcessor
{
const CREATORS_FIELD = 'tx_lisztbibliography_creators';
const FULLNAME_KEY = 'fullName';

public static function process(
array $bibliographyItem,
Expand Down Expand Up @@ -56,6 +58,8 @@ public static function process(
$bibliographyItem[self::SEARCHABLE_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::SEARCHABLE_FIELDS);
$bibliographyItem[self::BOOSTED_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::BOOSTED_FIELDS);

$bibliographyItem[self::CREATORS_FIELD] = self::buildNestedField($bibliographyItem, BibEntryConfig::CREATORS_FIELD);

return $bibliographyItem;
}

Expand All @@ -64,23 +68,88 @@ public static function buildListingField(
array $fieldConfig
): Stringable
{
return Collection::wrap($fieldConfig)->
map( function($field) use ($bibliographyItem) { return self::buildListingEntry($field, $bibliographyItem); })->
$collectedFields = Collection::wrap($fieldConfig)->
map( function($field) use ($bibliographyItem) { return self::buildListingEntry($field, $bibliographyItem); });
if (is_array($collectedFields->get(0))) {
print_r($collectedFields->get(0));
return $collectedFields->get(0);
}
return $collectedFields->
join('')->
trim();
}

private static function buildListingEntry(array $field, array $bibliographyItem): ?Stringable
/*
* @Matthias: this is a new function for nested fields with an array of object,
* maybe ist much easier with an own BibEntryConfig
*/
public static function buildNestedField(
array $bibliographyItem,
array $fieldConfig
): array
{
return Collection::wrap($fieldConfig)->
map(function ($field) use ($bibliographyItem) {
$entry = self::buildListingEntry($field, $bibliographyItem);

// buildListingEntry can return null if no field creators exist
if ($entry === null) {
// ignore or return empty array ?
return []; //
}

if (!is_array($entry)) {
throw new \UnexpectedValueException(
'Expected array from buildListingEntry, but got: ' . gettype($entry)
);
}
return $entry;
})->
flatMap(function (array $item): Collection {
return Collection::wrap($item)->map( function ($i) {
return [self::FULLNAME_KEY => $i];
});
})->toArray();

/*
returns:
(
[0] => Array
([fullName] => Illuminate\Support\Stringable Object ([value:protected] => Michael Saffle))
[1] => Array
([fullName] => Illuminate\Support\Stringable Object([value:protected] => Michael Saffle)
)
*/
}

private static function buildListingEntry(array $field, array $bibliographyItem): Stringable|array|null
{
// return empty string if field does not exist
if (
isset($field['field']) &&
!isset($bibliographyItem[$field['field']]) ||
isset($field['compound']['field']) &&
!isset($bibliographyItem[$field['compound']['field']])
!isset($bibliographyItem[$field['compound']['field']]) ||
isset($field['compoundArray']['field']) &&
!isset($bibliographyItem[$field['compoundArray']['field']])
) {
return null;
}

// return an array when compoundArray option is set
if (isset($field['compoundArray'])) {
// build compound fields
return Collection::wrap($bibliographyItem[$field['compoundArray']['field']])->
// get selected strings
map(function ($bibliographyCell) use ($field) {
return self::processCompound($field['compoundArray'], $bibliographyCell);
})->
// filter out non fitting fields
filter()->
toArray();
}

// return empty string if conditions are not met
if (
isset($field['conditionField']) &&
Expand Down
32 changes: 19 additions & 13 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,45 @@ plugin.tx_lisztcommon_searchlisting {
extensionName = liszt_bibliography
# the name of the entity index
indexName = zotero
# the filename of the language file for translations in /Resources/Private/Language/ of the extension
languageFile = bibliographylang
# the facets are multi selectable if multiselect is set
# size is the number of facet items shown, default = defaultFilterSize = 10
defaultFilterSize = 10
# maxSize is the number of items loaded and hidden for "display more" button
# the filter fields
filters {
0 {
field = itemType
type = keyword
multiselect= 1
}
1 {
field = creators
field = tx_lisztbibliography_creators
type = nested
script (
String firstName = doc['creators.firstName.keyword'].size() > 0 ? doc['creators.firstName.keyword'].value : '';
String lastName = doc['creators.lastName.keyword'].size() > 0 ? doc['creators.lastName.keyword'].value : '';
String type = doc['creators.creatorType'].size() > 0 ? doc['creators.creatorType'].value : '';
if (type == 'translator') {
return null;
}
if (firstName == '' && lastName == '') {
return null;
}
return (firstName + ' ' + lastName).trim();
)
key = fullName
multiselect= 1
maxSize = 80
}
2 {
field = date
type = terms
multiselect = 1
maxSize =100
size = 10
}
3 {
field = language
type = keyword
multiselect = 1
size = 5
}
4 {
field = publicationTitle
type = terms
multiselect = 1
size = 5
maxSize = 80
}
}
}
Expand Down
44 changes: 44 additions & 0 deletions Resources/Private/Language/bibliographylang.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="EXT:liszt_bibliography/Resources/Private/Language/bibliographylang.xlf" date="2025-01-14T13:20:31Z" product-name="liszt_bibliography">
<header/>
<body>
<trans-unit id="itemType" >
<source>Typ</source>
</trans-unit>
<trans-unit id="tx_lisztbibliography_creators" >
<source>Beteiligte</source>
</trans-unit>
<trans-unit id="date" >
<source>Datum</source>
</trans-unit>
<trans-unit id="language" >
<source>Sprache</source>
</trans-unit>
<trans-unit id="publicationTitle" >
<source>Journaltitel</source>
</trans-unit>
<trans-unit id="itemType_book" >
<source>Buch</source>
</trans-unit>
<trans-unit id="itemType_journalArticle" >
<source>Zeitschriftenartikel</source>
</trans-unit>
<trans-unit id="itemType_bookSection" >
<source>Buchkapitel</source>
</trans-unit>
<trans-unit id="itemType_thesis" >
<source>Dissertation</source>
</trans-unit>
<trans-unit id="itemType_attachment" >
<source>Anhang</source>
</trans-unit>
<trans-unit id="itemType_webpage" >
<source>Webseite</source>
</trans-unit>
<trans-unit id="itemType_encyclopediaArticle" >
<source>Enzyklopädieartikel</source>
</trans-unit>
</body>
</file>
</xliff>
11 changes: 11 additions & 0 deletions Resources/Private/Language/de.bibliographylang.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="EXT:liszt_bibliography/Resources/Private/Language/bibliographylang.xlf" date="2025-01-14T13:20:31Z" product-name="liszt_bibliography">
<header/>
<body>
<trans-unit id="itemType" >
<source>Kategorie</source>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 961e611

Please sign in to comment.