...
Code Block | ||
---|---|---|
| ||
-- Select all documents where 'exceptional pie' was found and 'apple tree' was not found. SELECT * FROM type where CONTAINS('+"exceptional pie" -"apple tree"') |
...
Boosting
Boosting can be applied to the list of matches of full-text search queries. The boost operator ^ influences the relevance of individual terms within a CONTAINS statement. Thus, the sorting of the objects in the hit list is directly influenced.
The relevance of individual terms is specified via a boosting factor. The larger the boosting factor, the higher the relevance of the corresponding term. Here, the ratio between the individual boosting factors is considered and not the absolute values.
To set the boosting factor, append the ^ operator and a decimal value without blank spaces to the corresponding term. A term without a specified boosting factor will get the default boosting factor 1
.
Code Block | ||
---|---|---|
| ||
-- Select all documents containing 'tree'. Prefer objects containing 'apple', 'pear' or 'chestnut'.
-- Prioritize 'pear' 4 times and 'chestnut' twice over 'apple'.
SELECT * FROM type where CONTAINS('apple pear^4 chestnut^2 +tree') |
It is possible to reduce the relevance by applying a boosting value between 0
and 1
.
Code Block | ||
---|---|---|
| ||
-- Select all documents containing 'pie' and not 'tree'. Prefer objects containing 'apple' and especially 'pear'.
-- Avoid objects containing 'chestnut'.
SELECT * FROM type where CONTAINS('apple pear^2 chestnut^0.2 -tree +pie') |
...
Fuzzy Search
In full-text search queries, partially matching objects can be provided as results. Thus, it is possible to search for similar terms or variant spellings.
The number of characters not matching the search term is called "edit distance". For each search term, a maximum edit distance can be defined that limits the number of unmatching characters.
Append the operator ~ followed by the integer maximum edit distance to a word within the CONTAINS statement. The values 0
, 1
and 2
(default) are allowed for the edit distance. If the ~ operator is set without an edit distance, the default value 2 will be used. Since missing, redundant or reversed letters can be handled with edit distance 1, this value should be sufficient in most cases.
Code Block | ||
---|---|---|
| ||
-- Select all objects containing words with maximum edit distance 1 to 'exceptionel' or 2 to 'cestnutt'.
-- E.g. objects containing 'exceptional' or 'chestnut' will be found.
SELECT * FROM type where CONTAINS('exceptionel~1 cestnutt~ ') |
...
Proximity Search
It is possible to allow for reversed ordering of words in a phrase or to allow for additional words between the words of a phrase.
Here, the number of words not matching the specified phrase is called "edit distance". A maximum edit distance can be defined that limits the number of unmatching words.
Append the operator ~ followed by the integer maximum edit distance to a word within the CONTAINS statement.
Code Block | ||
---|---|---|
| ||
-- Select all documents containing phrases of maximum edit distance 3 to the specified sentence.
SELECT * FROM type where CONTAINS('"Please be patient while this website is under construction."~3') |
Escaping in CONTAINS Statements
In a CONTAINS expression, the system interprets specific symbols as operators. If you want to use those symbols as characters NOT beeing an operator, you have to escape them with a backslash ('\').
...