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.generic;
016    
017    import com.liferay.portal.kernel.search.BooleanClause;
018    import com.liferay.portal.kernel.search.BooleanClauseFactory;
019    import com.liferay.portal.kernel.search.BooleanClauseOccur;
020    import com.liferay.portal.kernel.search.BooleanClauseOccurImpl;
021    import com.liferay.portal.kernel.search.Query;
022    import com.liferay.portal.kernel.search.SearchContext;
023    import com.liferay.portal.kernel.search.filter.Filter;
024    import com.liferay.portal.kernel.search.filter.TermFilter;
025    
026    /**
027     * @author Bruno Farache
028     */
029    public class BooleanClauseFactoryImpl implements BooleanClauseFactory {
030    
031            @Override
032            public BooleanClause<Query> create(Query query, String occur) {
033                    BooleanClauseOccur booleanClauseOccur = new BooleanClauseOccurImpl(
034                            occur);
035    
036                    return new BooleanClauseImpl<>(query, booleanClauseOccur);
037            }
038    
039            /**
040             * @deprecated As of 7.0.0, replaced by {@link #create(Query, String)}
041             */
042            @Deprecated
043            @Override
044            public BooleanClause<Query> create(
045                    SearchContext searchContext, Query query, String occur) {
046    
047                    return create(query, occur);
048            }
049    
050            /**
051             * @deprecated As of 7.0.0, replaced by {@link #create(String, String,
052             *             String)}}
053             */
054            @Deprecated
055            @Override
056            public BooleanClause<Query> create(
057                    SearchContext searchContext, String field, String value, String occur) {
058    
059                    return create(field, value, occur);
060            }
061    
062            @Override
063            public BooleanClause<Query> create(
064                    String field, String value, String occur) {
065    
066                    Query query = new TermQueryImpl(field, value);
067    
068                    BooleanClauseOccur booleanClauseOccur = new BooleanClauseOccurImpl(
069                            occur);
070    
071                    return new BooleanClauseImpl<>(query, booleanClauseOccur);
072            }
073    
074            @Override
075            public BooleanClause<Filter> createFilter(
076                    Filter filter, BooleanClauseOccur booleanClauseOccur) {
077    
078                    return new BooleanClauseImpl<>(filter, booleanClauseOccur);
079            }
080    
081            @Override
082            public BooleanClause<Filter> createFilter(
083                    String field, String value, BooleanClauseOccur booleanClauseOccur) {
084    
085                    TermFilter termFilter = new TermFilter(field, value);
086    
087                    return new BooleanClauseImpl<Filter>(termFilter, booleanClauseOccur);
088            }
089    
090    }