[16.0] base_search_mail: Bug searching on big messages
Module
base_search_mail_content
Describe the bug
In long messages, it cannot find the words you are looking for.
To Reproduce
Affected versions: 16.0
Steps to reproduce the behavior:
https://www.loom.com/share/9ba5478d5672459bad447cbb3390395e
Expected behavior Find a task that has a message containing the searched words
Additional context Usually, the body of a message is the largest part of it. Using “%” makes it return true, taking into account the similarity between what is being searched for and the content. If the content is very large and we are looking for something very specific, the threshold will be too small to return true and will give a false negative, not finding the content we need.
Suggested fix
As you can see in the video, we have fixed this by specifically changing the body operator to “ilike.”
def _search_message_content(self, operator, value):
model_domain = [("model", "=", self._name)]
if operator not in expression.NEGATIVE_TERM_OPERATORS:
model_domain += ["|"] * 4
model_domain += [
("record_name", operator, value),
("subject", operator, value),
("body", "ilike", value),
("email_from", operator, value),
("reply_to", operator, value),
]
recs = self.env["mail.message"].search(model_domain)
return [("id", "in", recs.mapped("res_id"))]
MT-10818 @moduon cc: @Andrii9090
Thanks! The fix looks good to me. Could you please open the PR? Thanks.