function biblio_build_search_query in Bibliography Module 6
Same name and namespace in other branches
- 6.2 includes/biblio.pages.inc \biblio_build_search_query()
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:
1 call to biblio_build_search_query()
File
- ./
biblio.pages.inc, line 807
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 get only nodes where "term1 AND term2"
// match as we demand 2 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} i\n INNER JOIN {node} 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;
}