When trying to search a string using SOSL, it behaves differently for one search parameter vs two search parameters with logical operator.

Search String 1 : FIND '"com"' => No of Records Returned : 910

Search String 2 : FIND '"com" or "net"' => No of Records Returned : 762

Shouldn't result two also be 910 or above. Logical operator is OR statement, so theoretically it should give us more results or at least at minimum 910. Right?

Please help me if I'm missing on something.

Please note :

  • I'm using FOR SOSL (ie loop over SOSL with limit of 20 SOSL to run at max) to return more than 200 records.
  • Only one sublist is returned in my SOSL

UPDATE (Adding Pseudo Code)

public with sharing class TestSOSL 
    public static Set<Sobject> conversionIds = new Set<Sobject>();
    public static String SearchMsg = '';
    public static void runSOSL(String query) 
        //Check Governor Limit
        if(Limits.getSoslQueries() < Limits.getLimitSoslQueries())
            //Do actual SOSL
            List<List<SObject>> searchList = search.query(query);
            //Check if search resulted any records or not
            if(searchList.size() > 0 && searchList.get(0).size() > 0) 
                //Add returned search results in set variable so that these results can be discarded in next iteration of search
                //Debug Message to show number of records returned in each iteration
                SearchMsg += searchList.get(0).size() + ' ';
                //If returned size is less than 200 then this is last iteration of SOSL, and there are no more matching records
                if(searchList.get(0).size() == 200)

Now execute above code using below anonymous code

String query = 'FIND \'"com" or "net" \' IN ALL FIELDS RETURNING Contentversion(Id where Id not in :conversionIds and firstPublishLocationId != null)';

This outputs : ************200 200 200 162

Now execute below

String query = 'FIND \'"com"\' IN ALL FIELDS RETURNING Contentversion(Id where Id not in :conversionIds and firstPublishLocationId != null)';

This outputs : ************200 200 200 200 110


=> Using FIND '"com"', no of Records Returned are 910 where as Using FIND '"com" or "net"', no of Records Returned are 762.

  • How did you manage to get more than 200 records returned :) Can you examine how many "sublists" with results you get back and how the count splits between different sObjects? Maybe the second search is "too generic" for SF so it decides to skip some sObjects... If I'm right you'd have to explicitly list them all similar to sidebar search where you decide which objects you want to check.
    – eyescream
    Mar 21, 2013 at 7:57
  • I did more of a FOR SOSL ie loop over and do SOSLs. There's only one sublist that I'm returning. Mar 21, 2013 at 7:58
  • Can you run same searches in sidebar / global search? If it's consistent (should be) you might be better off asking SF support. In the past I had some issues with this full text search ("a19*" returned also rows with just "19") but that was always more false positives, not less!
    – eyescream
    Mar 21, 2013 at 8:11
  • as the numbers are big 910 and 762, so to compare same with global search its hard, as global search says (25+) and you need to then keep scrolling next page. So hard to validate if search result count is same in sosl and global search. Might need to consider a similar scenario and do the validation. Mar 21, 2013 at 8:24
  • Can you post the code, or if not the exact code, some code that reproduces the issue? Mar 21, 2013 at 12:24

2 Answers 2


I've had a similar issue before and I worked with SFDC support who gave me potential reasons but they wouldn't commit to a single answer. Things to consider:

  • Thanks for comment, I understand that SOSL seems to be more of blackhole :) May 2, 2013 at 14:04

Just wanted to give more details with example so, adding this answer here.

As @Wes mentioned that "The SOSL search algorithm is a blackbox including some relevancy AI so it chooses which records to search through"

Due to which what happens is, when we provide search term like "com" its search all words that include "com" without applying any context.

For ex: complementary, compress, computation and including all website like google.com

But as soon as we add another search term like "net" AI search get contextual information that we are searching for domain names and not words like complementary, compress, computation and so it only return result with domain names.

Due to this additional filter that AI applies by looking at context of search, we get lesser result.

  • I hope some day they'll build a non black box / artificial intelligence kind of SOSL for the cases where finding my search terms is a requirement.
    – Kasper
    Aug 4, 2017 at 8:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .