Hello,

I needed to order (strictly) my search results using the created timestamp from the node, and I found no other "fast" solution than to go into node.module (core node module) and change the following line:

$find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. $join1, $conditions1 . (empty($where1) ? '' : ' AND '. $where1), $arguments1, $select2, $join2, $arguments2, 'ORDER BY n.created DESC, score DESC');

Instead of the regular 'ORDER BY score DESC', I set it as 'ORDER BY n.created DESC, score DESC'.

It works great, but the only issue is that I'd like to be able to achieve the same result without hacking core. Any idea how I could do this with a custom module?

Thanks

Comments

esllou’s picture

can't you go into search settings and alter the weight for "recently posted"...just put it up to 10 and the others to 1.

gafir777’s picture

esllou,

I've tried that but it didn't seem to change anything to the display, even after re-indexing the whole site after changing the ranking factor to 0 for keyword relevancy and 10 to recently posted, I would still get content from 2001 get on top of content from 2010.

Since I really didn't want this to happen at any time, the ORDER by n.created was an absolute solution to this.

I'll test again to change the ranking factor with full weight to the recently posted, but it does not seem to impact the search result as much as I would like it to.

subir_ghosh’s picture

I have been searching for ways to fix this.

It seems to be a Drupal core fallacy.

"Recently posted" assumes date modified, and NOT date created. So that option is redundant.

For the moment, I am settling for this: http://drupal.org/node/13771#comment-2028974

Quite an ugly hack, but seems good.

I wish I could leave the core files alone. Now, I have to remember to do this every time I do a core upgrade.

-----------------------------
Subir Ghosh
www.subirghosh.in

maromba’s picture

i have a very similar issue. i need to alter/ovrride the node_search function. does anyone know how to achieve this? I need to custimize my query string. Thanks!