SOSL allows you to specify the following for source objects:
text expression
scope of fields to search
list of objects and fields to retrieve
conditions for selecting rows in the source objects
Pass the entire SOSL expression in the search parameter of the search() call.
Comparing SOSL and SOQL
Like Salesforce Object
Query Language (SOQL), SOSL allows you to search your organization’s Salesforce data
for specific information. Unlike SOQL, which can only query one object
at a time, a single SOSL query can search all objects—including
custom objects—to which you have access. The API executes
the search within the specified scope and returns to you only the
information that is available to you based on the user permissions
under which your application has logged in.
Use SOQL with the query() call to select records for a single object.
Use SOSL with the search() call to find records for one or more objects. The search() call searches most text fields on an object. See Search Scope for information
on the fields searched.
Designing Efficient Text Searches
If your searches are too general, they will be slow and
return too many results. Use the following to write more efficient
searches:
IN clause—for limiting the types
of columns to search
The search() call searches most objects (including custom objects) and text
fields to which you have access. It does not search the following
objects and fields:
Any elements such as picklists that are defined as not searchable
(searchable is false). To determine whether a given
object is searchable, your application can invoke the describeSObjects() call on the object and inspect the searchable property in the DescribeSObjectResult.
Number, date, or checkbox fields. To search for such information,
use the query() call instead.
Textarea fields, unless you use the ALL FIELDS search group.
Attachment records associated with certain objects, such as Account, Contact, or Opportunity.
Note the following implementation tips:
The search() call provides synonym matching, stop words, stemming, and spell
correction for articles. In most cases, the search() call does not provide specialized search features such as synonym
matching or stop words.
Apex requires that you surround SOQL and SOSL statements with square
brackets in order to use them on the fly. Additionally, Apex script variables and expressions can be used if preceded by a colon
(:).