Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Full text search results priority?

Author  Topic 

rjoseph
Starting Member

3 Posts

Posted - 2008-12-02 : 03:36:37
Hi guys

I have a keywords search facility (full text search) on my website which is working fine as I have fully indexed my table.

My query is structured in such a way that any records returned have to contain ALL keywords somewhere within any of the field data within the record.

My question is this, is there any way of prioritising my results so that my query will search one specific field first , look if there are any records with ALL keywords in that specific field and display these records first? I hope I have explained this ok.

is this possible

Best regards

Rod from the UK

jholovacs
Posting Yak Master

163 Posts

Posted - 2008-12-02 : 14:41:08
I don't think there is a way to rank sources like you're describing, but you may be able to do something like:


;WITH Results (TablePK, SearchRank) AS
(
SELECT DISTINCT
t.pk_id,
RANK() OVER (
PARTITION BY t.pk_id ORDER BY CASE
WHEN fts1.[key] IS NOT NULL THEN 1
WHEN fts2.[key] IS NOT NULL THEN 2
WHEN fts3.[key] IS NOT NULL THEN 3
ELSE 4
END ASC)
FROM
[schema].tblSearchMe t
LEFT OUTER JOIN
FREETEXTTABLE([schema].tblSearchMe, [FirstColumnToSearch], @SearchText) fts1
ON
fts1.[key] = t.pk_id
LEFT OUTER JOIN
FREETEXTTABLE([schema].tblSearchMe, [SecondColumnToSearch], @SearchText) fts2
ON
fts2.[key] = t.pk_id
LEFT OUTER JOIN
FREETEXTTABLE([schema].tblSearchMe, [ThirdColumnToSearch], @SearchText) fts3
ON
fts3.[key] = t.pk_id
)

SELECT
tbl.*
FROM
[schema].tblSearchMe tbl
INNER JOIN
Results r
ON
r.TablePK = tbl.pk_id
ORDER BY
r.SearchRank ASC;


I haven't tested this, and frankly I'd imagine this to bee less than ideal, but it would probably work.

___________________________
Geek At Large
Go to Top of Page

rjoseph
Starting Member

3 Posts

Posted - 2008-12-05 : 06:12:58
Thanks jholovacs

I will give that a try!

Best regards

Rod from the UK
Go to Top of Page
   

- Advertisement -