001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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            public String spellCheckKeywords(SearchContext searchContext)
036                    throws SearchException {
037    
038                    if (_querySuggester == null) {
039                            if (_log.isDebugEnabled()) {
040                                    _log.debug("No query suggester configured");
041                            }
042    
043                            return StringPool.BLANK;
044                    }
045    
046                    return _querySuggester.spellCheckKeywords(searchContext);
047            }
048    
049            public Map<String, List<String>> spellCheckKeywords(
050                            SearchContext searchContext, int max)
051                    throws SearchException {
052    
053                    if (_querySuggester == null) {
054                            if (_log.isDebugEnabled()) {
055                                    _log.debug("No query suggester configured");
056                            }
057    
058                            return Collections.emptyMap();
059                    }
060    
061                    return _querySuggester.spellCheckKeywords(searchContext, max);
062            }
063    
064            public String[] suggestKeywordQueries(SearchContext searchContext, int max)
065                    throws SearchException {
066    
067                    if (_querySuggester == null) {
068                            if (_log.isDebugEnabled()) {
069                                    _log.debug("No query suggester configured");
070                            }
071    
072                            return StringPool.EMPTY_ARRAY;
073                    }
074    
075                    return _querySuggester.suggestKeywordQueries(searchContext, max);
076            }
077    
078            private static Log _log = LogFactoryUtil.getLog(BaseIndexSearcher.class);
079    
080            private QuerySuggester _querySuggester;
081    
082    }