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.filter;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    
019    import java.util.Arrays;
020    import java.util.HashSet;
021    import java.util.Set;
022    
023    /**
024     * @author Michael C. Han
025     */
026    public class TermsFilter extends BaseFilter {
027    
028            public TermsFilter(String field) {
029                    _field = field;
030            }
031    
032            @Override
033            public <T> T accept(FilterVisitor<T> filterVisitor) {
034                    return filterVisitor.visit(this);
035            }
036    
037            public void addValue(String value) {
038                    _values.add(value);
039            }
040    
041            public void addValues(String... values) {
042                    _values.addAll(Arrays.asList(values));
043            }
044    
045            public Execution getExecution() {
046                    return _execution;
047            }
048    
049            public String getField() {
050                    return _field;
051            }
052    
053            @Override
054            public int getSortOrder() {
055                    return 4;
056            }
057    
058            public String[] getValues() {
059                    return _values.toArray(new String[_values.size()]);
060            }
061    
062            public boolean isEmpty() {
063                    return _values.isEmpty();
064            }
065    
066            public void setExecution(Execution execution) {
067                    _execution = execution;
068            }
069    
070            @Override
071            public String toString() {
072                    StringBundler sb = new StringBundler(7);
073    
074                    sb.append("{(");
075                    sb.append(_field);
076                    sb.append("=");
077                    sb.append(_values);
078                    sb.append("), ");
079                    sb.append(super.toString());
080                    sb.append("}");
081    
082                    return sb.toString();
083            }
084    
085            public enum Execution {
086    
087                    AND, BOOL, FIELD_DATA, OR, PLAIN;
088    
089            }
090    
091            private Execution _execution = Execution.PLAIN;
092            private final String _field;
093            private final Set<String> _values = new HashSet<>();
094    
095    }