You are here

function biblio_search_query in Bibliography Module 7

Same name and namespace in other branches
  1. 7.2 includes/biblio.pages.inc \biblio_search_query()
1 call to biblio_search_query()
biblio_build_query in includes/biblio.pages.inc
Biblio_db_search builds the SQL query which will be used to select and order "biblio" type nodes. The query results are then passed to biblio_show_results for output.

File

includes/biblio.pages.inc, line 958
Copyright (C) 2006-2011 Ron Jerome.

Code

function biblio_search_query($keys) {
  if (!empty($keys)) {
    $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
      ->execute();
    $nids = array();
    foreach ($find as $item) {
      $nids[] = $item->sid;
    }
    return $nids;
  }
}