I am developing a search function and we have decided that users should be able to search by first name and surname. However it occurred to me that searching for (as a full name) would then return no results. So we have also decided to add it, but should full name also include any middle names?
I am assuming you are talking about one input field that takes a first name or a surname but you want it to also be able to take a full name.
Adding in the option to search for a middle name slightly expands the options a user has for input (assuming middle name is optional) so this is definitely some improvement. There is still the much larger problem here around expecting a certain kind of input from your users.
My name is Benjamin. What would happen if someone searched for "Ben"? Would I still be found? If not, perhaps that points to a flaw in the UX here beyond the fact that someone may wish to search for my full name. Users would have to be told what they can search for and how they should use this functionality. It feels quite clunky to have to say "Search for fist name, last name or full name with optional middle names".
A much more satisfying solution would be to consider some kind of full text search with fuzzy matching. This could take away any need to educate the user on how to use it since it should work like any search input they use virtually everywhere else (search engines, most website search, Operating systems file search, etc).
Name search should work as free text search. Otherwise you are creating nasty edge cases. If someone enters multiple names (first, last, middle), split into words, and search for all of them. Or let a third-party search engine take care of it. (eg Apache Lucene)
Why? Because some people don't have middle names. Some have two or more. Some have two surnames, as is the norm in Spanish-speaking countries.
Patrick McKenzie wrote a wonderful article about these problems: Falsehoods Programmers Believe About Names