001
014
015 package com.liferay.portal.kernel.search;
016
017 import com.liferay.portal.kernel.util.GetterUtil;
018 import com.liferay.portal.kernel.util.LocaleUtil;
019 import com.liferay.portal.kernel.util.PropsKeys;
020 import com.liferay.portal.kernel.util.PropsUtil;
021
022 import java.io.Serializable;
023
024 import java.util.HashMap;
025 import java.util.Locale;
026 import java.util.Map;
027
028
031 public class QueryConfig implements Serializable {
032
033 public static final String LOCALE = "locale";
034
035 public Serializable getAttribute(String name) {
036 return _attributes.get(name);
037 }
038
039 public Map<String, Serializable> getAttributes() {
040 return _attributes;
041 }
042
043 public int getHighlightFragmentSize() {
044 return GetterUtil.getInteger(
045 _attributes.get(PropsKeys.INDEX_SEARCH_HIGHLIGHT_FRAGMENT_SIZE),
046 _INDEX_SEARCH_HIGHLIGHT_FRAGMENT_SIZE);
047 }
048
049 public int getHighlightSnippetSize() {
050 return GetterUtil.getInteger(
051 _attributes.get(PropsKeys.INDEX_SEARCH_HIGHLIGHT_SNIPPET_SIZE),
052 _INDEX_SEARCH_HIGHLIGHT_SNIPPET_SIZE);
053 }
054
055 public Locale getLocale() {
056 Locale locale = (Locale)_attributes.get(LOCALE);
057
058 if (locale == null) {
059 locale = LocaleUtil.getMostRelevantLocale();
060 }
061
062 return locale;
063 }
064
065 public boolean isHighlightEnabled() {
066 return GetterUtil.getBoolean(
067 _attributes.get(PropsKeys.INDEX_SEARCH_HIGHLIGHT_ENABLED), false);
068 }
069
070 public boolean isScoreEnabled() {
071 return GetterUtil.getBoolean(
072 _attributes.get(PropsKeys.INDEX_SEARCH_SCORING_ENABLED),
073 _INDEX_SEARCH_SCORING_ENABLED);
074 }
075
076 public Serializable removeAttribute(String name) {
077 return _attributes.remove(name);
078 }
079
080 public void setAttribute(String name, Serializable value) {
081 _attributes.put(name, value);
082 }
083
084 public void setHighlightEnabled(boolean highlightEnabled) {
085 if (_INDEX_SEARCH_HIGHLIGHT_ENABLED) {
086 _attributes.put(
087 PropsKeys.INDEX_SEARCH_HIGHLIGHT_ENABLED, highlightEnabled);
088 }
089 else {
090 _attributes.put(PropsKeys.INDEX_SEARCH_HIGHLIGHT_ENABLED, false);
091 }
092 }
093
094 public void setHighlightFragmentSize(int highlightFragmentSize) {
095 _attributes.put(
096 PropsKeys.INDEX_SEARCH_HIGHLIGHT_FRAGMENT_SIZE,
097 highlightFragmentSize);
098 }
099
100 public void setHighlightSnippetSize(int highlightSnippetSize) {
101 _attributes.put(
102 PropsKeys.INDEX_SEARCH_HIGHLIGHT_SNIPPET_SIZE,
103 highlightSnippetSize);
104 }
105
106 public void setLocale(Locale locale) {
107 _attributes.put(LOCALE, locale);
108 }
109
110 public void setScoreEnabled(boolean scoreEnabled) {
111 _attributes.put(PropsKeys.INDEX_SEARCH_SCORING_ENABLED, scoreEnabled);
112 }
113
114 private static final boolean _INDEX_SEARCH_HIGHLIGHT_ENABLED =
115 GetterUtil.getBoolean(
116 PropsUtil.get(PropsKeys.INDEX_SEARCH_HIGHLIGHT_ENABLED));
117
118 private static final int _INDEX_SEARCH_HIGHLIGHT_FRAGMENT_SIZE =
119 GetterUtil.getInteger(
120 PropsUtil.get(PropsKeys.INDEX_SEARCH_HIGHLIGHT_FRAGMENT_SIZE));
121
122 private static final int _INDEX_SEARCH_HIGHLIGHT_SNIPPET_SIZE =
123 GetterUtil.getInteger(
124 PropsUtil.get(PropsKeys.INDEX_SEARCH_HIGHLIGHT_SNIPPET_SIZE));
125
126 private static final boolean _INDEX_SEARCH_SCORING_ENABLED =
127 GetterUtil.getBoolean(
128 PropsUtil.get(PropsKeys.INDEX_SEARCH_SCORING_ENABLED));
129
130 private Map<String, Serializable> _attributes =
131 new HashMap<String, Serializable>();
132
133 }