Back to results for “Indexes”
SQL Server › Full Text Search

How do you perform a proximity search using full text search, finding rows where two words appear near each other?

Intermediate

Answer

You use the CONTAINS predicate with the NEAR keyword, specifying the two words you want to find close together, optionally including a maximum distance between them, which is useful for finding relevant results where related terms appear together rather than scattered far apart throughout a large document.
SELECT * FROM Articles
WHERE CONTAINS(Content, 'NEAR(database, performance, 10)');
Real-world example A technical documentation search finds articles where the words database and performance appear within ten words of each other, surfacing more relevant results than a search that simply looks for both words anywhere in the document.

Common follow-ups: How do you control the exact maximum distance allowed in a NEAR search?;Does word order matter when using the NEAR keyword?