Index: roundup/backends/indexer_rdbms.py =================================================================== --- roundup/backends/indexer_rdbms.py (revision 4205) +++ roundup/backends/indexer_rdbms.py (working copy) @@ -92,18 +92,44 @@ return [] if self.db.implements_intersect: - # simple AND search + # ugly AND search sql = 'select distinct(_textid) from __words where _word=%s'%self.db.arg sql = '\nINTERSECT\n'.join([sql]*len(l)) self.db.cursor.execute(sql, tuple(l)) - r = self.db.cursor.fetchall() - if not r: + # fetch message or title escope matches + msg_or_title = self.db.cursor.fetchall() + if msg_or_title: + msg_or_title = tuple([int(row[0]) for row in msg_or_title]) + mt_ids = ','.join([self.db.arg] * len(msg_or_title)) + sql_mt = 'select _class, _itemid, _prop from __textids '\ + 'where _textid in (%s)' % mt_ids + # Ready our huge query for issue escope matches + sql = '''select distinct(nodeid) from issue_messages where linkid in ( +select CAST(_itemid as Integer) from __textids where _textid in ( +select distinct(_textid) from __words where _word=%s))'''%self.db.arg + sql = '\nINTERSECT\n'.join([sql]*len(l)) + self.db.cursor.execute(sql, tuple(l)) + # fetch issue IDs + issue_msgs = self.db.cursor.fetchall() + if issue_msgs: + issue_msgs = tuple([str(i[0]) for i in issue_msgs]) + im_ids = ','.join([self.db.arg] * len(issue_msgs)) + sql_im = 'select _class, _itemid, _prop from __textids '\ + 'where _itemid in (%s)' % im_ids + # If we have both kind of results, join them. Otherwise, provide + # a dummy for the missing kind. + if msg_or_title and issue_msgs: + sql = '\nUNION\n'.join([sql_mt,sql_im]) + elif msg_or_title: + sql = sql_mt + issue_msgs = () + elif issue_msgs: + sql = sql_im + msg_or_title = () + else: + # we have nothing: quit :) return [] - a = ','.join([self.db.arg] * len(r)) - sql = 'select _class, _itemid, _prop from __textids '\ - 'where _textid in (%s)'%a - self.db.cursor.execute(sql, tuple([int(row[0]) for row in r])) - + self.db.cursor.execute(sql, msg_or_title +issue_msgs ) else: # A more complex version for MySQL since it doesn't implement INTERSECT