001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }