Skip to content

Commit

Permalink
LIB-661 remove "and" + "&" from title and keyword searches
Browse files Browse the repository at this point in the history
  • Loading branch information
bricas committed Sep 19, 2024
1 parent d06fb78 commit b296fc5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions custom/modules/eresources/src/Form/KbFormBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,17 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form[$form_wrapper]['type']['#default_value'] = $req->get('type');

// $form['results_header'] = ['#markup' => '<h2 class="mt-3">Results</h2>'];
$stopWords = ['and', '&'];
$cleanQuery = preg_replace('/\b(' . implode('|', $stopWords) . ')\b/i', '', $query);
$cleanQuery = trim(preg_replace('/\s+/', ' ', $cleanQuery));

$search = [
'title' => $query,
'title' => $cleanQuery,
'orderBy' => 'title asc',
];
switch ($req->get('type')) {
case 'keyword':
$search = ['q' => $query];
$search = ['q' => $cleanQuery];
break;

case 'exact':
Expand Down

0 comments on commit b296fc5

Please sign in to comment.