I am building a search engine, and would like to get your ideas on how to (elegantly) search for individual (whole) words within fields. For instance if I want to search for a book by entering a word (or mulitiple words) into the Title field (of the search form), what is the best way to form the SQL string from these words. The way I've been doing it, is to use the Like Operator in the SQL string, but in order to search for individual (whole) words, I find that I have to use it four times for each word. This is what the WHERE clause looks like for one word (where TitleStr is the word):
"([Title] Like ""*[!a-z]" & TitleStr & "[!a-z]*"" Or [Title] Like """ & TitleStr & "[!a-z]*"" Or [Title] Like ""*[!a-z]" & TitleStr & """ Or [Title] Like """ & TitleStr & """
"
All these cases come about because I have to account for the case where my search word is exactly equal to the title, the case where it is at the beginning of the title, at the end, and in the middle somewhere.
This works, even for multiple words accross multiple fields, but as you can imagine, the resulting SQL string can become pretty ugly.
Any ideas?
Thanks,
JW.
"([Title] Like ""*[!a-z]" & TitleStr & "[!a-z]*"" Or [Title] Like """ & TitleStr & "[!a-z]*"" Or [Title] Like ""*[!a-z]" & TitleStr & """ Or [Title] Like """ & TitleStr & """
All these cases come about because I have to account for the case where my search word is exactly equal to the title, the case where it is at the beginning of the title, at the end, and in the middle somewhere.
This works, even for multiple words accross multiple fields, but as you can imagine, the resulting SQL string can become pretty ugly.
Any ideas?
Thanks,
JW.