0

I've searched around for any pre-existing solutions to tackle this problem but so far nothing obvious. Here is basically what I'm after:

1) User enters keyword(s) via core search box

2) If user enters a specific keyword from a list of pre-determined keywords, redirect them immediately to a specific URL/node, e.g:

switch ($keyword) {
    case 'brand a':
        drupal_goto('brands/brand-a');
        break;
    case 'brand b':
        drupal_goto('brands/brand-b');
        break;
    default:
       do a regular keyword search . . .
       break;
endswitch;

3) If their keyword doesn't exist in the pre-determined list, shuffle them off to the standard Drupal search

Any ideas on how to best accomplish in Drupal 7?

1 Answer 1

0

If there is only a few you and you don't need any advanced matching you can add a path alias for the search path pointing to the preferred page.

E.g. searching for brand a gives you the path search/node/brand a. This path you can add as a path alias at admin/config/search/path/add pointing to a node of your choice.

For more advanced matching (and a more solid solution) you should probably hook into hook_search_preprocess() and do something along the lines of your example code.

1
  • Thanks both of these worked great -- we actually ended up overriding the core search with a views-based search, and used a views preprocess hook for the redirects and we were able to automate it all by matching terms from a particular vocab and redirecting to the relevant taxonomy term panel.
    – broeker
    Commented May 2, 2013 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.