Source:
<code>public ArrayList<Pojo> getResults(String query) { query = StringNormalizer.normalize(query); ArrayList<Pojo> records = new ArrayList<>(); int relevance; String appNameNormalized; for (Pojo pojo : pojos) { relevance = 0; appNameNormalized = pojo.nameNormalized; ArrayList<Pair<Integer, Integer>> matchPositions = new ArrayList<>(); int queryPos = 0; int appPos = 0; int beginMatch = 0; int matchedWordStarts = 0; int totalWordStarts = 0; boolean match = false; for (char cApp : appNameNormalized.toCharArray()) { if (queryPos < query.length() && query.charAt(queryPos) == cApp) { if (!match) { beginMatch = appPos; match = true; } <START> if (Character.isUpperCase(pojo.name.charAt(appPos)) || appPos == 0 || Character.isWhitespace(pojo.name.charAt(appPos - 1))) <END> matchedWordStarts += 1; queryPos++; } else if (match) { matchPositions.add(Pair.create(beginMatch, appPos)); match = false; } if (Character.isUpperCase(pojo.name.charAt(appPos)) || appPos == 0 || Character.isWhitespace(pojo.name.charAt(appPos - 1))) totalWordStarts += 1; appPos++; } if (match) { matchPositions.add(Pair.create(beginMatch, appPos)); } if (queryPos == query.length()) { relevance += 20; relevance += (int)(((double)queryPos / appNameNormalized.length()) * 30); relevance += (int)(((double)matchedWordStarts / totalWordStarts) * 50); relevance *= (0.2 + 0.8 * (1.0 / matchPositions.size())); } if (relevance > 0) { pojo.setDisplayNameHighlightRegion(matchPositions); pojo.relevance = relevance; records.add(pojo); } } return records; }</code><technical_language>OQ: do want enforce a capital letter for a word</technical_language>

Target:
public ArrayList<Pojo> getResults(String query) { query = StringNormalizer.normalize(query); ArrayList<Pojo> records = new ArrayList<>(); int relevance; String appNameNormalized; ArrayList<Pair<Integer, Integer>> matchPositions; for (Pojo pojo : pojos) { relevance = 0; appNameNormalized = pojo.nameNormalized; matchPositions = null; int queryPos = 0; int appPos = 0; int beginMatch = 0; int matchedWordStarts = 0; int totalWordStarts = 0; boolean match = false; for (char cApp : appNameNormalized.toCharArray()) { if (queryPos < query.length() && query.charAt(queryPos) == cApp) { if (!match) { beginMatch = appPos; match = true; } if (Character.isUpperCase(pojo.name.charAt(appPos)) || appPos == 0 || Character.isWhitespace(pojo.name.charAt(appPos - 1))) matchedWordStarts += 1; queryPos++; } else if (match) { if (matchPositions == null) matchPositions = new ArrayList<>(); matchPositions.add(Pair.create(beginMatch, appPos)); match = false; } if (Character.isUpperCase(pojo.name.charAt(appPos)) || appPos == 0 || Character.isWhitespace(pojo.name.charAt(appPos - 1))) totalWordStarts += 1; appPos++; } if (match) { if (matchPositions == null) matchPositions = new ArrayList<>(); matchPositions.add(Pair.create(beginMatch, appPos)); } if (queryPos == query.length() && matchPositions != null) { relevance += (int)(((double)queryPos / appNameNormalized.length()) * 40); relevance += (int)(((double)matchedWordStarts / totalWordStarts) * 60); relevance *= (0.2 + 0.8 * (1.0 / matchPositions.size())); } if (relevance > 0) { pojo.setDisplayNameHighlightRegion(matchPositions); pojo.relevance = relevance; records.add(pojo); } } return records; }