I am Running into something that appears to be a bug in how Salesforce SOSL queries work with knowledge.
Consider this Snippet of code:
String searchquery = 'FIND \'SEARCH TERM\' IN ALL FIELDS RETURNING Article__kav(Title, Summary, UrlName, LastPublishedDate, LastModifiedById WHERE PublishStatus =\'Online\' AND Language = \'en_US\'' +
'AND Not_Searchable__c = false OFFSET 0) WITH DATA CATEGORY DataCat__c BELOW DataKitten__c ';
System.debug(search.query(searchquery));
Then this Snippet of code:
String searchquery = 'FIND \'SEARCH TERM\' IN ALL FIELDS RETURNING Article__kav(Title, Summary, UrlName, LastPublishedDate, LastModifiedById WHERE PublishStatus =\'Online\' AND Language = \'en_US\'' +
'AND Not_Searchable__c = false) WITH DATA CATEGORY DataCat__c BELOW DataKitten__c ';
System.debug(search.query(searchquery));
Now the only difference between the two queries is OFFSET 0
, yet I am getting a completely different order. The relevance of the search seems to be completely disregarded the second I add OFFSET
to the query.
Now what's even stranger is doing the query in the developer console:
Without Offset:
FIND {SEARCH TERM} IN ALL FIELDS RETURNING Article__kav(Title, Summary, UrlName, LastPublishedDate, LastModifiedById WHERE PublishStatus ='Online' AND Language = 'en_US' AND Not_Searchable__c = false) WITH DATA CATEGORY DataCat__c BELOW DataKitten__c
With Offset:
FIND {SEARCH TERM} IN ALL FIELDS RETURNING Article__kav(Title, Summary, UrlName, LastPublishedDate, LastModifiedById WHERE PublishStatus ='Online' AND Language = 'en_US' AND Not_Searchable__c = false OFFSET 0) WITH DATA CATEGORY DataCat__c BELOW DataKitten__c
The developer console showing the same order with and without the offset. Anyone have any idea what is happening on this?
UPDATE
It appears to be adding an Order By ID when Offset is included.. but that still does not explain why this is happening.
To further clarify the SOSL_EXECUTE_BEGIN in debug log does not show the Order By ID
when it is executing the SOSL search. It's just returning the results in such a way.