0

I seem to have an odd issue where for certain text phrases being searched with sosl, not all events being queried with the sosl search are returned that should be.

For example: when FIND (meeting*) IN ALL FIELDS RETURNING Event(Id, Subject) there are events with meeting blatantly in the subject that are not coming back from the query...

For example, there is one titled 'Weekly Staff Meeting' that does not returned, also some title 'Test Meeting' that don't get returned, while one titled 'Test Meeting' does (although the Test Meeting that returns has another text field with Meeting Room X in it while the others do not have 'meeting' mentioned outside the subject).

I dynamically build the sosl search terms:

//Add wildcards to the sosl and soql search queries for the free text search if anything was entered into that filter
    List<String> searchList = description.split(',');
    //system.debug(searchList);
    String soslSearch = '';
    String soqlSearch = '';
    Set<String>soqlSet = new Set<String>();
    for(Integer i = 0; i < searchList.size(); i++){
        soslSearch += '('+searchList[i]+'*) ';
        soqlSet.add('%'+searchList[i]+'%');
        if(i < searchList.size() - 1){
            soslSearch += 'OR ';
        }
    }

Where description is a comma separated list of search keywords like 'meeting,hello,goodbye' etc... So the sosl search part will be (meeting*) OR (hello*) OR (goodbye*).

Then do:

String soslQuery = 'Find :soslSearch IN ALL FIELDS RETURNING Event(Id, Subject, StartDateTime)';

            //system.debug('If Search Filter Text And There Are Users(sosl): '+soslQuery);
            //List<List<Event>> searchListDescription = search.query(soslQuery);
            List<List<Event>> searchListDescription = withoutSharingClass.soslQueryEvents(soslQuery);

I cannot see what is incorrect about the sosl setup, or why it is doing this. Going into the effected orgs dev console and directly querying, it doesn't return all the events either. So it may perhaps not be the query but something with permissions... but wanted to see if anyone finds any issue with my query that could be causing it.

Without the text searches, I do soql queries that return everything just fine.

1 Answer 1

0

Can you try quoting the searchstring within the query and see. Print and debug this statement to see what it is actually passing.
Try this:
String soslQuery ='FIND \'' + soslSearch + '\' IN ALL FIELDS RETURNING Event(Id, Subject, StartDateTime)';

5
  • Can you add some explanation as to why this string might help the OP?
    – Adrian Larson
    Sep 15, 2017 at 20:45
  • @AdrianLarson, It has been a long time since I replied that question but I was suggesting him to try with a quoted String since I could not see anything else wrong.
    – SF Learner
    Sep 17, 2017 at 11:55
  • Please edit your post to be clearer. Most people won't bother to read the comments.
    – Adrian Larson
    Sep 17, 2017 at 14:12
  • clear with what exactly when you think that no one reads comments? i have given my suggestion and with the context it should be good.Let me know what to add to it.
    – SF Learner
    Sep 17, 2017 at 22:56
  • Please use words within your post to explain what the OP needs to change and why. If you take what you added in the comments and put it in your post instead, that should be enough...
    – Adrian Larson
    Sep 17, 2017 at 23:01

You must log in to answer this question.

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