An old thread but faced the same problem and wanted to share my solution.
I did it for dovecot 2.2.21 and seems to be working fine for me. In lib-storage/mail-search.c I commented out the two *have_body = true assignments. So far no side effects apart from the obvious no search in message bodies. Still search text will search in headers. If search bodies is required (i.e. results are expected) but one does not want for actually searching in the bodies but headers only then the have_body = true may be replaced by a have_text = true.
Assuming you are rebuilding the same version as the one currently installed, the library that is to be replaced is libdovecot-storage.
As a side note: I always advise my users to have proper e-mail subjects for adequate searches. A subject with a single word "problem" doesn't help a lot when it comes to a search even within the body.