Skip to content

Commit

Permalink
Merge pull request #49 from digitalutsc/kylehuynh205-patch-1
Browse files Browse the repository at this point in the history
Adding boost number for each fields for edismax query
  • Loading branch information
rosiel authored Jul 3, 2024
2 parents ec0922f + 9d34cf7 commit bc7c2f6
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 bc7c2f6

Please sign in to comment.