/** * Returns a parsed version of the input. * * Calls <code>#parse(input, allowSingleNonLeadingWildCardPerTerm, maxLength, null, true)</code> * * @param input the user input * @param allowSingleNonLeadingWildCardPerTerm if there is allowed one wildcard (* or ?) per term (however, still * not allowed as leading for a term) * @param maxLength the maxLength of the returned parsed input * @return the parsed version of the <code>input</code>. When <code>input</code> is <code>null</code>, * <code>null</code> is returned */ public static String parse(final String input, final boolean allowSingleNonLeadingWildCardPerTerm, int maxLength) { return parse(input, allowSingleNonLeadingWildCardPerTerm, maxLength, null/*ignore*/, true); }
/** * <p> * Removes invalid chars, escapes some chars. If <code>allowSingleNonLeadingWildCard</code> is <code>true</code>, * there is one single non leading <code>*</code> or <code>?</code> allowed. Note, that this wildcard is not allowed * to be leading of a new word. * </p> * <p> * Recommended is to remove all wildcards * </p> * * @param input the user input * @param allowSingleNonLeadingWildCardPerTerm if there is allowed one wildcard (* or ?) per term (however, still * not allowed as leading for a term) * @return formatted version of <code>input</code> */ public static String removeInvalidAndEscapeChars(final String input, final boolean allowSingleNonLeadingWildCardPerTerm) { return removeInvalidAndEscapeChars(input, allowSingleNonLeadingWildCardPerTerm, null/*ignore*/, false); }
/** * Returns a parsed version of the input. * * @param input the user input * @param allowSingleNonLeadingWildCardPerTerm if there is allowed one wildcard (* or ?) per term (however, still * not allowed as leading for a term) * @param ignore the chars that should not be parsed * @param retainWordBoundaries whether to retain characters such as ~ & ! when they appear in a * token as word boundaries or remove them, see also * {@link #isSpecialChar(char)} * @return the parsed version of the <code>input</code>. When <code>input</code> is <code>null</code>, * <code>null</code> is returned */ public static String parse(final String input, final boolean allowSingleNonLeadingWildCardPerTerm, final char[] ignore, final boolean retainWordBoundaries) { if (input == null) { return null; } String parsed = EncodingUtils.foldToASCIIReplacer(input); parsed = compressWhitespace(parsed); parsed = removeInvalidAndEscapeChars(parsed, allowSingleNonLeadingWildCardPerTerm, ignore, retainWordBoundaries); parsed = removeLeadingOrTrailingOrOperator(parsed); parsed = rewriteNotOperatorsToMinus(parsed); parsed = removeLeadingAndTrailingAndReplaceWithSpaceAndOperators(parsed); log.debug("Rewrote input '{}' to '{}'", input, parsed); return parsed; }
if (!ignoreChar(c, ignore) && isSpecialChar(c)) { if (c == '\"') { sb.append('\\'); if (containsNextCharAndIsNotSpecial(input, i)) { sb.append(c); if (prevChar == ' ' && containsNextCharAndIsNotSpecial(input, i)) { sb.append(c); } else if (c == '-') { if (containsNextCharAndIsNotSpecial(input, i)) { sb.append(c); } else if (retainWordBoundaries && i != 0 && input.charAt(i-1) != ' ' && containsNextCharAndIsNotSpecial(input, i)) { sb.append(' '); log.debug("Rewrote input '{}' to '{}'", input, output); return compressWhitespace(output);
private static boolean containsNextCharAndIsNotSpecial(final String input, final int cursor) { if ((input.length() > cursor + 1) && !isSpecialChar(input.charAt(cursor + 1))) { return true; } return false; }
text = SearchInputParsingUtils.removeLeadingWildCardsFromWords(text); if (!text.equals(fullTextSearch)) { log.warn("Replaced fullTextSearch '{}' with '{}' as " +
/** * Returns a parsed version of the input. * * @param input the user input * @param allowSingleNonLeadingWildCardPerTerm if there is allowed one wildcard (* or ?) per term (however, still * not allowed as leading for a term) * @return the parsed version of the <code>input</code>. When <code>input</code> is <code>null</code>, * <code>null</code> is returned * * Calls <code>#parse(input, allowSingleNonLeadingWildCardPerTerm, null, true)</code> */ public static String parse(final String input, final boolean allowSingleNonLeadingWildCardPerTerm) { return parse(input, allowSingleNonLeadingWildCardPerTerm, null/*ignore*/, true); }
/** * <p> * Removes invalid chars, escapes some chars. If <code>allowSingleNonLeadingWildCard</code> is <code>true</code>, * there is one single non leading <code>*</code> or <code>?</code> allowed. Note, that this wildcard is not allowed * to be leading of a new word. * </p> * <p> * Recommended is to remove all wildcards * </p> * * @param input the user input * @param allowSingleNonLeadingWildCardPerTerm if there is allowed one wildcard (* or ?) per term (however, still * not allowed as leading for a term) * @param ignore the chars that should not be parsed * @return formatted version of <code>input</code> */ public static String removeInvalidAndEscapeChars(final String input, final boolean allowSingleNonLeadingWildCardPerTerm, final char[] ignore) { return removeInvalidAndEscapeChars(input, allowSingleNonLeadingWildCardPerTerm, ignore, false); }
/** * Returns a parsed version of the input. * * Calls <code>#parse(input, allowSingleNonLeadingWildCardPerTerm, null, retainWordBoundaries)</code> * * @param input the user input * @param allowSingleNonLeadingWildCardPerTerm if there is allowed one wildcard (* or ?) per term (however, still * not allowed as leading for a term) * @param retainWordBoundaries whether to retain characters such as ~ & ! when they appear in a * token as word boundaries or remove them, see also * {@link #isSpecialChar(char)} * @return the parsed version of the <code>input</code>. When <code>input</code> is <code>null</code>, * <code>null</code> is returned */ public static String parse(final String input, final boolean allowSingleNonLeadingWildCardPerTerm, final boolean retainWordBoundaries) { return parse(input, allowSingleNonLeadingWildCardPerTerm, null/*ignore*/, retainWordBoundaries); }
/** * Returns a parsed version of the input. * * Calls <code>#parse(input, allowSingleNonLeadingWildCardPerTerm, ignore, true)</code> * * @param input the user input * @param allowSingleNonLeadingWildCardPerTerm if there is allowed one wildcard (* or ?) per term (however, still * not allowed as leading for a term) * @param ignore the chars that should not be parsed * @return the parsed version of the <code>input</code>. When <code>input</code> is <code>null</code>, * <code>null</code> is returned */ public static String parse(final String input, final boolean allowSingleNonLeadingWildCardPerTerm, final char[] ignore) { return parse(input, allowSingleNonLeadingWildCardPerTerm, ignore, true); }
/** * Returns a parsed version of the input. * * Calls <code>#parse(input, allowSingleNonLeadingWildCardPerTerm, maxLength, ignore, true)</code> * * @param input the user input * @param allowSingleNonLeadingWildCardPerTerm if there is allowed one wildcard (* or ?) per term (however, still * not allowed as leading for a term) * @param maxLength the maxLength of the returned parsed input * @param ignore the chars that should not be parsed * @return the parsed version of the <code>input</code>. When <code>input</code> is <code>null</code>, * <code>null</code> is returned */ public static String parse(final String input, final boolean allowSingleNonLeadingWildCardPerTerm, final int maxLength, final char[] ignore) { return parse(input, allowSingleNonLeadingWildCardPerTerm, maxLength, ignore, true); }
@Nullable public String cleanupSearchQuery(final String query) { return SearchInputParsingUtils.parse(query, false); }
/** * Returns a parsed version of the input. * * @param input the user input * @param allowSingleNonLeadingWildCardPerTerm if there is allowed one wildcard (* or ?) per term (however, still * not allowed as leading for a term) * @param maxLength the maxLength of the returned parsed input * @param ignore the chars that should not be parsed * @param retainWordBoundaries whether to retain characters such as ~ & ! when they appear in a * token as word boundaries or remove them, see also * {@link #isSpecialChar(char)} * @return the parsed version of the <code>input</code>. When <code>input</code> is <code>null</code>, * <code>null</code> is returned */ public static String parse(final String input, final boolean allowSingleNonLeadingWildCardPerTerm, final int maxLength, final char[] ignore, final boolean retainWordBoundaries) { if (input == null) { return null; } String parsed = parse(input, allowSingleNonLeadingWildCardPerTerm, ignore, retainWordBoundaries); if (parsed.length() > maxLength) { parsed = parsed.substring(0, maxLength); } log.debug("Rewrote input '{}' to '{}'", input, parsed); return parsed; }