function apachesolr_search_add_boost_params in Apache Solr Search 6.2
Same name and namespace in other branches
- 8 apachesolr_search.module \apachesolr_search_add_boost_params()
- 5.2 apachesolr_search.module \apachesolr_search_add_boost_params()
- 6.3 apachesolr_search.module \apachesolr_search_add_boost_params()
- 6 apachesolr_search.module \apachesolr_search_add_boost_params()
- 7 apachesolr_search.module \apachesolr_search_add_boost_params()
1 call to apachesolr_search_add_boost_params()
- apachesolr_search_execute in ./
apachesolr_search.module - Execute a search results based on keyword, filter, and sort strings.
File
- ./
apachesolr_search.module, line 525 - Provides a content search implementation for node content for use with the Apache Solr search application.
Code
function apachesolr_search_add_boost_params(&$params, $query, $solr) {
// Note - we have query fields set in solrconfig.xml, which will operate when
// none are set.
$qf = variable_get('apachesolr_search_query_fields', array());
$fields = $solr
->getFields();
if ($qf && $fields) {
foreach ($fields as $field_name => $field) {
if (!empty($qf[$field_name])) {
if ($field_name == 'body') {
// Body is the only normed field.
$qf[$field_name] *= 40.0;
}
$params['qf'][] = $field_name . '^' . $qf[$field_name];
}
}
}
$data = $solr
->getLuke();
if (isset($data->index->numDocs)) {
$total = $data->index->numDocs;
}
else {
$total = db_result(db_query("SELECT COUNT(nid) FROM {node}"));
}
// For the boost functions for the created timestamp, etc we use the
// standard date-biasing function, as suggested (but steeper) at
// http://wiki.apache.org/solr/DisMaxRequestHandler
// rord() returns 1 for the newset doc, and the number in the index for
// the oldest doc. The function is thus: $total/(rord()*$steepness + $total).
$date_settings = variable_get('apachesolr_search_date_boost', '4:200.0');
list($date_steepness, $date_boost) = explode(':', $date_settings);
if ($date_boost) {
$params['bf'][] = "recip(rord(created),{$date_steepness},{$total},{$total})^{$date_boost}";
}
// Boost on comment count.
$comment_settings = variable_get('apachesolr_search_comment_boost', '0:0');
list($comment_steepness, $comment_boost) = explode(':', $comment_settings);
if ($comment_boost) {
$params['bf'][] = "recip(rord(comment_count),{$comment_steepness},{$total},{$total})^{$comment_boost}";
}
// Boost for a more recent comment or node edit.
$changed_settings = variable_get('apachesolr_search_changed_boost', '0:0');
list($changed_steepness, $changed_boost) = explode(':', $changed_settings);
if ($changed_boost) {
$params['bf'][] = "recip(rord(last_comment_or_change),{$changed_steepness},{$total},{$total})^{$changed_boost}";
}
// Boost for nodes with sticky bit set.
$sticky_boost = variable_get('apachesolr_search_sticky_boost', 0);
if ($sticky_boost) {
$params['bq'][] = "sticky:true^{$sticky_boost}";
}
// Boost for nodes with promoted bit set.
$promote_boost = variable_get('apachesolr_search_promote_boost', 0);
if ($promote_boost) {
$params['bq'][] = "promote:true^{$promote_boost}";
}
// Modify the weight of results according to the node types.
$type_boosts = variable_get('apachesolr_search_type_boosts', array());
if (!empty($type_boosts)) {
foreach ($type_boosts as $type => $boost) {
// Only add a param if the boost is != 0 (i.e. > "Normal").
if ($boost) {
$params['bq'][] = "type:{$type}^{$boost}";
}
}
}
}