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.BaseQueryImpl;
018    import com.liferay.portal.kernel.search.query.QueryVisitor;
019    
020    import java.util.ArrayList;
021    import java.util.Arrays;
022    import java.util.Collection;
023    import java.util.Collections;
024    import java.util.HashSet;
025    import java.util.List;
026    import java.util.Set;
027    
028    /**
029     * @author Michael C. Han
030     */
031    public class MoreLikeThisQuery extends BaseQueryImpl {
032    
033            public MoreLikeThisQuery(long companyId) {
034                    _companyId = companyId;
035            }
036    
037            @Override
038            public <T> T accept(QueryVisitor<T> queryVisitor) {
039                    return queryVisitor.visitQuery(this);
040            }
041    
042            public void addDocumentUID(String documentUID) {
043                    _documentUIDs.add(documentUID);
044            }
045    
046            public void addDocumentUIDs(Collection<String> documentUIDs) {
047                    _documentUIDs.addAll(documentUIDs);
048            }
049    
050            public void addDocumentUIDs(String... documentUIDs) {
051                    _documentUIDs.addAll(Arrays.asList(documentUIDs));
052            }
053    
054            public void addField(String field) {
055                    _fields.add(field);
056            }
057    
058            public void addFields(Collection<String> fields) {
059                    _fields.addAll(fields);
060            }
061    
062            public void addFields(String... fields) {
063                    _fields.addAll(Arrays.asList(fields));
064            }
065    
066            public void addStopWord(String stopWord) {
067                    _stopWords.add(stopWord);
068            }
069    
070            public void addStopWords(Collection<String> stopWords) {
071                    _stopWords.addAll(stopWords);
072            }
073    
074            public void addStopWords(String... stopWords) {
075                    _stopWords.addAll(Arrays.asList(stopWords));
076            }
077    
078            public String getAnalyzer() {
079                    return _analyzer;
080            }
081    
082            public long getCompanyId() {
083                    return _companyId;
084            }
085    
086            public Set<String> getDocumentUIDs() {
087                    return Collections.unmodifiableSet(_documentUIDs);
088            }
089    
090            public List<String> getFields() {
091                    return Collections.unmodifiableList(_fields);
092            }
093    
094            public String getLikeText() {
095                    return _likeText;
096            }
097    
098            public Integer getMaxDocFrequency() {
099                    return _maxDocFrequency;
100            }
101    
102            public Integer getMaxQueryTerms() {
103                    return _maxQueryTerms;
104            }
105    
106            public Integer getMaxWordLength() {
107                    return _maxWordLength;
108            }
109    
110            public Integer getMinDocFrequency() {
111                    return _minDocFrequency;
112            }
113    
114            public String getMinShouldMatch() {
115                    return _minShouldMatch;
116            }
117    
118            public Integer getMinTermFrequency() {
119                    return _minTermFrequency;
120            }
121    
122            public Integer getMinWordLength() {
123                    return _minWordLength;
124            }
125    
126            public Set<String> getStopWords() {
127                    return Collections.unmodifiableSet(_stopWords);
128            }
129    
130            public Float getTermBoost() {
131                    return _termBoost;
132            }
133    
134            public String getType() {
135                    return _type;
136            }
137    
138            public boolean isDocumentUIDsEmpty() {
139                    return _documentUIDs.isEmpty();
140            }
141    
142            public boolean isFieldsEmpty() {
143                    return _fields.isEmpty();
144            }
145    
146            public Boolean isIncludeInput() {
147                    return _includeInput;
148            }
149    
150            public void setAnalyzer(String analyzer) {
151                    _analyzer = analyzer;
152            }
153    
154            public void setIncludeInput(Boolean includeInput) {
155                    _includeInput = includeInput;
156            }
157    
158            public void setLikeText(String likeText) {
159                    _likeText = likeText;
160            }
161    
162            public void setMaxDocFrequency(Integer maxDocFrequency) {
163                    _maxDocFrequency = maxDocFrequency;
164            }
165    
166            public void setMaxQueryTerms(Integer maxQueryTerms) {
167                    _maxQueryTerms = maxQueryTerms;
168            }
169    
170            public void setMaxWordLength(Integer maxWordLength) {
171                    _maxWordLength = maxWordLength;
172            }
173    
174            public void setMinDocFrequency(Integer minDocFrequency) {
175                    _minDocFrequency = minDocFrequency;
176            }
177    
178            public void setMinShouldMatch(String minShouldMatch) {
179                    _minShouldMatch = minShouldMatch;
180            }
181    
182            public void setMinTermFrequency(Integer minTermFrequency) {
183                    _minTermFrequency = minTermFrequency;
184            }
185    
186            public void setMinWordLength(Integer minWordLength) {
187                    _minWordLength = minWordLength;
188            }
189    
190            public void setTermBoost(Float termBoost) {
191                    _termBoost = termBoost;
192            }
193    
194            public void setType(String type) {
195                    this._type = type;
196            }
197    
198            private String _analyzer;
199            private final long _companyId;
200            private final Set<String> _documentUIDs = new HashSet<>();
201            private final List<String> _fields = new ArrayList<>();
202            private Boolean _includeInput;
203            private String _likeText;
204            private Integer _maxDocFrequency;
205            private Integer _maxQueryTerms;
206            private Integer _maxWordLength;
207            private Integer _minDocFrequency;
208            private String _minShouldMatch;
209            private Integer _minTermFrequency;
210            private Integer _minWordLength;
211            private final Set<String> _stopWords = new HashSet<>();
212            private Float _termBoost;
213            private String _type;
214    
215    }