篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql MS SQL全文搜索查询示例相关的知识,希望对你有一定的参考价值。
-- CONTAINS
SELECT Comments
FROM Production.ProductReview
WHERE CONTAINS(Comments, 'adventure') ;
-- CONTAINSTABLE (Returns a table)
SELECT * FROM CONTAINSTABLE
(Production.ProductReview,Comments, 'adventure');
-- [Output]
-- KEY RANK
-- 4 8
-- Joining with full-text search
SELECT PR.Comments,
FTS.Rank
FROM Production.ProductReview PR
JOIN
CONTAINSTABLE(Production.ProductReview,
Comments,
'adventure') FTS
ON PR.ProductReviewID = FTS.[KEY]
ORDER BY FTS.Rank DESC;
-- Use double quotes (" "),
-- to look for a complete phrase
SELECT ProductID, Comments
FROM Production.ProductReview
WHERE CONTAINS(Comments, '"the praises"');
-- OR, AND
SELECT Comments
FROM Production.ProductReview
WHERE CONTAINS(Comments, 'little OR mountain')
-- Multiple phrases
SELECT Comments
FROM Production.ProductReview
WHERE CONTAINS(Comments, 'getting')
AND CONTAINS(Comments,'new');
-- DOS Wildcards *
SELECT Comments
FROM Production.ProductReview
WHERE CONTAINS(Comments, '"*Adventure*"')
-- Near: Relatively near each other
SELECT Comments
FROM Production.ProductReview
WHERE CONTAINS(Comments, 'mountain NEAR biking')
-- Weighting
SELECT PR.ProductID, PR.Comments, FTS.Rank
FROM Production.ProductReview PR
JOIN
CONTAINSTABLE(Production.ProductReview,
Comments, 'ISABOUT (little weight (.5),
adventure weight (.5))') FTS
ON PR.ProductReviewID = FTS.[KEY]
ORDER BY FTS.Rank DESC
-- Inflection
-- Find for inflectional change of the word
-- Here: praises is an inflectional change of praise
SELECT Comments
FROM Production.ProductReview
WHERE CONTAINS(Comments,
'FORMSOF(INFLECTIONAL,praise)');
-- Output
-- I can't believe I'm singing the praises of ...