001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.search;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.StringPool;
020    
021    import java.util.Collections;
022    import java.util.List;
023    import java.util.Map;
024    
025    /**
026     * @author Michael C. Han
027     */
028    public abstract class BaseIndexSearcher
029            implements IndexSearcher, QuerySuggester {
030    
031            public void setQuerySuggester(QuerySuggester querySuggester) {
032                    _querySuggester = querySuggester;
033            }
034    
035            @Override
036            public String spellCheckKeywords(SearchContext searchContext)
037                    throws SearchException {
038    
039                    if (_querySuggester == null) {
040                            if (_log.isDebugEnabled()) {
041                                    _log.debug("No query suggester configured");
042                            }
043    
044                            return StringPool.BLANK;
045                    }
046    
047                    return _querySuggester.spellCheckKeywords(searchContext);
048            }
049    
050            @Override
051            public Map<String, List<String>> spellCheckKeywords(
052                            SearchContext searchContext, int max)
053                    throws SearchException {
054    
055                    if (_querySuggester == null) {
056                            if (_log.isDebugEnabled()) {
057                                    _log.debug("No query suggester configured");
058                            }
059    
060                            return Collections.emptyMap();
061                    }
062    
063                    return _querySuggester.spellCheckKeywords(searchContext, max);
064            }
065    
066            @Override
067            public String[] suggestKeywordQueries(SearchContext searchContext, int max)
068                    throws SearchException {
069    
070                    if (_querySuggester == null) {
071                            if (_log.isDebugEnabled()) {
072                                    _log.debug("No query suggester configured");
073                            }
074    
075                            return StringPool.EMPTY_ARRAY;
076                    }
077    
078                    return _querySuggester.suggestKeywordQueries(searchContext, max);
079            }
080    
081            private static Log _log = LogFactoryUtil.getLog(BaseIndexSearcher.class);
082    
083            private QuerySuggester _querySuggester;
084    
085    }