function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PaulDysonPaulDyson 

Excluding fields from SOSL search

Is it possible to exclude certain fields from SOSL searches. We are using SOSL to search custom objects and want all fields to be search bar one. That one contains an external reference, many of which happen to contain pairs of letters (CD, BA and so on) that also happen to be common search terms, leading to spurious results.
mtbclimbermtbclimber

SOSL does not support exclusions. You can scope the fields to be included using exactly one of the scope options as described in the doc:

 

ALL FIELDS Search all searchable fields. If the IN clause is unspecified, then this is the default setting.
EMAIL FIELDS Search only email fields.
NAME FIELDS Search only name fields. In custom objects, fields that are defined as “Name Field” are searched. In standard and custom objects, name fields have the nameField property set to true in the (see the Field array of the fields parameter of the DescribeSObjectResult for more information).
PHONE FIELDS Search only phone number fields.
SIDEBAR FIELDS Search for valid records as listed in the Sidebar drop-down list. Unlike search in the application, the asterisk (*) wildcard is not appended to the end of a search string.


Not sure how your field is defined but if it doesn't fall into the scope for sidebar fields you might be able to get a decent result with that option. From the online help (you need to login) sidebar search scope for custom objects:

 

Fields Searched in Both Sidebar Search & Advanced Search   

  • Name   
  • All custom auto number fields and custom fields that are set as an external ID (Note that you do not need to enter any leading zeros during a search on an autonumber field.)
  • All custom fields of type email and phone.