Full-text search on registered, hierarchical records in SQL Server 2008

Probably a question about the Nob, but I will still go for him.

For example, I have a Person table, a tag table, and a ContactMethod table. A person will have several tag entries and several ContactMethod entries associated with them.

I would like to get a farewell search that will search among several fields from each table. Therefore, I can find a person by e-mail (through ContactMethod), their name (through Person) or the tag assigned to them.

As a complete noob for FTS, two approaches come:

  • Build some complex query that addresses each field separately
  • Create some kind of lookup table that combines the fields that I want to index and just do a full-text query in that view.

(Feel free to edit for clarity; I'm not in it for replica points.)

+1
sql-server full-text-search
source share
3 answers

If your sql server supports it, you can create an indexed view and full-text search, which; you can use containsstable (*, '"chris") to read all columns.

If it does not support it, since all fields come from different tables, I think for scalability; if you can easily fill in the fields in one row per record in a separate table, I would get a full text search, not separate records. As a result, you will have a less complex FTS directory, and your queries will not necessarily perform 4 full-text searches at the same time. Running many separate FTS queries on different tables at the same time is a ticket to asking for performance issues in my experience. The disadvantage of this is that you lose the ability to independently look for your last name; if this is what you need, you may have to look for an alternative.

In our application, we found that one table was faster (we cannot rely on clients having corporate sql at hand); therefore, we fill in the data with spaces in the FTS table via update sp, then our main contact search searches the list. We have two separate searches to handle the search for things with precision (e.g. names or phone numbers) or just for free text. Another nice thing in the table is the relatively easy and inexpensive way to add additional columns to the search (we were asked to provide a social security number, for example: for this, we just added a column to the SP update, and we were away with little or no impact.

0
source share

One of the possibilities is to create a view that has these columns: PersonID, ContentType, Content. ContentType will be something like "Email", "PhoneNumber", etc .... and Content will stick to that. You will search in the β€œContent” column and you will be able to find out what a user ID is. I'm not 100% sure how full-text search works, so I'm not sure if you can use this in a view.

0
source share

FTS can search multiple fields out of the box. The CONTAINS predicate accepts a list of columns to search. Also CONTAINSTABLE .

0
source share

All Articles