In most applications, we need to query or filter text that we have stored in a SQL Server database. If you have a Customer table and you need to filter by name it is ok to write a Select query with a Where clause to compare the input from the user with all customers’ names in that table.

Now, let’s say we have one table, a very simple one, to store all the posts from one blog.

We need to implement a functionality that allows the users to search for posts based on a specified input, but we need to show results even for posts similar to what the user-specified. The user doesn’t know the exact title of the post he is looking for, maybe he is not looking for any specific post but for some information related to what he entered.

Basic searches implementations, like the one we spoke about before to filter customers by name, use queries like these:

SELECT * FROM dbo.Post WHERE Title = 'param';
SELECT * FROM dbo.Post WHERE Title like '%param%';

Let’s say there is a post with the title: “The top 10 phones of 2017” and the user enter something like: “best mobiles” or “best smartphones in 2016”. Will the previous queries give us some good results? No, they won’t. They probably won’t get any result at all.

This kind of search is called Semantic Search and is very complicated to implement, at least from scratch. Fortunately, SQL Server provides a built-in feature that allows us to solve this problem and it is not so hard to get it working.

Comments