Searching on only one SOLR field

Events happening in the community are now at Drupal community events on www.drupal.org.
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:

Comments

I have even done this hoping

Posted by karma.code on August 2, 2010 at 11:33pm

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.

Posted by robertdouglass on September 12, 2010 at 12:37pm

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

Posted by karma.code on September 24, 2010 at 6:03pm

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

Posted by jaffarcheckout on February 23, 2011 at 10:02am

We are building a customized Scoring module for the Apache Solr Results.

The Custom function reads:

function hook_apachesolr_modify_query(&$query, &$params, $caller) {

$params['bf'][] = "recip(rord(is_field_mytestval),1000,1000,1000)^200";

}

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.

Lucene, Nutch and Solr

Group organizers

Group categories

Projects

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /