In a previous post we talked about basic use of the Anything pattern.
One "poltergeist" issue we may face is having an Anything pattern not catching long, multiple word user inputs. In our specific case it was only taking up to 4 word street names.
Everything seems to be working perfectly, but "mysteriously" 5+ word street names are not taken, what is the problem or how do we solve it?
Well, it took me a few to understand why wasn't working, and I found the answer looking at the BasicMatching.pkg library (where the Anything patterns are stored):
subpattern Anything {minlength="1" maxlength="100" score="MACRO_WEAK_SCORE" style="raw"}
subpattern AnythingWeaker {minlength="1" maxlength="100" score="MACRO_WEAKER_SCORE" style="raw"}
[...]
As I've marked in bold in the code fragment, the default Anything gets matched with something with a weak score (45 "points"), but there is a AnythingWeaker version which can handle even worse scorings (35 "points").
This is logic, because long user inputs will probably not only be unmatched, but get lower scores than short ones (the different between existing patterns and failed one gets bigger as the input increases length).
I've been able to capture 12 word user inputs using AnythingWeaker, so it should be enough... but for a real "catch-all", there is an unused score macro called FAILED_SCORE which captures inputs with 0 score :O
Tags: Development