I am trying to improve search functionality on my web forums. I have a message table, and each post has (among other less interesting things):
- PostID , a unique identifier for a single message.
- ThreadID , identifier of the thread to which the message belongs. Each thread can have any number of messages.
- Text , because the forum would be really boring without it.
I want to write an effective query that will search threads in the forum for a number of words, and it should return a hit for any ThreadID for which there are messages containing all the search words. For example, let's say that thread 9 has a post 1001 with the word "cat" in it, as well as message 1027 with the word "hat" in it. I want a cat hat search to return a hit for stream 9.
This seems like a direct requirement, but I don't know how to do it. Using the regular features of FREETEXT and CONTAINS for N'cat AND hat 'will not return any hits in the above example, because the words exist in different messages, although these messages are in the same thread. (As far as I can tell, when using CREATE FULLTEXT INDEX I have to give it my index on the primary key PostID and I can not say that it indexes all messages with the same ThreadID together.)
The solution that I am running now works, but sucks: maintain a separate table containing all the concatenated text text of each stream, and create a full text index on THAT. I am looking for a solution that does not require me to duplicate a copy of the text of each thread on my forums. Any ideas? Am I missing something?
sql-server sql-server-2008
Travis
source share