001
014
015 package com.liferay.util.lucene;
016
017 import com.liferay.portal.kernel.util.StringPool;
018 import com.liferay.portal.kernel.util.StringUtil;
019
020
025 public class KeywordsUtil {
026
027 public static final String[] SPECIAL = new String[] {
028 "+", "-", "&&", "||", "!", "(", ")", "{", "}", "[", "]", "^", "\"", "~",
029 "*", "?", ":", "\\"
030 };
031
032 public static String escape(String text) {
033 for (int i = SPECIAL.length - 1; i >= 0; i--) {
034 text = StringUtil.replace(
035 text, SPECIAL[i], StringPool.BACK_SLASH + SPECIAL[i]);
036 }
037
038 return text;
039 }
040
041 public static String toFuzzy(String keywords) {
042 if (keywords == null) {
043 return null;
044 }
045
046 if (!keywords.endsWith(StringPool.TILDE)) {
047 keywords = keywords + StringPool.TILDE;
048 }
049
050 return keywords;
051 }
052
053 public static String toWildcard(String keywords) {
054 if (keywords == null) {
055 return null;
056 }
057
058 if (!keywords.endsWith(StringPool.STAR)) {
059 keywords = keywords + StringPool.STAR;
060 }
061
062 return keywords;
063 }
064
065 }