I've been trying to do a search solely based on the node title, I dont want to search the the rendered body; is this possible?

I know node->title is indexed by default and is available as a sort by facet but that is not enough.

Any help/insight into this would be helpful.

Comments

Scott Reynolds’s picture

just need to change the search fields in the interface to just title admin/settings/apachesolr/query-fields. Same is true for Apache Solr Views as well ;-)

flk’s picture

Hi Scott thanks for pointing that out, I have been trying to modify the query field using the hook_apachesolr_modify_query

function parliament_solr_apachesolr_modify_query($query, $params, $caller) {
  unset($params['fl'],$params['qf'], $params['bq']);
  $params['fl']='title';
  $params['qf'][] = "title:^21.0";
  $params['bq'][] = "type:member^21.0";
 
}

but for some reason that does not seem to work; having traced how the 'search fields' are stored I thought maybe setting my own fields in the following manner might do the job

variable_set('apachesolr_search_query_fields', array('title' => '21.0'));

Which worked but isn't really what i had in mind, I want to be at a given search page be able to search given fields (basis for query builder?) but when i come back to the main search the fields are back to the default 'search fields' settings

Am I even using the right hook?

Scott Reynolds’s picture

If you need to do it conditionally, I believe only Views solution is there for you because it is the only solution that provides multiple pages. And as if I understand this:

but when i come back to the main search the fields are back to the default 'search fields' settings

That is what you are talking about. And Apache Solr Search Integration provides only one page (search/apachesolr_search), so your little jab about basis for a query builder kindof bounces off ;-).

Apache Solr Views exposes a couple member functions add_boost_function, add_boost_query and add_query_field.

So you can do this with Views

function parliament_solr_apachesolr_modify_query($query, $params, $caller) {
  if ($caller == 'apachesolr_views_query') {
    $query->add_query_field('title', 21.0);
    $query->add_boost_query('type', 'member', 21.0);
  }
}

That should be all you need, just create your View with one field Node Title.

flk’s picture

You've been tremendous help thank you :)

You're are right that views easily provides multiple pages search, since there are no easy way of doing it.

I would like to if it is possible assist in trying to get this functionality into the UI where would you suggest I start things from?

PS your code worked like a charm.

flk’s picture

Status: Active » Closed (fixed)
Andreas Radloff’s picture

I have created a sandbox project module for searching only in specific cck fields, support for title will be added in the future.
http://drupal.org/sandbox/AndreasRadloff/1474818

nick_vh’s picture

6.x-2.x is not supported. I hope your module will also support 6.x-1.x or at least 6.x-3.x?

Andreas Radloff’s picture

Circumstances forced me to choose 2.x for this client project (I needed some of the modules available only for 6.x-2.x). I'm aiming for a 6.x-3.x / 7.x version sometime soon, but as I understand it a lot has changed so I suppose I will need to do a lot of rewriting...