function biblio_build_search_query in Bibliography Module 6.2
Same name and namespace in other branches
- 6 biblio.pages.inc \biblio_build_search_query()
Creates a query for the do_search algorithm in seach module.
Build the query following the do_search algorithm in search.module. Unfortunately we cannot reuse anything from do_search as everything is hard-coded :-(
Parameters
$keys: (optional)
Return value
false|database resource
1 call to biblio_build_search_query()
- biblio_db_search in includes/
biblio.pages.inc - Page callback: Displays a listing of biblio type of content.
File
- includes/
biblio.pages.inc, line 903 - Functions in the biblio module related to filtering and page generation.
Code
function biblio_build_search_query($keys = '') {
if ($keys != '') {
$query = search_parse_query($keys);
if ($query[2] == '') {
form_set_error('keys', t('You must include at least one positive keyword with @count characters or more.', array(
'@count' => variable_get('minimum_word_size', 3),
)));
return FALSE;
}
if ($query === NULL || $query[0] == '') {
return FALSE;
}
$where = '(' . $query[2] . ')';
$args = $query[3];
if (!$query[5]) {
$where .= " AND ({$query[0]})";
$args = array_merge($args, $query[1]);
$join = " INNER JOIN {search_dataset} d ON i.sid = d.sid AND i.type = d.type";
}
// The COUNT ensures that we only get nodes where "term1 AND term2" match as
// we demand two matches. Note that this doesn't work when using the partial
// word search patch.
$args[] = $query[4];
$query = "SELECT distinct(i.sid) FROM {search_index} AS i\n INNER JOIN {node} AS n ON n.nid = i.sid\n {$join}\n WHERE n.status = 1 AND (n.type = 'biblio')\n AND {$where}\n AND i.type = 'node'\n GROUP BY i.type, i.sid HAVING COUNT(*) >= %d";
return db_query(db_rewrite_sql($query), $args);
}
return FALSE;
}