If you use a CONTAINS query in the FROM clause, then an additional score column is available for use in the SELECT list, ORDER BY clause, or other parts of the query. By default, the score column has the correlation name, contains. You can optionally specify a different correlation name following the closing bracket of the CONTAINS query. A higher score corresponds to a better match. Therefore, it is often useful to order by descending score to get the best matches first.
For example, create a text index on the Products.Description column as follows:
CREATE TEXT INDEX scoringExample ON Products ( Description );
Query the text index as follows. Note that the results of the CONTAINS clause can optionally be followed by a correlation name used to reference the score columns from elsewhere in the SELECT statement.
SELECT Products.Description, ct.* FROM Products CONTAINS ( Products.Description, 'cap OR cotton' ) ct ORDER BY ct.score DESC;
Note that Cotton Cap has a high score in the results because it contains both search terms.
When you perform a full text search across multiple columns, the result includes a score for the row. For example, create a text index on Products.Description and Products.Name columns as follows:
CREATE TEXT INDEX scoringExampleMult ON Products ( Description, Name );
Query the Description and Name columns for the terms cap or visor.
SELECT Products.Description, Products.Name, ct.score FROM Products CONTAINS ( Products.Description, Products.Name, 'cap OR visor' ) ct ORDER BY ct.score DESC;
|Wool cap||Baseball Cap||3.2340501745357333|
|Cotton Cap||Baseball Cap||3.090467108972918|
The scores for a multi-column search are calculated as if the column values were concatenated together and indexed as a single value. Note, however, that phrases and NEAR operators never match across column boundaries, and that a search term that appears in more than one column increases the score more than it would in a single concatenated value.
|Send feedback about this page via email or DocCommentXchange||Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0|