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            @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    }