@Test(expected = InvalidParameterException.class) public final void testDisallowedFieldBoost() { String searchFormat = "somefield:(%1$s) fieldwithweight:(%1$s)^5 superfield:(%1$s)^8797"; sut.boostField(searchFormat, "notAllowed", Integer.parseInt("10")); }
public String boostField(final String inFormatString, final String fieldName, final int weight) { if (!allowableBoostFields.contains(fieldName)) { throw new InvalidParameterException("The input field name is not in the list of allowed fields."); } String formatString = inFormatString; Pattern searchPattern = Pattern.compile(fieldName + ":\\(%1\\$s\\)(\\^[0-9]+)?"); Matcher patternMatcher = searchPattern.matcher(formatString); if (patternMatcher.find()) { formatString = patternMatcher.replaceFirst(fieldName + ":(%1\\$s)^" + weight); } else { formatString += " " + fieldName + ":(%1$s)^" + weight; } return formatString; }
LuceneFieldBooster { public String boostField(final String inFormatString, final String fieldName, final int weight) { if (!allowableBoostFields.contains(fieldName)) { throw new InvalidParameterException("The input field name is not in the list of allowed fields."); } String formatString = inFormatString; Pattern searchPattern = Pattern.compile(fieldName + ":\\(%1\\$s\\)(\\^[0-9]+)?"); Matcher patternMatcher = searchPattern.matcher(formatString); if (patternMatcher.find()) { formatString = patternMatcher.replaceFirst(fieldName + ":(%1\\$s)^" + weight); } else { formatString += " " + fieldName + ":(%1$s)^" + weight; } return formatString; } }
LuceneFieldBooster { public String boostField(final String inFormatString, final String fieldName, final int weight) { if (!allowableBoostFields.contains(fieldName)) { throw new InvalidParameterException("The input field name is not in the list of allowed fields."); } String formatString = inFormatString; Pattern searchPattern = Pattern.compile(fieldName + ":\\(%1\\$s\\)(\\^[0-9]+)?"); Matcher patternMatcher = searchPattern.matcher(formatString); if (patternMatcher.find()) { formatString = patternMatcher.replaceFirst(fieldName + ":(%1\\$s)^" + weight); } else { formatString += " " + fieldName + ":(%1$s)^" + weight; } return formatString; }  }
LuceneFieldBooster { public String boostField(final String inFormatString, final String fieldName, final int weight) { if (!allowableBoostFields.contains(fieldName)) { throw new InvalidParameterException("The input field name is not in the list of allowed fields."); } String formatString = inFormatString; Pattern searchPattern = Pattern.compile(fieldName + ":\\(%1\\$s\\)(\\^[0-9]+)?"); Matcher patternMatcher = searchPattern.matcher(formatString); if (patternMatcher.find()) { formatString = patternMatcher.replaceFirst(fieldName + ":(%1\\$s)^" + weight); } else { formatString += " " + fieldName + ":(%1$s)^" + weight; } return formatString; }  void setAllowableBoostFields(final List<String> inAllowableBoostFields); String boostField(final String inFormatString, final String fieldName, final int weight); }
LuceneFieldBooster { public String boostField(final String inFormatString, final String fieldName, final int weight) { if (!allowableBoostFields.contains(fieldName)) { throw new InvalidParameterException("The input field name is not in the list of allowed fields."); } String formatString = inFormatString; Pattern searchPattern = Pattern.compile(fieldName + ":\\(%1\\$s\\)(\\^[0-9]+)?"); Matcher patternMatcher = searchPattern.matcher(formatString); if (patternMatcher.find()) { formatString = patternMatcher.replaceFirst(fieldName + ":(%1\\$s)^" + weight); } else { formatString += " " + fieldName + ":(%1$s)^" + weight; } return formatString; }  void setAllowableBoostFields(final List<String> inAllowableBoostFields); String boostField(final String inFormatString, final String fieldName, final int weight);  }