001    /**
002     * Copyright (c) 2000-2012 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.util.Validator;
018    
019    /**
020     * @author Michael C. Han
021     */
022    public class BaseQueryFactoryUtil<T> {
023    
024            public T getQueryFactory(SearchContext searchContext) {
025                    String searchEngineId = searchContext.getSearchEngineId();
026    
027                    SearchEngine searchEngine = null;
028    
029                    if (Validator.isNotNull(searchEngineId)) {
030                            searchEngine = SearchEngineUtil.getSearchEngine(searchEngineId);
031                    }
032                    else {
033                            searchEngine = SearchEngineUtil.getSearchEngine();
034                    }
035    
036                    if (searchEngine.isLuceneBased()) {
037                            return _luceneBasedQueryFactory;
038                    }
039                    else {
040                            return _genericQueryFactory;
041                    }
042            }
043    
044            public void setGenericQueryFactory(T genericQueryFactory) {
045                    _genericQueryFactory = genericQueryFactory;
046            }
047    
048            public void setLuceneBasedQueryFactory(T luceneBasedQueryFactory) {
049                    _luceneBasedQueryFactory = luceneBasedQueryFactory;
050            }
051    
052            private T _genericQueryFactory;
053            private T _luceneBasedQueryFactory;
054    
055    }