Search code examples
sqlsql-serverfreetext

SQL SELECT FREETEXT order by Rank


I have this query in SQL Server 2008

SELECT TOP 1000 * 
FROM Quotes 
INNER JOIN QuoteImages ON Quotes.Id = QuoteImages.QuoteId 
WHERE FREETEXT(QuoteText,'some text')

How can I order the results by most relevant or highest rank ?

I have read the msdn documentation, but it seems complicated and I don't know how to create complex stored procedures.


Solution

  • You should use FREETEXTTABLE (link) instead of FREETEXT:

    SELECT TOP 1000 Q.*, QI.*
    FROM Quotes Q
    INNER JOIN QuoteImages QI
        ON Q.Id = QI.QuoteId 
    INNER JOIN FREETEXTTABLE(Quotes,QuoteText,'some text') FT
        ON Q.Id = FT.[Key]
    ORDER BY RANK DESC