Groups | Blog | Home
all groups > sql server full text search > may 2006 >

sql server full text search : how does contains sort returned rows?


vtxr1300
5/23/2006 5:56:19 AM
I've got a search page where a user can input a number of different
search criteria such as location, job type, keywords, pay amount, etc.
I've got one table that holds all of the data that is being freetext
searched so that we don't have to do joins. That has helped speed
things up, but I had been using contains to search the data. Now I
have learned that in order to sort by rank, I have to use
containstable. But in my testing, it seems I can only have one
containstable search condition in my query. This won't work for our
situation, so I'm curious as to how contains sorts it's returned
records? If you don't specify how you want them sorted, does it have
it's own sort of internal ranking that it sorts by or is it just
random? Thanks.
Daniel Crichton
5/23/2006 2:45:23 PM
vtxr1300 wrote on 23 May 2006 05:56:19 -0700:

[quoted text, click to view]

No idea on the contains sorting, but I'm guessing it's based on the
clustered index on the table.

You should be able to have more than one containstable, but you'll have
issues with the rank sorting as each row will have 1 rank per containstable,
so you'll have to work out how you want to deal with that. eg.

SELECT * FROM Table AS t
INNER JOIN CONTAINSTABLE(Table, *, 'word1') AS a ON t.PrimaryKey = a.[KEY]
INNER JOIN CONTAINSTABLE(Table, *, 'word2') AS b ON t.PrimaryKey = b.[KEY]

Using table aliases as above should let you use CONTAINSTABLE multiple
times, but it'll likely be inefficient and you'll probably want to look at
trying to work your search terms into a single clause. With the above you'll
have 2 ranks, one for each search, so you'll need to do something to
calculate how to do the overall sort - you could simply add them together,
or maybe average them, and then sort.

Dan

Hilary Cotter
5/23/2006 9:18:30 PM
They are ordered by the key you full-text index on.

--
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.

This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com



[quoted text, click to view]

AddThis Social Bookmark Button