Advanced Search Using SQL Server Full-Text Search: Part-2

Picture of Vivasoft Team
Vivasoft Team
Published on
22.09.2025
Time to Read
2 min
sql
Table of Contents

In part one, it is shown how to enable basic Full-Text search options on a table in SQL Server. But often our required data is not available in a table that may be available across multiple tables. In this case, we can make a VIEW and then apply the Full-Text search option on it.

In this part, we will try to show how to make VIEW and enable the Full-Text search option on it. In this example we need to search by name and address of customer and required data is available in Person table & Address table. We may not want to search separately, we want at one go.

1) First, we will check if VIEW already exists or not. If not, then we will create a new one with SCHEMABINDING
				
					IF OBJECT_ID('CustomerInfoIndexView','V') IS NOT NULL
DROP VIEW CustomerInfoIndexView
GO

CREATE VIEW CustomerInfoIndexView WITH SCHEMABINDING 
AS
SELECT 
       be.AddressID as Id
      ,pp.FirstName
      ,pp.MiddleName
     ,pp.LastName
      ,[AddressLine1] as [Address]
      ,[City]
FROM [Person].[Address] pa
INNER JOIN [Person].[BusinessEntityAddress] be ON  pa.AddressID = be.AddressID
INNER JOIN Person.Person pp ON be.BusinessEntityID = pp.BusinessEntityID
GO

				
			
2) Now need to create a unique clustered index on this VIEW
				
					IF NOT EXISTS(SELECT 1 FROM sys.indexes 
              WHERE name='CIX_CustomerInfoIndexView_Id' 
  AND object_id = OBJECT_ID('dbo.CustomerInfoIndexView')
  )
CREATE UNIQUE CLUSTERED INDEX CIX_CustomerInfoIndexView_Id ON dbo.CustomerInfoIndexView(Id)
GO

				
			

While running the above query, the system shows an error message. Because we need to create a FULLTEXT INDEX on our VIEW with KEY INDEX.

				
					IF NOT EXISTS(SELECT 1 FROM sys.indexes  
  WHERE name='CIX_CustomerInfoIndexView_Id'  
 AND object_id = OBJECT_ID('dbo.CustomerInfoIndexView')) 
CREATE UNIQUE CLUSTERED INDEX CIX_CustomerInfoIndexView_Id ON dbo.CustomerInfoIndexView(Id) 
GO

				
			
Create - a fulltext index on our view with key index
4) Create a FULLTEXT INDEX on VIEW CustomerInfoIndexView
				
					CREATE FULLTEXT INDEX ON CustomerInfoIndexView (
  FirstName,
  LastName,
  [Address],
  City
) KEY INDEX CIX_CustomerInfoIndexView_Id
GO

				
			
5) Test again and see the result
				
					SELECT * FROM CustomerInfoIndexView WHERE FREETEXT(*,'Gigi')
GO
				
			
CustomerInfoIndexView
6) Now test again with both FREETEXT & CONTAINS and see the difference
				
					SELECT * FROM CustomerInfoIndexView WHERE FREETEXT(*,'Gig')
GO
SELECT * FROM CustomerInfoIndexView WHERE CONTAINS(*,'"Gig*"')
GO
				
			
Test - with both FREETEXT & CONTAINS

 

To know why this result is showing see part-1

To get a tailored application hire Developers from us
7) To get better benefits we can combine both FREETEXT and CONTAINS. But Suffix searches are not supported in CONTAINS, they only support Prefix.
				
					SELECT * FROM CustomerInfoIndexView WHERE FREETEXT(*,'Gigi Butl')
UNION
SELECT * FROM CustomerInfoIndexView WHERE CONTAINS(*,'"Gig*" OR "Butl*"' )
GO
				
			
Benefits - of combining both FREETEXT and CONTAINS
50+ companies rely on our top 1% talent to scale their dev teams.
Excellence Our minimum bar.
It has become a prerequisite for companies to develop custom software.
We've stopped counting. Over 50 brands count on us.
Our company specializes in software outsourcing and provides robust, scalable, and efficient solutions to clients around the world.
klikit

Chris Withers

CEO & Founder, Klikit

Klikit-logo
Heartfelt appreciation to Vivasoft Limited for believing in my vision. Their talented developers can take any challenges against all odds and helped to bring Klikit into life.appreciation to Vivasoft Limited for believing in my vision. Their talented developers can take any challenges.
Start with a dedicated squad in 7 days

NDA first, transparent rates, agile delivery from day one.

Where We Build the Future
Scale Engineering Without the Overhead

Elastic offshore teams that integrate with your processes and timezone.

Tech Stack
0 +
Blogs You May Love

Don’t let understaffing hold you back. Maximize your team’s performance and reach your business goals with the best IT Staff Augmentation

let's build our future together

Get to Know Us Better

Explore our expertise, projects, and vision.