Searching: Jump to Title Immediately Without Showing Search Results
Last modified: April 18, 2008 - 00:11
Imagine that you'd like, with Drupal's core search module, to jump straight to a node titled, say, "Spinal Tap" by just typing it, rather than having to sift through a bunch of search results. At the same time, you'd like search results when the exact title does not exist among your existing content.
I had this problem and seemingly solved it this way, though your feedback is appreciated for this Drupal noob in case I goofed up.
In search.module, you will find:
<?php
>
function search_box_form_submit($form_id, $form_values) {
return 'search/node/'. trim($form_values[$form_id .'_keys']);
<
?>Replace it with the following to first check whether that title exists in your data base, and then to go to the URL of that title, here prefaced by
movies/. Otherwise, just go ahead and provide search results as you would anyway:
<?php
>
function search_box_form_submit($form_id, $form_values) {
$temp_result = db_query("SELECT n.title FROM {node} n WHERE n.title='%s'", $form_values['search_theme_form_keys']);
$temp_object = db_fetch_object($temp_result);
if($temp_object->title){
return 'movies/' . $form_values['search_theme_form_keys'];
}
else{
return 'search/node/'. trim($form_values[$form_id .'_keys']);
}
<
?>Of course, this isn't confined to titles. All you'd have to do is replace
n.title above with n.whateverfieldyouwanthere
Things get even juicier when you use this with the Search AutoComplete module (http://drupal.org/project/search_autocomplete), where existing titles are suggested as you type.

=-=
core modules should never be hacked. create a seperate module, create a snippet to do this type of task.
_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )