Include comments in search in The Bug Genie

4th April, 2013 - Posted by david

Back in July, I was given the task of finding a decent, preferably PHP-based, bug-tracking system and opted for The Bug Genie, as it had pretty much everything we wanted: email notifications, tickets grouped by project, various levels of user access and more. One thing we noticed however, was that when you searched all issues for a particular string, The Bug Genie only searched the main issue text and omitted any text in the comments. This wasn’t ideal, so I went through the source code, found where the searches were being performed and wrote a short hack to get what I wanted. I must stress, this is a hack and I’m sure could be done alot more elegantly! I just didn’t have the time to tidy it up.

What the code does is perform a simple LIKE on the comments table for your search term, gets each comment’s parent’s issue ID and includes any issues with the set of matched IDs in the main search results. The code snippet below is to go in function findIssues in core/classes/B2DB/TBGIssuesTable.class.php. I’ve included the few lines of code directly above where my code needs to be inserted:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// ... rest of function findIssues above
if ($filter_info['operator'] == '=')
{
  $ctn = $crit->returnCriterion(self::TITLE, $searchterm, Criteria::DB_LIKE);
  $ctn->addOr(self::DESCRIPTION, $searchterm, Criteria::DB_LIKE);
  $ctn->addOr(self::REPRODUCTION_STEPS, $searchterm, Criteria::DB_LIKE);
  $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $searchterm, Criteria::DB_LIKE);
  //****** my code begins here
  // manually connect to DB
  $c = mysqli_connect(Core::getHost(), Core::getUname(), Core::getPasswd(), Core::getDBname());
  // search comments table for the text you're looking for
  $query = mysqli_query($c, 'SELECT target_id FROM tbg3_comments WHERE content LIKE \''.mysqli_real_escape_string($c, $searchterm).'\'');
  // if we've matches, build up an array
  $ids = array();
  while ($row = mysqli_fetch_row($query))
  {
    $ids[] = $row[0];
  }
  if (count($ids))
  {
    // add clause to map any found target_ids on the comments table to actual id's on the issues table
    $ctn->addOr(self::ID, $ids, Criteria::DB_IN);
  }
  //****** rest of function can continue on
}
else {
  // etc.

Tags: bug genie mysql php | david | 4th Apr, 2013 at 18:57pm | No Comments

No Comments

Leave a reply

You must be logged in to post a comment.