Tag Archives: search

Introduction to MySQL Query Expansion – Part 1

12 Sep

We all know that back in stone age, the cave-man had no issues with data incompatibility, storage and search because stones & leaves were the only medium for data storage and search but that is past and  today we are in 21st century where we have to dealt with tons and tons of data and the data searching becomes more important.

Today we are going to learn the basics of MySQL Query Expansion. There are some cases,  where you want to find some information based on limited knowledge that you have. You use some keywords to search for information, and typically those keywords are too short. To solve this problem and help users to find what they want based on the too-short keywords, MySQL full-text search engine introduces a concept called query expansion.

What is query expansion?

The term query expansion in MySQL is used to broaden the search result of the full-text searches based on automatic relevance feedback which is sometimes referred as blind query expansion. Let us understand  how MySQL full-text search engine performs the steps when the query expansion is used:

  • First, MySQL full-text search engine looks for all the rows that match the search query provided by you.
  • Second, it checks all rows in the search result and then it finds all the relevant words.
  • Third, it performs a search again but based on the relevant words instead of the original keywords provided by the users.

Since you understood the basic concepts of query expansion, it might be clear  that you can use the query expansion when the search results are too short. You need to  perform the searches again but with query expansion to offer users more information that are related and relevant to the user.

Lets us understand the syntax:

In order to use query expansion, you need to use the WITH QUERY EXPANSION search modifier in the AGAINST()function. The following illustrates the syntax of the query using the WITH QUERY EXPANSION search modifier.

SELECT column1, column2
FROM table1
WHERE MATCH(column1,column2)
      AGAINST(‘keyword’,WITH QUERY EXPANSION);
In the next post, I’ll be continuing this topic with relevant examples and will see some quick facts about the full- text search. Please share your feedback and share if you like this topic.
Advertisements