The way I've solved this in the past is to create an inverted index, eliminating high-frequency words (a, and, the, with, etc.) and then either do:
- linear matches based on what's typed for each word;
- remove vowels; or
- use Soundex.
Whether you do a search for each character that's entered or not is up to you, although this approach is ideal for real-time filtering. (The point is, you're not hitting the database on each character that's typed. You hit it after the first few characters then filter the rest from the results.)
I've done this with both in-memory search tables as well as using database tables.
For an inverted index, you break everything up into words and save a list of record numbers for each word. When the person types 'natio' it shows a list of all records that match any word that starts with the stem 'natio', like 'nation', 'nations', 'national', etc. So 'national' might be found in 25 records, 'nations' might be in 37, and 'nation' might be in 58. Obviously, the longer the stem, the fewer the hits.
If they enter multiple words, treat each word like a separate search, but AND the results together. So 'nation' and 'bank' would only show the results where both word stems are found together.
It's really not all that difficult. First make a list of all the words in the database along with their frequency counts. Eliminate all of the meaningless high-frequency words, and any others that aren't very meaningful. Then build an inverted index from the rest.
If the data changes very frequently, then keep the list of meaningless words around and rebuild your inverted index automatically after updating the inverted word index by removing these words first.
The result isn't all that big, and it should run quite fast if you implement it correctly.
I've never seen a situation where the use of SQL queries with LIKE in them ran anywhere near as fast as this approach.
LIKE
operator with wildcards. Is that available in it's SQL grammar?LIKE '%National%'
, which of course won't use indexes and might be somewhat slower.