Custom module search ranking not working + ranking admin settings not showing properly I'm using a custom module, with custom content type and custom search implementations and ranking. To rank the results I'm using the votes cast for the posts. But the voting system is custom too, i.e. it uses a custom table and not a standard drupal table. Now the problem is that:


The ranking doesn't work at all. I have set an influence value(content ranking factor) of 1 in the search settings for the ranking.
You know the ranking factors I mentioned above, in the search settings? It will only list my ranking factor, if and only if I enable the node module in the Active Search Modules section. As you might have figured I have my custom module in the Active Search Modules enabled.


Maybe problem #2 is the cause of #1?

The code for the hook_ranking() implementation is as follows:

function knowledge_ranking() {
    return array(
        'post_rating' =&gt; array(
            'title' =&gt; t('Post Rating'),
            'join' =&gt; array(
                'type' =&gt; 'LEFT',
                'table' =&gt; TABLE_POST_VOTES,
                'alias' =&gt; TABLE_POST_VOTES,
                'on' =&gt; TABLE_POST_VOTES . '.pid = i.sid',
            ),
            'score' =&gt; 'vote.average / CAST(:max_rating AS DECIMAL)',
            //I also did the following:
            //'score' =&gt; 'AVG(vote) / CAST(:max_rating AS DECIMAL)',
            'arguments' =&gt; array(':max_rating' =&gt; 5),
        ),
    );
}


It's worth mentioning that I have cleared cache, rerun cron and re-indexed the site several times.

Any help or tips are appreciated, thanks :-)

Update 1:

Solved #2

You need to implement yourmodule_search_admin() and from there return that part  of the form.

Update 2:

I'm pretty sure that problem #1 lies within this line:

'score' =&gt; 'vote.average / CAST(:max_rating AS DECIMAL)',


So now I guess I have to put the average rating for each post in a field in the posts table. But there are gonna be a lot of more factors. So now the question is can't we use such complex scores at all?
Finally I cracked this frigging case!
As it turns out, there was no way for anyone to be able to answer this question since my given information was incomplete. Although in my defence if I knew that I should've given that info, I would've solved the problem long ago(two days) :-D.

Solving problem #1:

Dead simple! In my case I had commented out the following line inside hook_search_execute():

_node_ranking($query);


this functions adds the rankings to the results.

Solving problem #2:

As for this problem, the influence choosing form doesn't show up automatically. The node module, if active in the Active search modules, lists all the factors for all Search active modules. But for a module to list its own factors, it must implement the hook_search_admin() function like this:

function hook_search_admin() {
  // Output form for defining rank factor weights.
  $form['post_ranking'] = array(
    '#type' =&gt; 'fieldset',
    '#title' =&gt; t('Post ranking'),
  );
  $form['post_ranking']['#theme'] = 'node_search_admin';
  $form['post_ranking']['info'] = array(
    '#markup' =&gt; '&lt;p&gt;&lt;em&gt;' . t('Influence is a numeric multiplier used in ordering search results. A higher number means the corresponding factor has more influence on search results; zero means the factor is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . '&lt;/em&gt;&lt;/p&gt;'
  );

  // Note: reversed to reflect that higher number = higher ranking.
  $options = drupal_map_assoc(range(0, 10));
  foreach (knowledge_ranking() as $var =&gt; $values) {
    $form['post_ranking']['factors']['node_rank_' . $var] = array(
      '#title' =&gt; $values['title'],
      '#type' =&gt; 'select',
      '#options' =&gt; $options,
      '#default_value' =&gt; variable_get('node_rank_' . $var, 0),
    );
  }
  return $form;
}