Is there a way (hook or other) to add my own bias settings to use? I need to be able to sort the result by a CCK field, i.e. have nodes with a certain value higher up in the list.

Also, what is the default sort order? Is this changeable?

Comments

pwolanin’s picture

The default sort order is by relevancy - i.e. the best match comes first.

janusman’s picture

To me this idea would something like a hook that allows index-time boosts per node defined by modules...

Something like:

/**
 * Implementation of hook_apachesolr_node_boost().
 * Returns an integer with a boost factor to be injected at indexing time; return false for no boost.
 */
function mymodule_apachesolr_node_boost($node) {
  if ($node->field_foo[0]['value'] == "foobar") {
    return 500;
  }
  if ($node->sticky) {
    return 10000;
  }
  return false;
}

Question: Would the module author must also need to specify when a node needs reindexing? Or is that handled automatically after every node submission/insertion?

A common use case for this hook (that perhaps could ship with v1 of the module?) could be handling node stickiness in search results. This was touched way back in this comment.

pwolanin’s picture

@janusman - in this case, why not alter the query parameters to add a boost function? I guess you'd need to make sure the field in question was indexed. We have been avoiding index-time boosts for the obvious reason that changing it requires re-indexing.

janusman’s picture

@blackdog: @pwolanin told me the one answer for this: use hook_apachesolr_modify_query():

function mymodule_apachesolr_modify_query(&$query, &$params) {
  // I only want to see articles by the admin!
  $params['bq'][] = "tid:123^10.0"; // This boosts nodes that have tid:123
}

So you just need to replace tid:123 with your CCK field's name in the Solr index.

blackdog’s picture

Status: Active » Fixed

Great stuff!

The biggest problem was getting my CCK field indexed, found another hook for that which worked though (hook_apachesolr_update_index) and added the field to the schema.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.