How to override/implement a module's hook Is there a possible to override a module's hook? What I want is, write a search__query_alter() hook to restrict search results. But to achive this, I should write the hook in built-in module search's .module file.

This way, I'm hacking into core drupal files, which must be bad. Is there a way to write the hook for another module in my theme's template.php file or somewhere else, not touching the core drupal files? When I write search_query_alter() in my theme's template.php file it simply doesn't work.

From my question, you may understand I'm very new to Drupal! Thank you for helping.
You must create a custom module and add a custom hook function to it. The function name will be modulename_query_alter ().  Drupal maintains a list of all included hooks by searching the enabled modules for functions following that pattern.

Instructions for creating one are here.  This is the basic means for introducing custom behaviors to your site. The hook system is discussed here and you should look at using the hook_query_alter function here.

This will get you started and no doubt lead to further questions.