Newer Version Available

This content describes an older version of this product. View Latest

FIND {SearchQuery}

The required FIND clause allows you to specify the word or phrase to search for. A search query includes:
  • The literal text (single word or a phrase) to search for
  • Optionally, Wildcards
  • Optionally, logical Operators, including grouping parentheses

Searches are evaluated from left to right and use Unicode (UTF-8) encoding. Text searches are case-insensitive. For example, searching for Customer, customer, or CUSTOMER all return the same results.

Note that special types of text expressions (such as macros, functions, or regular expressions) that are evaluated at run time are not allowed in the FIND clause.

The SearchQuery must be delimited with curly braces. This is needed to unambiguously distinguish the search expression from other clauses in the text search.

Note

Single Words and Phrases

A SearchQuery contains two types of text:

  • Single Word— single word, such as test or hello. Words in the SearchQuery are delimited by spaces, punctuation, and changes from letters to digits (and vice-versa). Words are always case insensitive.

    In Chinese, Japanese, and Korean (CJK), words are also delimited by pairs of CJK-type characters. For example, this string in Japanese, 東京都知事, would be tokenized as four bigrams: 東京, 京都, 都知, and 知事. In the context of this usage, if a user searched for 京都, their intent is to find 京都, not 東京都. However, 東京都 would be returned in search results.

    Note

  • Phrase— collection of words and spaces surrounded by double quotes such as "john smith". Multiple words can be combined together with logic and grouping Operators to form a more complex query. Certain keywords (“and,” “or,” and “and not”) must be surrounded in double quotes if you want to search for those words, otherwise they are interpreted as the corresponding operator.

Wildcards

You can specify the following wildcard characters to match text patterns in your search:
Wildcard Description
* Asterisks match zero or more characters at the middle or end (not the beginning) of your search term. For example, a search for john* finds items that start with john, such as, john, johnson, or johnny. A search for mi* meyers finds items with mike meyers or michael meyers. If you are searching for a literal asterisk in a word or phrase, then escape the asterisk (precede it with the \ character).
? Question marks match only one character in the middle or end (not the beginning) of your search term. For example, a search for jo?n finds items with the term john or joan but not jon or johan.
When using wildcards, consider the following notes:
  • Wildcards take on the type of the preceding character. For example, aa*a matches aaaa and aabcda, but not aa2a or aa.!//a, and p?n matches pin and pan, but not p1n or p!n. Likewise, 1?3 matches 123 and 143, but not 1a3 or 1b3.
  • A wildcard (*) is appended at the end of single characters in Chinese, Japanese, Korean, and Thai (CJKT) searches, except in exact phrase searches.
  • The more focused your wildcard search, the faster the search results are returned, and the more likely the results will reflect your intention. For example, to search for all occurrences of the word prospect (or prospects, the plural form), it is more efficient to specify prospect* in the search string than to specify a less restrictive wildcard search (such as prosp*) that could return extraneous matches (such as prosperity).
  • Tailor your searches to find all variations of a word. For example, to find property and properties, you would specify propert*.
  • Punctuation is indexed. To find * or ? inside a phrase, you must enclose your search string in quotation marks and you must escape the special character. For example, "where are you\?" finds the phrase where are you?. The escape character (\) is required in order for this search to work correctly.

Operators

You can use the following special operators to focus your text search. Operator support is case-insensitive.

Operator Description
" " Use quotation marks around search terms to find an exact phrase match. This can be especially useful when searching for text with punctuation. For example, "acme.com" finds items that contain the exact text acme.com. A search for "monday meeting" finds items that contain the exact phrase monday meeting.
AND Finds items that match all of the search terms. For example, john AND smith finds items with both the word john and the word smith. In most cases if an operator isn't specified, AND is the default operator. When searching articles, documents, and solutions, AND must be specified because OR is the default operator. Case-insensitive.
OR Finds items with at least one of the search terms. For example, john OR smith finds items with either john or smith, or both words. Case-insensitive.
AND NOT Finds items that do not contain the search term. For example, john AND NOT smith finds items that have the word john but not the word smith. Case-insensitive.
( ) Use parentheses around search terms in conjunction with logical operators to group search terms. For example, you can search for:
  • ("Bob" and "Jones") OR ("Sally" and "Smith")—searches for either Bob Jones or Sally Smith.
  • ("Bob") and ("Jones" OR "Thomas") and Sally Smith—searches for documents that contain Bob Jones and Sally Smith or Bob Thomas and Sally Smith.

SearchQuery Character Limits

If the SearchQuery string is longer than 10,000 characters, no result rows are returned. If SearchQuery is longer than 4,000 characters, any logical operators are removed. For example, the AND operator in a statement with a SearchQuery that’s 4,001 characters will default to the OR operator, which could return more results than expected.

Search Order

When you combine multiple operators in a search string, they are evaluated in this order:
  1. () (parentheses)
  2. AND and AND NOT (evaluated from right to left)
  3. OR
These examples show how search strings are evaluated:
Searching for... Is the same as... Finds items with the words...
acme AND california AND NOT meeting acme AND (california AND NOT meeting) acme and california but not meeting
acme AND NOT california AND meeting acme AND NOT (california AND meeting) acme but not with both california and meeting
acme AND california OR meeting (acme AND california) OR meeting acme and california and items with the word meeting
acme AND (california OR meeting) acme AND (california OR meeting) acme and california and items with the words acme and meeting

Reserved Characters

The following characters are reserved:
1? & | ! { } [ ] ( ) ^ ~ * : \ " ' + -

Reserved characters, if specified in a text search, must be escaped (preceded by the backslash \ character) in order to be properly interpreted. An error occurs if you do not precede reserved characters with a backslash. This is true even if the SearchQuery is enclosed in double quotes.

For example, to search for the following text:

1{1+1}:2

insert a backslash before each reserved character:

1\{1\+1\}\:2

Example FIND Clauses

Type of Search Example(s)
Single term examples FIND {MyProspect}

FIND {mylogin@mycompany.com}

FIND {FIND}

FIND {IN}

FIND {RETURNING}

FIND {LIMIT}

Single phrase FIND {John Smith}
Term OR Term FIND {MyProspect OR MyCompany}
Term AND Term FIND {MyProspect AND MyCompany}
Term AND Phrase FIND {MyProspect AND "John Smith"}
Term OR Phrase FIND {MyProspect OR "John Smith"}
Complex query using AND/OR FIND {MyProspect AND "John Smith" OR MyCompany}

FIND {MyProspect AND ("John Smith" OR MyCompany)}

Complex query using AND NOT FIND {MyProspect AND NOT MyCompany}
Wildcard search FIND {My*}
Escape sequences FIND {Why not\?}
Invalid or incomplete phrase (will not succeed) FIND {"John Smith}

FIND Clauses in Apex

The syntax of the FIND clause in Apex differs from the syntax of the FIND clause in the SOAP API:
  • In Apex, the value of the FIND clause is demarcated with single quotes. For example:
    1FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead
  • In the Force.com API, the value of the FIND clause is demarcated with braces. For example:
    1FIND {map*} IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead

The Force.com Apex Code Developer's Guide has more information about using SOSL and SOQL with Apex.