Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.0 » SQL Anywhere Server - SQL Usage » Querying and Modifying Data » Querying data » Full text search » Types of full text searches

 

Proximity searching

You can use the NEAR keyword to find terms that appear in close proximity to each other. For example, 'term1 NEAR term2' finds instances of term1 that appear close to term2. Unless otherwise specified, the database server searches for instances that appear within ten terms of each other.

You can specify an integer argument with the NEAR keyword to specify the maximum distance. For example, term1 NEAR[5] term2 finds instances of term1 that are within five terms of term2.

You can also use a tilde character (~) instead of the NEAR keyword. For example, 'term1 ~ term2'. However, you cannot specify a distance when using the tilde form, so the database server always searches within ten terms.

To use the CONTAINS clause, you must first create a text index. See Text indexes.

Example

Supposed you have a table named Applicants with a column called Schools that contains applicants' educational history. You want to search for applicants who have attended a university in Virginia. Assuming you have a text index on the Schools column, you could search as follows, specifying that the search terms should be within five terms of each other:

SELECT * FROM Applications CONTAINS ( Schools, 'university NEAR[5] virginia' );