Full-Text Search in SQL Server and Azure SQL Database lets users and applications run full-text queries against character-based data in SQL Server tables.
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
MS SQL Server Full-Text Search
1. MS SQL Server Full-Text Search
Prepared By: Bassam Diab
Date: 25-04-2019
2. Overview
• What is Full-Text Search?
• When will Full-text Search be best choice?
• Full-Text Search queries.
• How to Set up full-text search in MS SQL Server?
• Does the Entity Framework support Full-Text Search?
• MS SQL Server Index VS Search Platform (Solr and Elasticsearch).
• Questions.
3. What is full-Text Search?
Full-Text Search lets users and applications run full-text queries against
character-based data in SQL Server tables or Indexed Views.
APPLIES TO:
1. SQL Server (starting with 2008).
2. Azure SQL Database.
3. SQL Data Warehouse.
4. Parallel Data Warehouse.
4. What is full-Text Search?
Full-text search architecture consists of the following processes:
1. The SQL Server process (sqlservr.exe).
2. The filter daemon host process (fdhost.exe).
These two processes contain the components of the full-text search
architecture. These components and their relationships are summarized in
the following illustration.
6. Full-Text Search queries VS LIKE
Full-Text Search queries:
1. Powerful Features (thesaurus,stemmers,ranking).
2. Query can take only seconds or less against millions of rows of text data .
3. Used to query formatted binary data.
Like predicate :
1. Works on character patterns only.
2. Query against millions of rows of text data can take minutes of unstructured text
data to return.
3. Cannot used to query formatted binary data.
7. Full-Text Search queries
After columns have been added to a full-text index, users and applications
can run full-text queries on the text in the columns. These queries can search
for any of the following:
1. One or more specific words or phrases (simple term).
2. A word or a phrase where the words begin with specified text (prefix term).
3. Inflectional forms of a specific word (generation term).
4. Synonymous forms of a specific word (thesaurus).
5. Words or phrases using weighted values (weighted term).
8. Set up full-text search
There are two basic steps to set up full-text search:
1. Create a full-text catalog.
2. Create a full-text index on tables or indexed view you want to search.
Each full-text index must belong to a full-text catalog. You can create a
separate text catalog for each full-text index, or you can associate multiple
full-text indexes with a given catalog. A full-text catalog is a virtual object
and does not belong to any file group. The catalog is a logical concept that
refers to a group of full-text indexes.
9. Full-Text Predicates
There is four predicates in the full-text search:
1. CONTAINSTABLE.
2. CONTAINS.
3. FREETEXTTABLE.
4. FREETEXT.
10. Full-Text Indexes – CONTAINSTABLE
• Returns a table of zero or one or more rows for the columns queried
containing precise or less precise matches to single words and phrases,
proximity of words within a distance of one another or weighted matches.
• Used in the FROM clause.
• Returns a relevance ranking value and full-text key in the result set.
11. Full-Text Indexes – CONTAINS
• Used in the WHERE clause of a query.
• Searches for precise or less precise matches to single words and phrases.
• Can search for the following:
1. Prefix of a word or phrase
2. A word that is inflectionally generated from another (i.e. drive, drives,
drove, driving, driven).
3. Synonyms of another word using a thesaurus.
12. Full-Text Indexes – FREETEXT
• Used in the WHERE clause of a query.
• Searches for values that match the meaning and not the exact wording of
the search criteria.
• Queries using FREETEXT are less precise than CONTAINS.
• Matches are generated if any term or form of any term is found.
13. Full-Text Indexes – FREETEXTTABLE
• Used in the FROM clause of a query like CONTAINSTABLE .
• Uses the same search conditions as FREETEXT.
• It adds a rank and key value for each row.
14. Does the Entity Framework support Full-Text
Search?
Out of the box Entity Framework does not support Full Text Search. To do Full
Text Search you have a number of options to get it working. You can get Full
Text Search working using a table valued function. The method does the Full
Text Search in a table valued function that returns an id list, the returned ids
can be used to filter the records from an actual table.
15. Full-Text VS Search Platform
Solr MS SQL Full-Text
Index auto Update No Yes
Store Data in Index Yes No
Location in Memory Yes No
Interface Yes SQL
Querying Multiple Columns Yes Yes
Custom Index documents
structure
Yes No