I'm trying to use the a dismax setting the qt param and then calling apachesolr _search_search function but this function is adding the hash fiter in the query but dismax does not support fielded searches through the regular query.
Is there a workaround for this?

Thanks!
Matias.

CommentFileSizeAuthor
#4 hash_before_hook.patch1.1 KBandrewlevine

Comments

mburak’s picture

Any word about this? Or maybe someone telling me how is the right way to do a dismax search.

Thanks!

dipen chaudhary’s picture

Dismax is the standard request handler as of solr 1.3, If you wish to use the standard query handler which allows for detailed lucene operators u'd use q.alt. Dismax is for simple queries on predefined fields which u pass as part of the request or defined in your configuration xml's. Can you be more specific on which "hash filter in the query" u mean here? I've not used q.alt

Oh btw which solr version?

mburak’s picture

Thanks for your reply Dipen. I'm using the last nightly build of solr 1.4.

Basically what i'm trying to do is the following:

I've defined a request handler un my solrconfig.xml:

<requestHandler name="dismaxDPCMarketplace" class="solr.SearchHandler" >
    <lst name="defaults">
     <str name="defType">dismax</str>
     <str name="echoParams">explicit</str>
     <str name="fq">type:(marketplace OR restaurant)</str>
     <float name="tie">1.0</float>
     <str name="qf">
        taxonomy_tree_text^25 keyword^20 title^20 phone thefacts moreinfo reviews webaddress street city state zip country ssfield_premium_restaurant link_text
     </str>
     <str name="pf">
        taxonomy_tree_text^25 keyword^20 title^20 phone thefacts moreinfo reviews webaddress street city state zip country ssfield_premium_restaurant link_text
     </str>
     <str name="fl">*</str>
     <int name="ps">100</int>
     <str name="q.alt">*:*</str>
    </lst>
  </requestHandler>

Then, in a custom module I'm setting this variable:

function marketplace_search_apachesolr_modify_query(&$query, &$params) {
  $params['qt'] = "dismaxDPCMarketplace";
}

and finally in another function, I'm calling the original apachesolr_search_search('search', $keys), but this function is adding at some point the hash field to the query:

$hash = md5(url(NULL, NULL, NULL, TRUE));
$query->add_field('hash', $hash);

The problem is that dismax doesn't allow fields in the q param. It takes them as regular keywords.

andrewlevine’s picture

StatusFileSize
new1.1 KB

So what we can do is move the addition of the hash field above the apachesolr_modify_query hook. That means that a module could take the field out when using dismax. If the attached patch is accepted to the module, the following hook would make dismax work:

function hook_apachesolr_modify_query(&$query, &$params) {
   //dismax doesn't support hash in the query, we'll add it in bq
   $query->remove_field('hash');
   //use dismax query handler because it can weight fields
   $params['qt'] = 'dismax';
   //take all fields into account
   $params['fl'] = '*';
   //weight title higher
   $params['qf'] = 'title^2.0';
   //add site hash back in
   $params['bq'] = 'hash:' . md5(url(NULL, NULL, NULL, TRUE));
}
andrewlevine’s picture

Status: Active » Needs review
CKoch’s picture

That code won't work with the default apachesolr.xml as it stands.

The main issue is that the 'qf' field if explictly set, overrides the default value.

So, in the example above, that will search _only_ the title field.

What needs to be done is enforcement of the type of the parameters.

  // Search the content, and the title weighed higher
  $params['qf'][] = 'title^2.0';
  $params['qf'][] = 'text';

Also, the filter for the hash must be added into fq rather than bq (filtering, vs boosting results. bq will just weight results with the hash higher, but you still get results where the hash doesn't match)

 $params['fq'][] = 'hash:' . md5(url(NULL, NULL, NULL, TRUE));

Also, the function will need to take into account it's operating in a hook context and that it doesn't wipe out any modules alterations to the parameters.

andrewlevine’s picture

CKoch, thanks. Just to be clear, my sample hook code was wrong, but the patch worked :)

jpmckinney’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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