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