@Test public void testWildcards() { assertEquals("*", QueryPreprocessor.sanitize("*")); assertEquals("*", QueryPreprocessor.sanitize(" * ")); assertEquals("*?*", QueryPreprocessor.sanitize("?")); assertEquals("*?*", QueryPreprocessor.sanitize(" ? ")); assertEquals("*H*llo* *Worl*d*", QueryPreprocessor.sanitize("H*llo Worl*d")); assertEquals("*H?llo* *Worl?d*", QueryPreprocessor.sanitize("H?llo Worl?d")); }
public static String sanitize(String query) { String sanitizedQuery = ""; String sanitizedToken; ArrayList<String> tokens = tokenize(query); int i = 0; while (i < tokens.size()) { String token = tokens.get(i); if (isUnaryOperator(token)) { sanitizedToken = sanitizeUnaryOperator(token); } else if (isBinaryOperator(token)) { if ((i == 0) || isBinaryOperator(tokens.get(i - 1)) || (i >= tokens.size() - 1) || isBinaryOperator(tokens.get(i + 1))) { sanitizedToken = "" + BACKSLASH + token; } else { sanitizedToken = token; } } else { sanitizedToken = enablePartialMatches(token, 0); } if (i != 0) { sanitizedQuery += " "; } sanitizedQuery += sanitizedToken; i++; } logger.debug("Sanitized input '{}' to '{}'", query, sanitizedQuery); return sanitizedQuery; }
QueryPreprocessor { public static String sanitize(String query) { String sanitizedQuery = ""; String sanitizedToken; ArrayList<String> tokens = tokenize(query); int i = 0; while (i < tokens.size()) { String token = tokens.get(i); if (isUnaryOperator(token)) { sanitizedToken = sanitizeUnaryOperator(token); } else if (isBinaryOperator(token)) { if ((i == 0) || isBinaryOperator(tokens.get(i - 1)) || (i >= tokens.size() - 1) || isBinaryOperator(tokens.get(i + 1))) { sanitizedToken = "" + BACKSLASH + token; } else { sanitizedToken = token; } } else { sanitizedToken = enablePartialMatches(token, 0); } if (i != 0) { sanitizedQuery += " "; } sanitizedQuery += sanitizedToken; i++; } logger.debug("Sanitized input '{}' to '{}'", query, sanitizedQuery); return sanitizedQuery; } }
QueryPreprocessor { public static String sanitize(String query) { String sanitizedQuery = ""; String sanitizedToken; ArrayList<String> tokens = tokenize(query); int i = 0; while (i < tokens.size()) { String token = tokens.get(i); if (isUnaryOperator(token)) { sanitizedToken = sanitizeUnaryOperator(token); } else if (isBinaryOperator(token)) { if ((i == 0) || isBinaryOperator(tokens.get(i - 1)) || (i >= tokens.size() - 1) || isBinaryOperator(tokens.get(i + 1))) { sanitizedToken = "" + BACKSLASH + token; } else { sanitizedToken = token; } } else { sanitizedToken = enablePartialMatches(token, 0); } if (i != 0) { sanitizedQuery += " "; } sanitizedQuery += sanitizedToken; i++; } logger.debug("Sanitized input '{}' to '{}'", query, sanitizedQuery); return sanitizedQuery; } private  QueryPreprocessor(); }
QueryPreprocessor { public static String sanitize(String query) { String sanitizedQuery = ""; String sanitizedToken; ArrayList<String> tokens = tokenize(query); int i = 0; while (i < tokens.size()) { String token = tokens.get(i); if (isUnaryOperator(token)) { sanitizedToken = sanitizeUnaryOperator(token); } else if (isBinaryOperator(token)) { if ((i == 0) || isBinaryOperator(tokens.get(i - 1)) || (i >= tokens.size() - 1) || isBinaryOperator(tokens.get(i + 1))) { sanitizedToken = "" + BACKSLASH + token; } else { sanitizedToken = token; } } else { sanitizedToken = enablePartialMatches(token, 0); } if (i != 0) { sanitizedQuery += " "; } sanitizedQuery += sanitizedToken; i++; } logger.debug("Sanitized input '{}' to '{}'", query, sanitizedQuery); return sanitizedQuery; } private  QueryPreprocessor(); static String sanitize(String query); }
QueryPreprocessor { public static String sanitize(String query) { String sanitizedQuery = ""; String sanitizedToken; ArrayList<String> tokens = tokenize(query); int i = 0; while (i < tokens.size()) { String token = tokens.get(i); if (isUnaryOperator(token)) { sanitizedToken = sanitizeUnaryOperator(token); } else if (isBinaryOperator(token)) { if ((i == 0) || isBinaryOperator(tokens.get(i - 1)) || (i >= tokens.size() - 1) || isBinaryOperator(tokens.get(i + 1))) { sanitizedToken = "" + BACKSLASH + token; } else { sanitizedToken = token; } } else { sanitizedToken = enablePartialMatches(token, 0); } if (i != 0) { sanitizedQuery += " "; } sanitizedQuery += sanitizedToken; i++; } logger.debug("Sanitized input '{}' to '{}'", query, sanitizedQuery); return sanitizedQuery; } private  QueryPreprocessor(); static String sanitize(String query);  }