1
14
15 package com.liferay.util.lucene;
16
17 import com.liferay.portal.kernel.util.StringPool;
18 import com.liferay.portal.kernel.util.StringUtil;
19
20
27 public class KeywordsUtil {
28
29 public static final String[] SPECIAL = new String[] {
30 "+", "-", "&&", "||", "!", "(", ")", "{", "}", "[", "]", "^", "\"", "~",
31 "*", "?", ":", "\\"
32 };
33
34 public static String escape(String text) {
35 for (int i = SPECIAL.length - 1; i >= 0; i--) {
36 text = StringUtil.replace(
37 text, SPECIAL[i], StringPool.BACK_SLASH + SPECIAL[i]);
38 }
39
40 return text;
41 }
42
43 public static String toFuzzy(String keywords) {
44 if (keywords == null) {
45 return null;
46 }
47
48 if (!keywords.endsWith(StringPool.TILDE)) {
49 keywords = keywords + StringPool.TILDE;
50 }
51
52 return keywords;
53 }
54
55 public static String toWildcard(String keywords) {
56 if (keywords == null) {
57 return null;
58 }
59
60 if (!keywords.endsWith(StringPool.STAR)) {
61 keywords = keywords + StringPool.STAR;
62 }
63
64 return keywords;
65 }
66
67 }