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.Arrays;
021    import java.util.Collection;
022    import java.util.Collections;
023    import java.util.HashSet;
024    import java.util.Set;
025    
026    /**
027     * @author Michael C. Han
028     */
029    public class FuzzyLikeThisQuery extends BaseQueryImpl {
030    
031            public FuzzyLikeThisQuery(String likeText) {
032                    _likeText = likeText;
033            }
034    
035            @Override
036            public <T> T accept(QueryVisitor<T> queryVisitor) {
037                    return queryVisitor.visitQuery(this);
038            }
039    
040            public void addField(String field) {
041                    _fields.add(field);
042            }
043    
044            public void addFields(Collection<String> fields) {
045                    _fields.addAll(fields);
046            }
047    
048            public void addFields(String... fields) {
049                    _fields.addAll(Arrays.asList(fields));
050            }
051    
052            public String getAnalyzer() {
053                    return _analyzer;
054            }
055    
056            public Set<String> getFields() {
057                    return Collections.unmodifiableSet(_fields);
058            }
059    
060            public Float getFuzziness() {
061                    return _fuzziness;
062            }
063    
064            public String getLikeText() {
065                    return _likeText;
066            }
067    
068            public Integer getMaxQueryTerms() {
069                    return _maxQueryTerms;
070            }
071    
072            public Integer getPrefixLength() {
073                    return _prefixLength;
074            }
075    
076            public boolean isFieldsEmpty() {
077                    return _fields.isEmpty();
078            }
079    
080            public Boolean isIgnoreTermFrequency() {
081                    return _ignoreTermFrequency;
082            }
083    
084            public void setAnalyzer(String analyzer) {
085                    _analyzer = analyzer;
086            }
087    
088            public void setFuzziness(Float fuzziness) {
089                    _fuzziness = fuzziness;
090            }
091    
092            public void setIgnoreTermFrequency(Boolean ignoreTermFrequency) {
093                    _ignoreTermFrequency = ignoreTermFrequency;
094            }
095    
096            public void setMaxQueryTerms(Integer maxQueryTerms) {
097                    _maxQueryTerms = maxQueryTerms;
098            }
099    
100            public void setPrefixLength(Integer prefixLength) {
101                    _prefixLength = prefixLength;
102            }
103    
104            private String _analyzer;
105            private final Set<String> _fields = new HashSet<>();
106            private Float _fuzziness;
107            private Boolean _ignoreTermFrequency;
108            private final String _likeText;
109            private Integer _maxQueryTerms;
110            private Integer _prefixLength;
111    
112    }