[SalesForce] SOSL not returning all expected results

I'm trying to SOSL search a custom object we have, by a phone number field but the results are not working as I'd expect. The issue seems to be around missing characters at the start of the search string; but I expect SOSL to search "within" field values to get around this.

The search is simply

FIND {criteria} IN ALL FIELDS RETURNING Object_Name__c(Id, Name, etc, etc)

I can't share a real example because the phone number is a genuine one, but say I have a phone number stored as:

01 395 24 24 68

searching for {1 395 24 24 68} (where the opening number is removed) returns no results, but if I search for {395 24 24 68} (opening two numbers are removed) then the record IS retrieved by the query.

This seems to be something to do with the formatting of the number so to work around this I created a new field and using regex in a trigger, I populate this field with ONLY numbers from the phone number field. In this example, the value would be 01395242468. However this makes NO difference to the SOSL results. I've tried making the new field a Phone, Text and Text (External Id) field. It is on the page layout and is editable by everybody. Obviously if I use SOQL, wrap the search in wildcard symbols and perform a LIKE search, the record is retrieved but I'm confused, why will SOSL not find that record?

NOTE: I've also found out that using Salesforce's own Global Search yields exactly the same problem!

Best Answer

The search indexes require the first character of each "word" (in your case, numbers) in order to make a match. This is a limitation of the search engine's indexes, and you can't work around it aside from making sure you have all permutations you want to have searchable. See FIND {SearchQuery} for more details on wild cards and what partial searches are allowed.

Related Topic