private static Pattern buildCharsAnywherePattern(final String lowerCaseInput) {
        final StringBuilder patternBuilder = new StringBuilder();
        for (int i = 0; i < lowerCaseInput.length(); i++) {
            patternBuilder.append(".*?"); // no-greedy match all
            char chr = lowerCaseInput.charAt(i);
            if (Character.isLetterOrDigit(chr)) {
                patternBuilder.append(chr);
            } else {
                // Might be a special char so escape it
                patternBuilder.append(Pattern.quote(String.valueOf(chr)));
            }
        }
        patternBuilder.append(".*?");
        return Pattern.compile(patternBuilder.toString(), Pattern.CASE_INSENSITIVE);
    }
For a given user input this method will return a function that can evaluate a string to see how
good the match is. The quality of the match is determined by the length of the matched region
(shorter == better) and its distance from the start of the string (closer == better).
stroom-query/stroom-query-common/src/main/java/stroom/query/common/v2/StringPredicateFactory.java