private static MatchInfo calculateMatchInfo(final Pattern shortestMatchPattern,
                                                final String strLower) {

        final MatchInfo result;
        if (strLower == null) {
            result = MatchInfo.noMatchInfo();
        } else {
            final Matcher matcher = shortestMatchPattern.matcher(strLower);
            int bestMatchLen = -1;
            int bestMatchIdx = -1;

            while (matcher.find()) {
                final int matchLen = matcher.end() - matcher.start();
                final int matchIdx = matcher.start();
                if (bestMatchLen == -1 || matchLen < bestMatchLen) {
                    bestMatchLen = matchLen;
                    bestMatchIdx = matchIdx;
                }
            }

            if (bestMatchLen == -1) {
                result = MatchInfo.noMatchInfo();
            } else {
                result = new MatchInfo(bestMatchLen, bestMatchIdx);
            }
        }
        return result;
    }
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