comments are excluded from search results ATM

Comments

nedjo’s picture

I tried the following code to include comments in the general node search, but commented it out as it led to no results being returned. The code adds c.subject and c.comment to the list of fields being selected and creates a join between the comments and node fields. Any suggestions as to why this doesn't work?


// When comments are included, no results are returned.  What is the problem?
//  if (module_exist('comment')) {
//    $query->fields[] = 'c.subject';
//    $query->fields[] = 'c.comment';
//    $query->joins .= ' INNER JOIN {comments} c ON n.nid = c.nid';
//  }

kbahey’s picture

Nedjo

I also noticed this comment in function node_trip_search()

// When comments are included, no results are returned. What is the problem?
// if (module_exist('comment')) {
// $query->fields[] = 'c.subject';
// $query->fields[] = 'c.comment';
// $query->joins .= ' INNER JOIN {comments} c ON n.nid = c.nid';
// }

I think the reason is that this is an INNER JOIN. So it tries to join nodes to comments, and since not all nodes have comments, this does not work.

Try a LEFT JOIN instead and see if it works.

nedjo’s picture

Yep, thanks kblahey, that worked.

Anonymous’s picture

Anonymous’s picture

Anonymous’s picture

Anonymous’s picture

Anonymous’s picture

Anonymous’s picture

Anonymous’s picture

Anonymous’s picture

Anonymous’s picture

Status: Fixed » Closed (fixed)