Skip to content

Commit

Permalink
Make Highlight aware of Advanced Search Aggregated field search
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoPino committed Apr 14, 2023
1 parent 3e39f8c commit 2a79207
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/Plugin/search_api/processor/StrawberryFieldHighlight.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ public function postprocessSearchResults(ResultSetInterface $results) {
// If a join query is present we will use its current config to trigger a quick
// strawberry flavor solr query to highlight the current returned ADOs/NODE IDs
// based on the existing $results->getQuery()->getOption('sbf_join_flavor') array
if ($results->getQuery()->getOption('sbf_join_flavor') &&
if (($results->getQuery()->getOption('sbf_join_flavor') ||
$results->getQuery()->getOption('sbf_advanced_search_filter_flavor_hl')) &&
$this->configuration['highlight_processing'] == 'backend') {
$fetched_ids = [];
$from_solr_highlight_fields = [];
Expand Down Expand Up @@ -340,7 +341,7 @@ protected function addExcerpts(array $results, array $fulltext_fields, array $ke
'highlighted_keys'
);
if ($highlighted_keys && is_array($highlighted_keys)) {
// first implide all existing keys, makes comparing easier.
// first implode all existing keys, makes comparing easier.
$joined_keys = strtolower(implode(" ", $keys));
foreach($highlighted_keys as $index => $highlighted_key) {
if (strpos($joined_keys, strtolower($highlighted_key)) !== FALSE) {
Expand Down Expand Up @@ -431,6 +432,9 @@ protected function getKeywordsParseModeAware(QueryInterface $query, string $pars
$direct_keys = $query->getOriginalKeys();
$match = [];
$keys = [];
// This assumes we are indeed using phrase escaping (see \Drupal\search_api_solr\Utility\Utility::flattenKeys)
// And not term escaping (which would be desired for single keys
// but then i will not re-write code from \Drupal\search_api_solr!
preg_match_all('/"([^"]+)"/', $direct_keys,$match);
if (isset($match[1]) && is_array($match[1])) {
$keys = array_unique($match[1]);
Expand Down Expand Up @@ -1000,16 +1004,13 @@ public function highlightFlavorsFromIndex(QueryInterface $query, array $entities
// Just in case someone tried to copy the code without understanding, let's be safe
$combined_keys = $query->getOption('sbf_join_flavor')['hl'] ??
($query->getOption('sbf_join_flavor')['v'] ?? NULL);

$combined_querys_query = $query->getOption('sbf_join_flavor')['v'] ?? NULL;
if ($combined_keys && $combined_querys_query
&& is_string($combined_keys) && is_string($combined_querys_query)
&& strlen(
trim($combined_keys)
) > 0
&& strlen(
trim($combined_querys_query)
) > 0
// No join. Try with the Advanced Search Flavor Filter
// Sweet and made for a hit summer of advanced Searching!
// @See \Drupal\format_strawberryfield_views\Plugin\views\filter\AdvancedSearchApiFulltext::query
if (!$combined_keys) {
$combined_keys = $query->getOption('sbf_advanced_search_filter_flavor_hl') ?? NULL;
}
if ($combined_keys && is_string($combined_keys) && strlen(trim($combined_keys)) > 0
) {
$group_options = [
'use_grouping' => TRUE,
Expand Down

0 comments on commit 2a79207

Please sign in to comment.