001package com.avaje.ebean.search;
002
003/**
004 * Simple text query options.
005 * <p>
006 * This maps to an ElasticSearch "simple text query".
007 * </p>
008 *
009 * <pre>{@code
010 *
011 *  TextSimple options = new TextSimple()
012 *       .analyzeWildcard(true)
013 *       .fields("name")
014 *       .lenient(true)
015 *       .opAnd();
016 *
017 *   List<Customer> customers = server.find(Customer.class)
018 *       .text()
019 *       .textSimple("quick brown", options)
020 *       .findList();
021 *
022 * }</pre>
023 */
024public class TextSimple {
025
026  protected String[] fields;
027
028  protected boolean operatorAnd;
029
030  protected String analyzer;
031
032  protected String flags;
033
034  protected boolean lowercaseExpandedTerms = true;
035
036  protected boolean analyzeWildcard;
037
038  protected String locale;
039
040  protected boolean lenient;
041
042  protected String minShouldMatch;
043
044  /**
045   * Construct
046   */
047  public TextSimple() {
048  }
049
050  /**
051   * Set the fields.
052   */
053  public TextSimple fields(String... fields) {
054    this.fields = fields;
055    return this;
056  }
057
058  /**
059   * Use AND as the default operator.
060   */
061  public TextSimple opAnd() {
062    this.operatorAnd = true;
063    return this;
064  }
065
066  /**
067   * Use OR as the default operator.
068   */
069  public TextSimple opOr() {
070    this.operatorAnd = false;
071    return this;
072  }
073
074  /**
075   * Set the analyzer
076   */
077  public TextSimple analyzer(String analyzer) {
078    this.analyzer = analyzer;
079    return this;
080  }
081
082  /**
083   * Set the flags.
084   */
085  public TextSimple flags(String flags) {
086    this.flags = flags;
087    return this;
088  }
089
090
091  /**
092   * Set the false to not use lowercase expanded terms.
093   */
094  public TextSimple lowercaseExpandedTerms(boolean lowercaseExpandedTerms) {
095    this.lowercaseExpandedTerms = lowercaseExpandedTerms;
096    return this;
097  }
098
099  /**
100   * Set to true to use analyze wildcard.
101   */
102  public TextSimple analyzeWildcard(boolean analyzeWildcard) {
103    this.analyzeWildcard = analyzeWildcard;
104    return this;
105  }
106
107  /**
108   * Set the locale.
109   */
110  public TextSimple locale(String locale) {
111    this.locale = locale;
112    return this;
113  }
114
115  /**
116   * Set the lenient mode.
117   */
118  public TextSimple lenient(boolean lenient) {
119    this.lenient = lenient;
120    return this;
121  }
122
123  /**
124   * Set the minimum should match.
125   */
126  public TextSimple minShouldMatch(String minShouldMatch) {
127    this.minShouldMatch = minShouldMatch;
128    return this;
129  }
130
131  /**
132   * Return lenient mode.
133   */
134  public boolean isLenient() {
135    return lenient;
136  }
137
138  /**
139   * Return true to analyse wildcard.
140   */
141  public boolean isAnalyzeWildcard() {
142    return analyzeWildcard;
143  }
144
145  /**
146   * Return lowercase expanded terms mode.
147   */
148  public boolean isLowercaseExpandedTerms() {
149    return lowercaseExpandedTerms;
150  }
151
152  /**
153   * Return true if the default operator should be AND.
154   */
155  public boolean isOperatorAnd() {
156    return operatorAnd;
157  }
158
159  /**
160   * Return the analyzer to use.
161   */
162  public String getAnalyzer() {
163    return analyzer;
164  }
165
166  /**
167   * Return the fields.
168   */
169  public String[] getFields() {
170    return fields;
171  }
172
173  /**
174   * Return the locale.
175   */
176  public String getLocale() {
177    return locale;
178  }
179
180  /**
181   * Return the flags.
182   */
183  public String getFlags() {
184    return flags;
185  }
186
187  /**
188   * Return the minimum should match.
189   */
190  public String getMinShouldMatch() {
191    return minShouldMatch;
192  }
193
194}