'Returns a domain with ids of workitem whose `operator` matches  with the given `operand`'

def _search_res_name(self, operator, operand):

    if (not operand):
        return []
    condition_name = [None, operator, operand]
    self.env.cr.execute('\n                                                SELECT    w.id,    w.res_id,    m.model\n                                                FROM    marketing_campaign_workitem    w                                                    LEFT    JOIN    marketing_campaign_activity    a    ON    (a.id=w.activity_id)                                                LEFT    JOIN    marketing_campaign    c    ON    (c.id=a.campaign_id)                                                LEFT    JOIN    ir_model    m    ON    (m.id=c.object_id)\n                                ')
    res = self.env.cr.fetchall()
    workitem_map = {}
    matching_workitems = []
    for (id, res_id, model) in res:
        workitem_map.setdefault(model, {}).setdefault(res_id, set()).add(id)
    for (model, id_map) in workitem_map.iteritems():
        Model = self.env[model]
        condition_name[0] = Model._rec_name
        condition = [('id', 'in', id_map.keys()), condition_name]
        for record in Model.search(condition):
            matching_workitems.extend(id_map[record.id])
    return [('id', 'in', list(set(matching_workitems)))]
