Commit 5db67a92 authored by Jonny Bradley's avatar Jonny Bradley

[ENH] search: Add a new pref to allow some facets (aggregations) to not be...

[ENH] search: Add a new pref to allow some facets (aggregations) to not be displayed on the default search page tiki-searchindex.php
parent f56c1344
Pipeline #50298243 failed with stages
in 28 minutes and 34 seconds
......@@ -90,6 +90,9 @@ function prefs_search_list()
'filter' => 'digits',
'units' => tra('facet results'),
'default' => '10',
'dependencies' => [
'search_use_facets',
],
],
'search_index_outdated' => [
'name' => tra('Search index outdated'),
......@@ -119,6 +122,9 @@ function prefs_search_list()
'description' => tr('Use date histogram aggregations (facets) when indexing, requires Elasticsearch'),
'type' => 'flag',
'default' => 'n',
'dependencies' => [
'search_use_facets',
],
],
'search_date_facets_interval' => [
'name' => tra('Date histogram aggregations interval'),
......@@ -150,5 +156,17 @@ now/m,now+1m/m,Next Month
'search_date_facets',
],
],
'search_excluded_facets' => [
'name' => tra('Excluded facets'),
'description' => tra('List of facets (a.k.a. aggregations) to exclude from the default search results'),
'hint' => 'For example: object_type,title_initial,title_firstword,tracker_field_userName',
'type' => 'text',
'filter' => 'word',
'separator' => ',',
'default' => [],
'dependencies' => [
'search_use_facets',
],
],
];
}
......@@ -176,6 +176,7 @@
<br>
{preference name=search_use_facets}
{preference name=search_facet_default_amount}
{preference name=search_excluded_facets}
{preference name=category_custom_facets}
{preference name=search_date_facets}
{preference name=search_date_facets_interval}
......
......@@ -101,14 +101,20 @@ if (count($filter) || count($postfilter)) {
$isCached = true;
}
}
$excludedFacets = $prefs['search_excluded_facets'];
if (! $isCached) {
$results = tiki_searchindex_get_results($filter, $postfilter, $offset, $maxRecords);
$facets = array_map(
function ($facet) {
return $facet->getName();
$facets = array_filter(array_map(
function ($facet) use ($excludedFacets) {
$name = $facet->getName();
if (! in_array($name, $excludedFacets)) {
return $name;
} else {
return '';
}
},
$results->getFacets()
);
));
$plugin = new Search_Formatter_Plugin_SmartyTemplate('searchresults-plain.tpl');
$plugin->setData(
......@@ -205,7 +211,9 @@ function tiki_searchindex_get_results($filter, $postfilter, $offset, $maxRecords
$provider = $unifiedsearchlib->getFacetProvider();
foreach ($provider->getFacets() as $facet) {
$query->requestFacet($facet);
if (! in_array($facet->getName(), $prefs['search_excluded_facets'])) {
$query->requestFacet($facet);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment