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            @Override
061            public void indexKeyword(
062                            SearchContext searchContext, float weight, String keywordType)
063                    throws SearchException {
064    
065                    if (_spellCheckIndexWriter == null) {
066                            if (_log.isDebugEnabled()) {
067                                    _log.debug("No spell check index writer configured");
068                            }
069    
070                            return;
071                    }
072    
073                    _spellCheckIndexWriter.indexKeyword(searchContext, weight, keywordType);
074            }
075    
076            @Override
077            public void indexQuerySuggestionDictionaries(SearchContext searchContext)
078                    throws SearchException {
079    
080                    if (_spellCheckIndexWriter == null) {
081                            if (_log.isDebugEnabled()) {
082                                    _log.debug("No spell check index writer configured");
083                            }
084    
085                            return;
086                    }
087    
088                    _spellCheckIndexWriter.indexQuerySuggestionDictionaries(searchContext);
089            }
090    
091            @Override
092            public void indexQuerySuggestionDictionary(SearchContext searchContext)
093                    throws SearchException {
094    
095                    if (_spellCheckIndexWriter == null) {
096                            if (_log.isDebugEnabled()) {
097                                    _log.debug("No spell check index writer configured");
098                            }
099    
100                            return;
101                    }
102    
103                    _spellCheckIndexWriter.indexQuerySuggestionDictionary(searchContext);
104            }
105    
106            @Override
107            public void indexSpellCheckerDictionaries(SearchContext searchContext)
108                    throws SearchException {
109    
110                    if (_spellCheckIndexWriter == null) {
111                            if (_log.isDebugEnabled()) {
112                                    _log.debug("No spell check index writer configured");
113                            }
114    
115                            return;
116                    }
117    
118                    _spellCheckIndexWriter.indexSpellCheckerDictionaries(searchContext);
119            }
120    
121            @Override
122            public void indexSpellCheckerDictionary(SearchContext searchContext)
123                    throws SearchException {
124    
125                    if (_spellCheckIndexWriter == null) {
126                            if (_log.isDebugEnabled()) {
127                                    _log.debug("No spell check index writer configured");
128                            }
129    
130                            return;
131                    }
132    
133                    _spellCheckIndexWriter.indexSpellCheckerDictionary(searchContext);
134            }
135    
136            public void setSpellCheckIndexWriter(
137                    SpellCheckIndexWriter spellCheckIndexWriter) {
138    
139                    _spellCheckIndexWriter = spellCheckIndexWriter;
140            }
141    
142            private static final Log _log = LogFactoryUtil.getLog(
143                    BaseIndexWriter.class);
144    
145            private SpellCheckIndexWriter _spellCheckIndexWriter;
146    
147    }