public static Function<String, MatchInfo> createMatchInfoEvaluator(final String userInput) {

        if (userInput.startsWith(CHARS_ANYWHERE_PREFIX)) {
            // chars anywhere matching so score the match base on the shortest match of the supplied
            // letters, e.g. 'oa' input for 'foobar' gives a match len of 3
            final String strippedLowerUserInput = stripPrefixesAndSuffixes(userInput).toLowerCase();
            final Pattern shortestMatchPattern = buildShortestBlocksPattern(strippedLowerUserInput);
            LOGGER.trace(() -> LogUtil.message("Pattern: {}", shortestMatchPattern.toString()));
            return str ->
                    calculateMatchInfo(shortestMatchPattern, str);
        } else if (userInput.startsWith(REGEX_PREFIX)) {
            // User supplied regex so score on the len of the matched region
            final String strippedUserInput = stripPrefixesAndSuffixes(userInput);
            try {
                final Pattern usersPattern = Pattern.compile(strippedUserInput, Pattern.CASE_INSENSITIVE);
                return str ->
                        calculateMatchInfo(usersPattern, str);
            } catch (PatternSyntaxException e) {
                // This is likely as the user may have not finished typing the regex
                return str -> MatchInfo.noMatchInfo();
            }
        } else {
            // All other modes just return a not found match info, e.g. if we are doing contains
            // it doesn't make much sense to compare the match length as it will be the same
            return str -> MatchInfo.noMatchInfo();
        }
    }
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