001    /**
002     * Copyright (c) 2000-present 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.search.suggest.SpellCheckIndexWriter;
020    
021    /**
022     * @author Michael C. Han
023     */
024    public abstract class BaseIndexWriter
025            implements IndexWriter, SpellCheckIndexWriter {
026    
027            @Override
028            public void clearQuerySuggestionDictionaryIndexes(
029                            SearchContext searchContext)
030                    throws SearchException {
031    
032                    if (_spellCheckIndexWriter == null) {
033                            if (_log.isDebugEnabled()) {
034                                    _log.debug("No spell check index writer configured");
035                            }
036    
037                            return;
038                    }
039    
040                    _spellCheckIndexWriter.clearQuerySuggestionDictionaryIndexes(
041                            searchContext);
042            }
043    
044            @Override
045            public void clearSpellCheckerDictionaryIndexes(SearchContext searchContext)
046                    throws SearchException {
047    
048                    if (_spellCheckIndexWriter == null) {
049                            if (_log.isDebugEnabled()) {
050                                    _log.debug("No spell check index writer configured");
051                            }
052    
053                            return;
054                    }
055    
056                    _spellCheckIndexWriter.clearSpellCheckerDictionaryIndexes(
057                            searchContext);
058            }
059    
060            /**
061             * @throws SearchException
062             */
063            @Override
064            public void commit(SearchContext searchContext) throws SearchException {
065            }
066    
067            @Override
068            public void indexKeyword(
069                            SearchContext searchContext, float weight, String keywordType)
070                    throws SearchException {
071    
072                    if (_spellCheckIndexWriter == null) {
073                            if (_log.isDebugEnabled()) {
074                                    _log.debug("No spell check index writer configured");
075                            }
076    
077                            return;
078                    }
079    
080                    _spellCheckIndexWriter.indexKeyword(searchContext, weight, keywordType);
081            }
082    
083            @Override
084            public void indexQuerySuggestionDictionaries(SearchContext searchContext)
085                    throws SearchException {
086    
087                    if (_spellCheckIndexWriter == null) {
088                            if (_log.isDebugEnabled()) {
089                                    _log.debug("No spell check index writer configured");
090                            }
091    
092                            return;
093                    }
094    
095                    _spellCheckIndexWriter.indexQuerySuggestionDictionaries(searchContext);
096            }
097    
098            @Override
099            public void indexQuerySuggestionDictionary(SearchContext searchContext)
100                    throws SearchException {
101    
102                    if (_spellCheckIndexWriter == null) {
103                            if (_log.isDebugEnabled()) {
104                                    _log.debug("No spell check index writer configured");
105                            }
106    
107                            return;
108                    }
109    
110                    _spellCheckIndexWriter.indexQuerySuggestionDictionary(searchContext);
111            }
112    
113            @Override
114            public void indexSpellCheckerDictionaries(SearchContext searchContext)
115                    throws SearchException {
116    
117                    if (_spellCheckIndexWriter == null) {
118                            if (_log.isDebugEnabled()) {
119                                    _log.debug("No spell check index writer configured");
120                            }
121    
122                            return;
123                    }
124    
125                    _spellCheckIndexWriter.indexSpellCheckerDictionaries(searchContext);
126            }
127    
128            @Override
129            public void indexSpellCheckerDictionary(SearchContext searchContext)
130                    throws SearchException {
131    
132                    if (_spellCheckIndexWriter == null) {
133                            if (_log.isDebugEnabled()) {
134                                    _log.debug("No spell check index writer configured");
135                            }
136    
137                            return;
138                    }
139    
140                    _spellCheckIndexWriter.indexSpellCheckerDictionary(searchContext);
141            }
142    
143            public void setSpellCheckIndexWriter(
144                    SpellCheckIndexWriter spellCheckIndexWriter) {
145    
146                    _spellCheckIndexWriter = spellCheckIndexWriter;
147            }
148    
149            private static final Log _log = LogFactoryUtil.getLog(
150                    BaseIndexWriter.class);
151    
152            private SpellCheckIndexWriter _spellCheckIndexWriter;
153    
154    }