0

I have hook for user_search_execute and node_search_execute for both user and nodes but i want to merge both into mymoduel_search_execute but only node_search_execute uses index not user_search_execute like below :-


    /* node search execute */

    function node_search_execute($keys = NULL, $conditions = NULL) {
        // Build matching conditions
        $query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');
        $query->join('node', 'n', 'n.nid = i.sid');
        $query
            ->condition('n.status', 1)
            ->addTag('node_access')
            ->searchExpression($keys, 'node');

        // Insert special keywords.
        $query->setOption('type', 'n.type');
        $query->setOption('language', 'n.language');
        if ($query->setOption('term', 'ti.tid')) {
            $query->join('taxonomy_index', 'ti', 'n.nid = ti.nid');
        }
        // Only continue if the first pass query matches.
        if (!$query->executeFirstPass()) {
            return array();
        }

        // Add the ranking expressions.
        _node_rankings($query);

        // Load results.
        $find = $query
            ->limit(10)
            ->execute();
        $results = array();
        foreach ($find as $item) {
            // Render the node.
            $node = node_load($item->sid);
            $build = node_view($node, 'search_result');
            unset($build['#theme']);
            $node->rendered = drupal_render($build);

            // Fetch comments for snippet.
            $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node);

            $extra = module_invoke_all('node_search_result', $node);

            $uri = entity_uri('node', $node);
            $results[] = array(
                'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE))),
                'type' => check_plain(node_type_get_name($node)),
                'title' => $node->title,
                'user' => theme('username', array('account' => $node)),
                'date' => $node->changed,
                'node' => $node,
                'extra' => $extra,
                'score' => $item->calculated_score,
                'snippet' => search_excerpt($keys, $node->rendered),
                'language' => entity_language('node', $node),
            );
        }
        return $results;
    }

i want to combine both queries into one even search url anything else.

please help..

1 Answer 1

0

Check our the module Search combine, it gives you exactly that.

Here's how I have the admin search configured:

enter image description here

Also related: How to have a combined search view that shows both users and content on search terms?

7
  • Hi thanks, i have installed it but this module is not working properly because i got some error like "The page isn't redirecting properly" because this url not have any template to render this content.
    – kamal
    Jun 17, 2014 at 10:12
  • any other options...? my url for this is "xyz.com/drupal/?q=search/all/test" drupal don't have any template for this url. that's why browser says "server is redirecting the request for this address in a way that will never complete."
    – kamal
    Jun 17, 2014 at 10:20
  • please help....
    – kamal
    Jun 17, 2014 at 10:25
  • Not sure what might be happening in your site, I've just installed the suggested module using simplytest.me and seems to work correctly with a default drupal install.
    – pcambra
    Jun 17, 2014 at 11:48
  • Not working yet..
    – kamal
    Jun 17, 2014 at 13:37

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .