2

I would like to build a custom search module in Drupal 6 for searching through CCK. I need the user to search between his nodes (node.uid=x) and of a certain type (type='xyz'). I think I have to implement hook_search but I don't know where to put my filters. Can anyone help me?

iknow
  • 8,358
  • 12
  • 41
  • 68
Cris
  • 12,124
  • 27
  • 92
  • 159

3 Answers3

2

You already accepted an answer (which is probably the best option for you), but there are a few other ways to accomplish this.

IIRC, the Custom Search module will work for what you want.

You can copy the stock hook_search function to a custom module and modify the query. You can do something like this:


// ...
case 'search':
    // Build matching conditions
    list($join1, $where1) = _db_rewrite_sql();
    $arguments1 = array();
    $conditions1 = 'n.status = 1';

    // NEW BIT START
    $allowed = array(
        'content_type_1',
        'content_type_2',
        'content_type_3',
    );

    $types = array();
    foreach ($allowed as $t) {
        $types[] = "n.type = '%s'";
        $arguments1[] = $t;
    }
    $conditions1 .= ' AND ('. implode(' OR ', $types) .')';
    $keys = search_query_insert($keys, 'type');
    // NEW BIT END

This replaces the bit that extracts the type from the actual query string.

You would have to add in the bit to restruct to a particular n.uid. I have been using this method lately, rather that Custom Search, because it simpler from the user's perspective.

HTH

mpdonadio
  • 2,891
  • 3
  • 35
  • 54
1

You might try creating a Views with an exposed filter, it's the absolute easiest way to implementing your idea.

dkinzer
  • 32,179
  • 12
  • 66
  • 85
0

Also you can try use CCK Facets. But Views - of course simple.

Nikit
  • 5,128
  • 19
  • 31