Hi Carles:
However, admittedly without having put an enormous amount of thought into it, your query expression looks flawed to me. Wouldn't [pits][pits][pits][pits] match anything that contained those four letters (or any subset thereof)? While the likes of "pppp" or "stst" would technically match but almost certainly isn't in your database, so would (for example) "pips", "sits" or "sips", which while being valid English words, aren't actually anagrams of "pits"? Similarly while "step" matches "pets" and "pest" correctly in this way it'd also match "sees", "tees", "sets", and presumably other non-anagram (yet valid) words.
It also wouldn't (shouldn't?) match "spits" like you've mentioned as it's a letter too long, isn't it?
I can't think of a guaranteed bulletproof easy way to do this off the top of my head, but some dusty memory in a corner of my brain suggests that I'd start with taking your dictionary file, and for each word compute a second "word" where the constituent letters are sorted in alphabetical order, and then doing the same to your search word and matching those in your query instead.
Using your example, and a handy web site at
this link, we have a list of anagrams for "pits": "tips", "spit", and of course "pits". I'd associate each of these with the equivalent sorted list of letters ("ipst") in your database, then in your query match the "sorted" word against the "sorted" search term rather than the approach you're taking. I reckon that little bit of precomputing will make your life MUCH easier (sort of a "sortedSearchWord LIKE 'ipst'") and should make the whole process much faster at the cost of a slightly larger database. Or at least this all makes sense right now while I'm not fully awake.
Hope it helps.
Domhnall.