Skip to content

Commit

Permalink
Update AdvancedSearchQuery.php
Browse files Browse the repository at this point in the history
Add missing boost number for each field for edismax search
  • Loading branch information
kylehuynh205 authored Jun 20, 2024
1 parent ec0922f commit 9d34cf7
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/AdvancedSearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,25 @@ public function alterQuery(Request $request, SolariumQueryInterface &$solarium_q
}
else {
$query_fields = $fields_list;
}

// Get the indexed fields from /admin/config/search/search-api/index/..../fields
$boostedFields = [];
foreach ($index->getFields() as $field_id => $field) {
$boostedFields[$field_id] = $field->getBoost();
}
$query_fields = implode(" ", array_unique($query_fields));
$dismax->setQueryFields($query_fields);

$str_fields_with_boost = "";
// Adding a boost number for each field)
foreach($query_fields as $solr_field) {
foreach($boostedFields as $indexed_field => $boostnum) {
if(strpos($str_fields_with_boost, $indexed_field) == false && strpos($solr_field, $indexed_field) !== false) {
$str_fields_with_boost .= $solr_field . "^" . $boostnum . " ";
}
}
}

$dismax->setQueryFields($str_fields_with_boost);
}
}

Expand Down

0 comments on commit 9d34cf7

Please sign in to comment.