sql-serverindexingviewazure-sql-databasefreetext

Why we need FREETEXT if we already have CONTAINS?


Why we need FREETEXT if we already have CONTAINS? in SQL Server can you you give where exactly we can make use of.

Syntax for using FREETEXT is exactly the same as CONTAINS , so When you need to do an CONTAINS and FREETEXT,


Solution

  • FREETEXT evaluates not only on the string, but also the meaning. Whereas CONTAINS is used for precise or fuzzy searching on a string.

    CONTAINS and FREETEXT are quite similar functions. Both return a boolean value, and both take 2 parameters: a Free-Text indexed column name and the Free-Text search term. But they behave quite differently.

    Like larnu said, even sometimes the syntax can be the same, it doesn't mean the do the same thing.

    FREETEXT is more restrictive predicate which by default does a search based on various forms of a word or phrase (that means it by default includes Inflectional forms as well as thesaurus).

    CONTAINS, unlike FREETEXT, gives you flexibility to do various forms of search separately.

    Here are the blogs which showed us some examples to make it more clear how different searches are done through FREETEXT and CONTAINS. This may help you have a good understand about FREETEXT and CONTAINS.

    Ref:

    1. Is it better to use FREETEXT or CONTAINS Full Text Searches when searching by single characters
    2. Full Text Queries : CONTAINS and FREETEXT predicates
    3. Sql Server Full-Text Search Protips Part 2: CONTAINS vs. FREETEXT

    HTH.