Posted by karma.code on August 2, 2010 at 10:42pm
I would like to query ApacheSOLR to return results based on one field in a node but I do not know how to do this. For example, instead of searching for the word 'dog' in a node's title, body, created date, etc, I only want to search the node title for the word 'dog'.
Can I do this using by implementing hook_apachesolr_modify_query? Any feedback on this would be much appreciated.
Categories: ApacheSolr
Comments
I have even done this hoping
I have even done this hoping that only title would remain to be searched and this still did not work:
function hook_apachesolr_modify_query(&$query, &$params, $caller){if($caller == 'solr_ui_autocomplete'){
$fields =& apachesolr_get_solr()->getFields();
foreach($fields as $key => $value){
if($key !== 'title'){
// remove everything except for the title field to search on
unset($fields->$key);
}
}
}
}
Am I getting warmer? colder?
Warmer.
In the same hook, you want to override the three following parameters:
<?php$params['fl'] = $field_name;
$params['qf'][] = "{$field_name}^1.0";
$params['hl.fl'] = "$field_name";
?>
That example (slightly modified) is taken from the contrib/apachesolr_text module (available in the 6.x-2.x branch), which I suggest you study.
Thank you Robert. I am glad I
Thank you Robert. I am glad I came back to this post. I ended up figuring out to override the element awhile back. I can also do:
<?php$query->add_filter('title', $value);
$params['fl'] = 'title';
?>
Custom Scoring Each node
We are building a customized Scoring module for the Apache Solr Results.
The Custom function reads:
function hook_apachesolr_modify_query(&$query, &$params, $caller) {
}
In the above function
we assigned score to this is_field_mytestval ....
There is so difference tin the results, the above Query doesnot get exact result.