Skip to content

Commit

Permalink
custom mappings, facettes for creator names, full text search with bo…
Browse files Browse the repository at this point in the history
…osting of phrases
  • Loading branch information
thomas-sc committed Nov 19, 2024
1 parent e893b9d commit ba8934d
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 42 deletions.
65 changes: 57 additions & 8 deletions Classes/Common/QueryParamsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function createElasticParams(array $searchParams): array
'index' => $bibIndex,
'body' => [
'size' => 10,
'_source' => ['itemType', 'tx_lisztcommon_header', 'tx_lisztcommon_body', 'tx_lisztcommon_footer'],
'_source' => ['itemType', 'tx_lisztcommon_header', 'tx_lisztcommon_body', 'tx_lisztcommon_footer', 'tx_lisztcommon_searchable'],
//'aggs' => $aggs
'aggs' =>
[
Expand All @@ -38,15 +38,35 @@ public static function createElasticParams(array $searchParams): array
'field' => 'date.keyword',
]
],
'language' => [
'terms' => [
'field' => 'language.keyword',
]
],
'journalTitle' => [
'terms' => [
'field' => 'publicationTitle.keyword',
]
],
'creators_name' => [
'nested' => [
'path' => 'creators',
],
'aggs' => [
'names' => [
'terms' => [
'script' => [
'source' => '
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 : \'\';
if (firstName == \'\' && lastName == \'\') {
return null;
}
return (firstName + \' \' + lastName).trim();
',
'lang' => 'painless',
],
'size' => 15,
]
]
]
]
]
]
Expand All @@ -60,10 +80,25 @@ public static function createElasticParams(array $searchParams): array
]
];
} else {
// search in field "fulltext" exakt phrase match boost over all words must contain
$params['body']['query'] = [
'bool' => [
'must' => [
['query_string' => ['query' => $searchParams['searchText']]],
'should' => [
[
'match_phrase' => [
'tx_lisztcommon_searchable' => [
'query' => $searchParams['searchText'],
'boost' => 2.0 // boosting for exakt phrases
]
]
],
[
'query_string' => [
'query' => $searchParams['searchText'],
'fields' => ['fulltext'],
'default_operator' => 'AND'
]
]
]
]
];
Expand All @@ -79,6 +114,20 @@ public static function createElasticParams(array $searchParams): array
if (isset($searchParams['f_date']) && $searchParams['f_date'] !== "") {
$params['body']['query']['bool']['filter'][] = ['term' => ['date.keyword' => $searchParams['f_date']]];
}
// filter creators name, Todo: its not a filter query because they need 100% match (with spaces from f_creators_name)
// better would be to build the field 'fullName' at build time with PHP?
if (isset($searchParams['f_creators_name']) && $searchParams['f_creators_name'] !== "") {
$params['body']['query']['bool']['must'][] = [
'nested' => [
'path' => 'creators',
'query' => [
'match' => [
'creators.fullName' => $searchParams['f_creators_name']
]
]
]
];
}

return $params;
}
Expand Down
36 changes: 36 additions & 0 deletions Resources/Private/Partials/FilterBlock.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{namespace lc=Slub\LisztCommon\ViewHelpers}
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">

<div class="filter-block frame">
<h4 class="">{key}</h4>
<f:variable name="searchParamsFilterKey">f_{key}</f:variable>
<ul>
<f:for each="{filterGroup.buckets}" as="filter">
<li>
<f:if condition="{filter.key} && {searchParams.{searchParamsFilterKey}} == {filter.key}">
<f:then>
<f:link.action action="index" controller="Search" pluginName="SearchListing" arguments="{lc:searchParams(action: 'remove', searchParamsArray: searchParams, key: searchParamsFilterKey)}" class="filter-item selected">
<span class="filter-item-label">{filter.key}</span>
<span class="filter-item-count">{filter.doc_count}</span>
</f:link.action>
</f:then>
<f:else if="{filter.key}">
<f:link.action action="index" controller="Search" pluginName="SearchListing" arguments="{lc:searchParams(action: 'add', searchParamsArray: searchParams, key: searchParamsFilterKey, value: filter.key)}" class="filter-item">
<span class="filter-item-label">{filter.key}</span>
<span class="filter-item-count">{filter.doc_count}</span>
</f:link.action>
</f:else>
</f:if>
</li>

<f:comment> <!-- old versions of filter (form input), ToDo: remove later if not needed-->
<li><f:link.action action="index" controller="Search" pluginName="SearchListing" arguments="{searchParams: {f_itemType: filter.key}}" class="form-checkbox"><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 class="count">{filter.doc_count}</span></f:link.action></li>
<li><a href="{f:uri.action(controller: 'Search', action: 'index', extensionName: 'liszt_common', pluginName: 'SearchListing', pageUid: '18')}" class="form-checkbox"><input class="form-check-input" type="checkbox" id="{filter.key}" value="{filter.key}"><label class="form-check-label" for="{filter.key}">{filter.key}</label></a><span class="count">{filter.doc_count}</span></li>
<li><span class="form-checkbox"><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:comment>

</f:for>
</ul>
</div>

</html>
38 changes: 4 additions & 34 deletions Resources/Private/Templates/Search/Index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
{f:translate(key: 'filter_container_label', extensionName: 'liszt_common')}
</button>
</div>
<f:debug>{_all}</f:debug>

<f:if condition="{searchParams}">
<div class="searchresults-filtertags" aria-label="{f:translate(key: 'searchResults_params_label', extensionName: 'liszt_common')}" role="navigation" >
Expand Down Expand Up @@ -42,39 +41,10 @@ <h5 class="offcanvas-title">{f:translate(key: 'filter_container_label', extensio
<div class="offcanvas-body">
<f:for each="{searchResults.aggregations}" key="key" as="filterGroup">
<f:if condition="{filterGroup.buckets}">
<div class="filter-block frame">
<h4 class="">{key}</h4>
<f:variable name="searchParamsFilterKey">f_{key}</f:variable>
<ul>
<f:for each="{filterGroup.buckets}" as="filter">
<li>
<f:if condition="{searchParams.{searchParamsFilterKey}} == {filter.key}">
<f:then>
<f:link.action action="index" controller="Search" pluginName="SearchListing" arguments="{lc:searchParams(action: 'remove', searchParamsArray: searchParams, key: searchParamsFilterKey)}" class="filter-item selected">
<span class="filter-item-label">{filter.key}</span>
<span class="filter-item-count">{filter.doc_count}</span>
</f:link.action>
</f:then>
<f:else>
<f:link.action action="index" controller="Search" pluginName="SearchListing" arguments="{lc:searchParams(action: 'add', searchParamsArray: searchParams, key: searchParamsFilterKey, value: filter.key)}" class="filter-item">
<span class="filter-item-label">{filter.key}</span>
<span class="filter-item-count">{filter.doc_count}</span>
</f:link.action>
</f:else>
</f:if>
</li>



<f:comment> <!-- old versions of filter (form input), ToDo: remove later if not needed-->
<li><f:link.action action="index" controller="Search" pluginName="SearchListing" arguments="{searchParams: {f_itemType: filter.key}}" class="form-checkbox"><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 class="count">{filter.doc_count}</span></f:link.action></li>
<li><a href="{f:uri.action(controller: 'Search', action: 'index', extensionName: 'liszt_common', pluginName: 'SearchListing', pageUid: '18')}" class="form-checkbox"><input class="form-check-input" type="checkbox" id="{filter.key}" value="{filter.key}"><label class="form-check-label" for="{filter.key}">{filter.key}</label></a><span class="count">{filter.doc_count}</span></li>
<li><span class="form-checkbox"><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:comment>

</f:for>
</ul>
</div>
<f:render partial="FilterBlock" arguments="{key: key, filterGroup: filterGroup, searchParams: searchParams}" />
</f:if>
<f:if condition="{filterGroup.names}">
<f:render partial="FilterBlock" arguments="{key: key, filterGroup: filterGroup.names, searchParams: searchParams}" />
</f:if>
</f:for>
</div>
Expand Down

0 comments on commit ba8934d

Please sign in to comment.