Query expansion is used to try to widen the range of returned full-text search results. Consider the following scenario. You want to find all notes with references toanvils in them. Only one note contains the word anvils, but you also want any other rows that may be related to your search, even if the specific word anvils is not contained within them.
This is a job for query expansion. When query expansion is used, MySQL makes two passes through the data and indexes to perform your search:
1. First, a basic full-text search is performed to find all rows that match the search criteria.
2. Next, MySQL examines those matched rows and selects all useful words (we'll explain how MySQL figures out what is useful and what is not shortly).
3. Then, MySQL performs the full-text search again, this time using not just the original criteria, but also all of the useful words.
- SELECT note_text
- FROM productnotes
- WHERE Match(note_text) Against('anvils' WITH QUERY EXPANSION);