According to SOSL reference here

? & | ! { } [ ] ( ) ^ ~ * : \ " ' + - are reserved characters and need to be escaped by \

I have a rather simple dynamic SOSL Query for searching inside FeedItem fields :

Find {*spm8\]*} IN All FIELDS RETURNING FeedItem(Body,Title ORDER BY Status DESC, CreatedDate DESC LIMIT 1000 OFFSET 0 )

Now I have FeedItems with following title:

  1. spm8_
  2. spm8?
  3. spm8<
  4. spm8>
  5. spm8]

Whenever I execute the query all of above feeditems are returned, while it was supposed to return only spm8]

Am I missing something here?

1 Answer 1


Indexes don't index punctuation as part of the word, as mentioned in How Search Breaks Up Information:

Alphanumeric terms are split at letter-number boundaries. Terms with non-alphanumeric characters, such as punctuation marks are split at the non-alphanumeric characters into alphabetic, numeric, and alphanumeric tokens.

The escape process only ensures that the SOSL won't be misinterpreted by the search engine.

  • So, @sfdcfox you mean this is normal behavior, and nothing can be one about it? or else is there any other way I can accurately return matches with 'spm8]' only? Sep 21, 2022 at 18:36
  • @AmanSharma Right. Whatever it is you're trying to do is probably better written in SOQL instead of SOSL. See the document link in the answer for more details about how records are indexed.
    – sfdcfox
    Sep 21, 2022 at 19:33
  • 1
    If you cannot switch to SOQL (e.g. because you are filtering against what are encrypted fields) then use SOSL and post-filter the results in memory.
    – Phil W
    Sep 21, 2022 at 21:06
  • 1
    @PhilW exactly, the field cannot be filtered in soql query, hence i am forced to use sosl. Sep 21, 2022 at 21:32

You must log in to answer this question.

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