Index: modules/trip_search/trip_search.module
===================================================================
--- modules/trip_search/trip_search.module (revision 837)
+++ modules/trip_search/trip_search.module (working copy)
@@ -255,7 +255,7 @@
}
// 4C - get the corresponding nodes
- if ($find = trip_search_get('node', $parsed_keys)) {
+ if ($find = trip_search_get('node', $parsed_keys) + trip_search_get('comment', $parsed_keys)) {
if (variable_get('trip_search_rank_results', 1)) {
$results = trip_search_rank_results($find, $parsed_keys);
}
@@ -1431,9 +1431,9 @@
else {
return;
}
-print $where;
-dprint_r($query->wheres);
-dprint_r($query->params);
+//print $where;
+//dprint_r($query->wheres);
+//dprint_r($query->params);
$sql = "SELECT DISTINCT(t.tid), " . $query->selects . " FROM {term_data} t " . $query->joins . $where;
$result = db_query_range($sql, $query->params, 0, $max);
@@ -1467,7 +1467,7 @@
}*/
function node_trip_search($keys, $op = 'nodes') {
- $max = variable_get('trip_search_query_max', 500);
+ $max = variable_get('trip_search_query_max', 500); //unused
$use_security = variable_get('trip_search_secure', 0) == 1 ? TRUE : FALSE;
$query->selects = 'n.title,n.type,nr.body,n.sticky';
$query->search_string = '';
@@ -1499,27 +1499,18 @@
// $query->joins .= ' LEFT JOIN {files} f ON n.nid = f.nid';
$query->joins = ' INNER JOIN {node_revisions} nr ON n.vid = nr.vid';
-// COMMENTS WILL BE ADDED BACK LATER
-/* if (module_exist('comment')) {
- $query->fields[] = 'c.subject';
- $query->fields[] = 'c.comment';
- $query->joins .= ' LEFT JOIN {comments} c ON n.nid = c.nid';
- }*/
- if (module_exist('statistics') && variable_get('statistics_count_content_views', 0)) {
+ if (module_exist('statistics') && variable_get('statistics_count_content_views', 0)) {
$query->selects .= ',nc.totalcount';
$query->joins .= ' INNER JOIN {node_counter} nc ON n.nid = nc.nid';
$query->order_bys[] = 'nc.totalcount DESC';
}
if ($keys->uid) {
- $query->joins .= ' INNER JOIN {users} u ON n.uid = u.uid ';
-// $query->wheres[] = 'u.uid = ' . $keys->uid;
- $query->wheres[] = 'u.uid = %s';
+ $query->wheres[] = 'n.uid = %s';
$query->params[] = $keys->uid;
}
elseif ($keys->user) {
if ($user = db_fetch_object(db_query("SELECT uid, name FROM {users} WHERE name = '%s'", $keys->user))) {
- $query->joins .= ' INNER JOIN {users} u ON n.uid = u.uid ';
- $query->wheres[] = 'u.uid = ' . $user->uid;
+ $query->wheres[] = 'n.uid = ' . $user->uid;
}
else {
drupal_set_message(t('Requested user "%user" not found.', array('%user' => $keys->user)), 'error');
@@ -1536,15 +1527,14 @@
$query->wheres[] = 'n.created < ' . $keys->before;
}
}
- if ($keys->type) {
- $types = array();
- foreach ($keys->type as $type) {
-// $types[] = '(n.type = "' . $type . '")';
- $types[] = '(n.type = "%s")';
- $query->params[] = $type;
- }
- $query->wheres[] = '(' . implode(' OR ', $types) . ')';
+ if (count($keys->type) > 1) {
+ $query->wheres[] = 'n.type IN ("%s"'. str_repeat(',"%s"', count($keys->type)-1) .')';
+ $query->params = array_merge($query->params, $keys->type);
}
+ elseif (count($keys->type) == 1) {
+ $query->wheres[] = 'n.type = "%s"';
+ $query->params[] = $keys->type[0];
+ }
if ($keys->term) {
$depth = 0;
foreach ($keys->term as $index => $tid) {
@@ -1578,15 +1568,15 @@
//print '
';
trip_search_expand_query($query, $keys);
}
-print '
After expansion
';
-print_r($query);
-print '
';
+//print '
After expansion
';
+//print_r($query);
+//print '
';
switch ($op) {
case 'find':
$sql = "SELECT n.nid, " . $query->selects . " FROM {node} n " . $query->joins . " WHERE n.status = 1 AND " . implode(" AND ", $query->wheres) . " ORDER BY " . implode(",", $query->order_bys);
// Debug print to display generated SQL
- print 'find '.$sql.'
';
- print_r($query->params);
+// print 'find '.$sql.'
';
+// print_r($query->params);
// print '
find expanded '.db_rewrite_sql($sql,'n','nid',$query->params).'
';
$result = db_query_range(db_rewrite_sql($sql), $query->params, 0, 500);
// $result = db_query($sql, $query->params);
@@ -1610,7 +1600,7 @@
case 'terms':
$sql = "SELECT DISTINCT(t.tid), t.name, COUNT(n.nid) AS count FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {term_data} t ON r.tid = t.tid " . $query->joins . " WHERE n.status = 1 AND " . implode(" AND ", $query->wheres) . " GROUP BY t.name ORDER BY t.name";
// Debug print to display generated SQL
- print 'terms '.$sql.'
';
+// print 'terms '.$sql.'
';
$result = db_query(db_rewrite_sql($sql), $query->params);
$terms = array();
while ($term = db_fetch_object($result)) {
@@ -1620,7 +1610,7 @@
case 'types':
$sql = "SELECT DISTINCT(n.type), COUNT(n.nid) AS count, n.nid, " . $query->selects . " FROM {node} n " . $query->joins . " WHERE n.status = 1 AND " . implode(" AND ", $query->wheres) . " GROUP BY n.type ORDER BY n.type";
// Debug print to display generated SQL
- print 'types '.$sql.'
';
+// print 'types '.$sql.'
';
$result = db_query(db_rewrite_sql($sql), $query->params);
$types = array();
while ($type = db_fetch_object($result)) {
@@ -1640,4 +1630,110 @@
}
return;
}
+
+function comment_trip_search($keys) {
+ if (!module_exist('comment')) {
+ return;
+ }
+ $max = variable_get('trip_search_query_max', 500); //unused
+ $query->selects = 'n.title,n.type,nr.body,n.sticky';
+ $query->joins .= ' INNER JOIN {comments} c ON n.nid = c.nid';
+ if (variable_get('trip_search_type', 'mysql_full') == 'mysql_full') {
+ if ($query = trip_search_translate_keys($keys, 'mysql_full', &$query)) {
+ if ($keys->exclude && !$keys->require) {
+ $exclusion = 'NOT ';
+ $query->search_string = str_replace('-', '', $query->search_string);
+ }
+ else {
+ $exclusion = '';
+ }
+ $query->wheres[] = $exclusion . 'MATCH (c.subject,c.comment) AGAINST (\'' . $query->search_string . '\' IN BOOLEAN MODE)';
+ }
+ }
+ else {
+ $query->fields = array('c.subject', 'c.comment');
+ }
+
+ $query->joins .= ' LEFT JOIN {node_revisions} nr ON n.vid = nr.vid';
+
+ if (module_exist('statistics') && variable_get('statistics_count_content_views', 0)) {
+ $query->selects .= ',nc.totalcount';
+ $query->joins .= ' INNER JOIN {node_counter} nc ON n.nid = nc.nid';
+ $query->order_bys[] = 'nc.totalcount DESC';
+ }
+ if ($keys->uid) {
+ $query->wheres[] = 'c.uid = '. $keys->uid;
+ }
+ elseif ($keys->user) {
+ if ($user = db_fetch_object(db_query("SELECT uid, name FROM {users} WHERE name = '%s'", $keys->user))) {
+ $query->wheres[] = 'c.uid = '. $user->uid;
+ }
+ else {
+ // node_trip_search will report this error
+ return array();
+ }
+ }
+ if ($keys->after && $keys->before) {
+ $query->wheres[] = 'c.timestamp BETWEEN '. $keys->after .' AND '. $keys->before;
+ }
+ else if ($keys->after) {
+ $query->wheres[] = 'c.timestamp > '. $keys->after;
+ }
+ else if ($keys->before) {
+ $query->wheres[] = 'c.timestamp < '. $keys->before;
+ }
+ if (count($keys->type) > 1) {
+ $query->wheres[] = 'n.type IN ("%s"'. str_repeat(',"%s"', count($keys->type)-1) .')';
+ $query->params = array_merge($query->params, $keys->type);
+ }
+ elseif (count($keys->type) == 1) {
+ $query->wheres[] = 'n.type = "%s"';
+ $query->params[] = $keys->type[0];
+ }
+ if ($keys->term) {
+ $depth = 0;
+ foreach ($keys->term as $index => $tid) {
+ $term = taxonomy_get_term($tid);
+ $tree = taxonomy_get_tree($term->vid, $tid, -1, $depth);
+ $descendant_tids[] = array_merge(array($tid), array_map('_taxonomy_get_tid_from_term', $tree));
+ }
+
+ if ($keys->tid_operator == 'OR') {
+ $str_tids = implode (',', call_user_func_array('array_merge', $descendant_tids));
+ $query->joins .= ' INNER JOIN {term_node} tn ON n.nid = tn.nid ';
+ $query->wheres[] = 'tn.tid IN ('. $str_tids .')';
+ }
+ else {
+ foreach ($descendant_tids as $index => $tids) {
+ $query->joins .= ' INNER JOIN {term_node} tn'. $index .' ON n.nid = tn'. $index .'.nid';
+ $query->wheres[] = 'tn'. $index .'.tid IN ('. implode (',', $tids) .')';
+ }
+ }
+ }
+ $query->order_bys[] = 'n.sticky DESC';
+ $query->order_bys[] = 'n.created DESC';
+ if ($query->fields) {
+ $query = trip_search_expand_query($query, $keys);
+ }
+ else if ($query->match) {
+ $query->wheres[] = $query->match;
+ }
+ $sql = 'SELECT n.nid, '. $query->selects .' FROM {node} n '. $query->joins .' WHERE n.status = 1 AND '. implode(' AND ', $query->wheres) .' ORDER BY '. implode(',', $query->order_bys);
+ $result = db_query_range(db_rewrite_sql($sql), $query->params, 0, 500);
+ if ($num = db_num_rows($result)) {
+ while ($node = db_fetch_object($result)) {
+ if (!$find[$node->nid]) {
+ $find[$node->nid]['score'] = 0;
+ if ($node->totalcount) {
+ $find[$node->nid]['hits'] = $node->totalcount;
+ }
+ $find[$node->nid]['id'] = $node->nid;
+ $find[$node->nid]['title'] = $node->title;
+ $find[$node->nid]['snippet'] = $node->body;
+ $find[$node->nid]['promote'] = $node->sticky;
+ }
+ }
+ }
+ return $find;
+}
?>