You’ll be interested in the post_search_data table, which stores tsvector information about each post (the tsvectors are weighted collections of lexemes / word roots, which postgres can compare to a search term much faster than a raw post body).
The class you’re looking for is lib/search.rb which is… well, a bit tangled, but the line which executes the search is here:
If I had a wild guess, I would guess that converting the word ‘chem123’ to a lexeme results in {'chem123':1}, which doesn’t match the tsquery 123
(The ‘f’ is for false, aka, the document ‘chem123’ isn’t a match for the search term ‘123’)
I definitely don’t have my head around a good fix for that, but I wish you luck! Maybe you could write a clause in there specifically for if the query is a number.
PS I found this post to be a really great intro to how postgres does its fulltext search.
