@Test public void testSplitEmptyValue() { List<String> rez = SearchUtil.splitForSearch("", 0); assertTrue(rez.isEmpty()); rez = SearchUtil.splitForSearch(" ,,++||-- + - ", 3); assertArrayEquals(new String[] {",,++" }, rez.toArray()); rez = SearchUtil.splitForSearch(" ,,++||-- + - ", 0); assertArrayEquals(new String[] {",,++", "--", "+", "-" }, rez.toArray()); }
public static List<String> splitForSearch(final String phrase, final int charThreshold) { if (phrase != null) { String [] token = StringUtils.splitPreserveAllTokens(phrase, "| ;/\\"); List<String> words = new ArrayList<>(token.length); for (final String aToken : token) { if (StringUtils.isNotBlank(aToken)) { String clean = aToken.trim(); if (clean.length() >= charThreshold) { int pos = clean.length() - 1; for (; pos >= 0; pos--) { char last = clean.charAt(pos); if (last != ',' && last != '.' && last != '!' && last != '?' && last != ')' && last != '}' && last != ']') { break; } } if (pos < clean.length() - 1) { clean = clean.substring(0, pos + 1); } pos = 0; for (; pos < clean.length(); pos++) { char first = clean.charAt(pos); if (first != '(' && first != '{' && first != '[') { break; } } if (pos > 0) { clean = clean.substring(pos); } if (clean.length() >= charThreshold) { pos = clean.indexOf('-'); if (pos >= charThreshold && clean.length() > charThreshold * 2 + 1 && pos != 0 && (pos < clean.length() - charThreshold) && clean.charAt(pos + 1) != '-') { words.add(clean.substring(0, pos)); words.add(clean.substring(pos + 1, clean.length())); } else { words.add(clean); } } } } } return words; } return Collections.EMPTY_LIST; }
SearchUtil { public static List<String> splitForSearch(final String phrase, final int charThreshold) { if (phrase != null) { String [] token = StringUtils.splitPreserveAllTokens(phrase, "| ;/\\"); List<String> words = new ArrayList<>(token.length); for (final String aToken : token) { if (StringUtils.isNotBlank(aToken)) { String clean = aToken.trim(); if (clean.length() >= charThreshold) { int pos = clean.length() - 1; for (; pos >= 0; pos--) { char last = clean.charAt(pos); if (last != ',' && last != '.' && last != '!' && last != '?' && last != ')' && last != '}' && last != ']') { break; } } if (pos < clean.length() - 1) { clean = clean.substring(0, pos + 1); } pos = 0; for (; pos < clean.length(); pos++) { char first = clean.charAt(pos); if (first != '(' && first != '{' && first != '[') { break; } } if (pos > 0) { clean = clean.substring(pos); } if (clean.length() >= charThreshold) { pos = clean.indexOf('-'); if (pos >= charThreshold && clean.length() > charThreshold * 2 + 1 && pos != 0 && (pos < clean.length() - charThreshold) && clean.charAt(pos + 1) != '-') { words.add(clean.substring(0, pos)); words.add(clean.substring(pos + 1, clean.length())); } else { words.add(clean); } } } } } return words; } return Collections.EMPTY_LIST; } }
SearchUtil { public static List<String> splitForSearch(final String phrase, final int charThreshold) { if (phrase != null) { String [] token = StringUtils.splitPreserveAllTokens(phrase, "| ;/\\"); List<String> words = new ArrayList<>(token.length); for (final String aToken : token) { if (StringUtils.isNotBlank(aToken)) { String clean = aToken.trim(); if (clean.length() >= charThreshold) { int pos = clean.length() - 1; for (; pos >= 0; pos--) { char last = clean.charAt(pos); if (last != ',' && last != '.' && last != '!' && last != '?' && last != ')' && last != '}' && last != ']') { break; } } if (pos < clean.length() - 1) { clean = clean.substring(0, pos + 1); } pos = 0; for (; pos < clean.length(); pos++) { char first = clean.charAt(pos); if (first != '(' && first != '{' && first != '[') { break; } } if (pos > 0) { clean = clean.substring(pos); } if (clean.length() >= charThreshold) { pos = clean.indexOf('-'); if (pos >= charThreshold && clean.length() > charThreshold * 2 + 1 && pos != 0 && (pos < clean.length() - charThreshold) && clean.charAt(pos + 1) != '-') { words.add(clean.substring(0, pos)); words.add(clean.substring(pos + 1, clean.length())); } else { words.add(clean); } } } } } return words; } return Collections.EMPTY_LIST; }  }
SearchUtil { public static List<String> splitForSearch(final String phrase, final int charThreshold) { if (phrase != null) { String [] token = StringUtils.splitPreserveAllTokens(phrase, "| ;/\\"); List<String> words = new ArrayList<>(token.length); for (final String aToken : token) { if (StringUtils.isNotBlank(aToken)) { String clean = aToken.trim(); if (clean.length() >= charThreshold) { int pos = clean.length() - 1; for (; pos >= 0; pos--) { char last = clean.charAt(pos); if (last != ',' && last != '.' && last != '!' && last != '?' && last != ')' && last != '}' && last != ']') { break; } } if (pos < clean.length() - 1) { clean = clean.substring(0, pos + 1); } pos = 0; for (; pos < clean.length(); pos++) { char first = clean.charAt(pos); if (first != '(' && first != '{' && first != '[') { break; } } if (pos > 0) { clean = clean.substring(pos); } if (clean.length() >= charThreshold) { pos = clean.indexOf('-'); if (pos >= charThreshold && clean.length() > charThreshold * 2 + 1 && pos != 0 && (pos < clean.length() - charThreshold) && clean.charAt(pos + 1) != '-') { words.add(clean.substring(0, pos)); words.add(clean.substring(pos + 1, clean.length())); } else { words.add(clean); } } } } } return words; } return Collections.EMPTY_LIST; }  static List<String> splitForSearch(final String phrase, final int charThreshold); static String priceFacetName(final long shopId, final String currency); static long priceToLong(final BigDecimal price); static Long valToLong(final String value, final int scale); static String longToVal(final String value, final int scale); static void destroy(); static void addDestroyable(final Destroyable destroyable); }
SearchUtil { public static List<String> splitForSearch(final String phrase, final int charThreshold) { if (phrase != null) { String [] token = StringUtils.splitPreserveAllTokens(phrase, "| ;/\\"); List<String> words = new ArrayList<>(token.length); for (final String aToken : token) { if (StringUtils.isNotBlank(aToken)) { String clean = aToken.trim(); if (clean.length() >= charThreshold) { int pos = clean.length() - 1; for (; pos >= 0; pos--) { char last = clean.charAt(pos); if (last != ',' && last != '.' && last != '!' && last != '?' && last != ')' && last != '}' && last != ']') { break; } } if (pos < clean.length() - 1) { clean = clean.substring(0, pos + 1); } pos = 0; for (; pos < clean.length(); pos++) { char first = clean.charAt(pos); if (first != '(' && first != '{' && first != '[') { break; } } if (pos > 0) { clean = clean.substring(pos); } if (clean.length() >= charThreshold) { pos = clean.indexOf('-'); if (pos >= charThreshold && clean.length() > charThreshold * 2 + 1 && pos != 0 && (pos < clean.length() - charThreshold) && clean.charAt(pos + 1) != '-') { words.add(clean.substring(0, pos)); words.add(clean.substring(pos + 1, clean.length())); } else { words.add(clean); } } } } } return words; } return Collections.EMPTY_LIST; }  static List<String> splitForSearch(final String phrase, final int charThreshold); static String priceFacetName(final long shopId, final String currency); static long priceToLong(final BigDecimal price); static Long valToLong(final String value, final int scale); static String longToVal(final String value, final int scale); static void destroy(); static void addDestroyable(final Destroyable destroyable);  }