Sql-server – Sql Server Full Text Search one table for text values in another table

full-text-searchsql server

Is it possible to run a full text search on an FTS-indexed column for all values in another table?

Conceptually it'd look like

select d.* from Docs d, Tags t where CONTAINS(d.fulltext, t.tagvalue)

I'm rather new to MSSQL FTS, though I know that the equivalent would work in postgres

select d.* from docs d, tags t where to_tsquery(t.tagvalue) @@ to_tsvector(d.fulltext)

Thanks for the help!

Best Answer

Yes, but not directly. You would have to build dynamic SQL strings, one row for every join set (pair of Docs and Tags rows), and then execute those strings. That's probably not practical.

In the FROM query, if you had 1,000 records in Docs and 1,000 records in Tags, the result set would have 1,000,000 rows. I'm assuming you knew that and just dummied up some quick T-SQL - obviously this wouldn't work in production.