Search

Thursday, July 28, 2011

Fulltext search with ranking

To have the best result from an fulltext query you can use the rank function. It can be used as in the example below:

SELECT [id],englishname,englishcode
from sqlcode AS code,
CONTAINStable(sqlcode,englishcode,'FORMSOF(INFLECTIONAL, "backup")') AS v1
where
v1.[KEY] = code.id
order by v1.rank desc

It is also possible to rank individual words, e.g. make database weight more than log.

SELECT [id],englishname,englishcode
from sqlcode AS code,
CONTAINStable(sqlcode,englishcode,'ISABOUT (backup weight (1),
database weight (.9), log weight (.2) )' ) AS v1
where
v1.[KEY] = code.id
order by v1.rank desc

No comments:

Post a Comment