Skip to content

Commit

Permalink
Issue #3485800 by castanearie, mkalkbrenner: No results when a key co…
Browse files Browse the repository at this point in the history
…nsists only of a backslash
  • Loading branch information
mkalkbrenner committed Nov 15, 2024
1 parent 881d231 commit 5701bb4
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/Utility/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -997,15 +997,28 @@ public static function flattenKeysToPayloadScore($keys, ?ParseModeInterface $par
}
}
elseif ($escaped) {
$k[] = trim($key);
$trimmed = trim($key);
// See the boost_term_payload field type in schema.xml. If we send
// shorter or larger keys then defined by solr.LengthFilterFactory
// we'll trigger a "SpanQuery is null" exception.
if (mb_strlen($trimmed) >= 2 && mb_strlen($trimmed) <= 100) {
$k[] = $trimmed;
}
}
else {
switch ($parse_mode_id) {
case 'terms':
case "sloppy_terms":
case 'fuzzy_terms':
case 'edismax':
$k[] = $queryHelper->escapePhrase(trim($key));
$trimmed = trim($key);
// See the boost_term_payload field type in schema.xml. If we
// send shorter or larger keys then defined by
// solr.LengthFilterFactory we'll trigger a "SpanQuery is null"
// exception.
if (mb_strlen($trimmed) >= 2 && mb_strlen($trimmed) <= 100) {
$k[] = $queryHelper->escapePhrase($trimmed);
}
break;

case 'phrase':
Expand All @@ -1031,15 +1044,7 @@ public static function flattenKeysToPayloadScore($keys, ?ParseModeInterface $par
}
}

// See the boost_term_payload field type in schema.xml. If we send shorter
// or larger keys then defined by solr.LengthFilterFactory we'll trigger a
// "SpanQuery is null" exception.
$k = array_filter($k, function ($v) {
$v = trim($v, '"');
return (mb_strlen($v) >= 2) && (mb_strlen($v) <= 100);
});

if ($k) {
if (!empty($k)) {
$payload_scores[] = ' {!payload_score f=boost_term v=' . implode(' func=max} {!payload_score f=boost_term v=', $k) . ' func=max}';
}
}
Expand Down

0 comments on commit 5701bb4

Please sign in to comment.