0

I have a community page. It has a search box and a list view to display the search result. Below is the Query I'm building: (It will search in 15M total records)

List<List<sObject>> searchList = [FIND '1234*' IN ALL  FIELDS RETURNING Service_visit__c 
                                  (Account__r.Name, Account__r.Location__c, OId, Start_Date__c, Address1__c, City__c, State__c, Report_Type__c ORDER BY Start_Date__c DESC LIMIT 200 )
                               ];

Above SOSL is resulting in less record assuming 30 counts.

But When I'm searching with some other string 'abcd 1234*', It's resulting in many records (150 records):

List<List<sObject>> searchList = [FIND 'abcd1234*' IN ALL  FIELDS RETURNING Service_visit__c 
                                  (Account__r.Name, Account__r.Location__c, OId, Start_Date__c, Address1__c, City__c, State__c, Report_Type__c ORDER BY Start_Date__c DESC LIMIT 200 )
                               ];
1

Those are simply different queries that match different result sets.

SOSL does not perform substring matching (matches that start within a token). 1234* will match any token beginning with 1234, but it won't match, for example, abcd1234. Conversely, abcd1234* will match abcd123456, but it will not match 123456.

There are some examples demonstrating this principle in the FIND section of the SOQL and SOSL Reference:

Asterisks match zero or more characters at the middle or end 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.

Emphasis mine. Note how the wildcards apply only in the middle or at the end of a token that is part of the search term.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.