001package io.ebean.search;
002
003/**
004 * Text common terms query.
005 * <p>
006 * This maps to an ElasticSearch "common terms query".
007 * </p>
008 * <pre>{@code
009 *
010 *  TextCommonTerms options = new TextCommonTerms()
011 *    .cutoffFrequency(0.001)
012 *    .minShouldMatch("50%")
013 *    .lowFreqOperatorAnd(true)
014 *    .highFreqOperatorAnd(true);
015 *
016 *  List<Customer> customers = database.find(Customer.class)
017 *    .text()
018 *    .textCommonTerms("the brown", options)
019 *    .findList();
020 *
021 * }</pre>
022 * <pre>{@code
023 *
024 *   // ElasticSearch expression
025 *
026 *   "common": {
027 *     "body": {
028 *       "query": "the brown",
029 *       "cutoff_frequency": 0.001,
030 *       "low_freq_operator": "and",
031 *       "high_freq_operator": "and",
032 *       "minimum_should_match": "50%"
033 *     }
034 *   }
035 *
036 * }</pre>
037 */
038public class TextCommonTerms {
039
040  protected double cutoffFrequency;
041
042  protected boolean lowFreqOperatorAnd;
043  protected boolean highFreqOperatorAnd;
044
045  protected String minShouldMatch;
046  protected String minShouldMatchLowFreq;
047  protected String minShouldMatchHighFreq;
048
049  /**
050   * Set the cutoff frequency.
051   */
052  public TextCommonTerms cutoffFrequency(double cutoffFrequency) {
053    this.cutoffFrequency = cutoffFrequency;
054    return this;
055  }
056
057  /**
058   * Set to true if low frequency terms should use AND operator.
059   */
060  public TextCommonTerms lowFreqOperatorAnd(boolean opAnd) {
061    this.lowFreqOperatorAnd = opAnd;
062    return this;
063  }
064
065  /**
066   * Set to true if high frequency terms should use AND operator.
067   */
068  public TextCommonTerms highFreqOperatorAnd(boolean opAnd) {
069    this.highFreqOperatorAnd = opAnd;
070    return this;
071  }
072
073  /**
074   * Set the minimum should match.
075   */
076  public TextCommonTerms minShouldMatch(String minShouldMatch) {
077    this.minShouldMatch = minShouldMatch;
078    return this;
079  }
080
081  /**
082   * Set the minimum should match for low frequency terms.
083   */
084  public TextCommonTerms minShouldMatchLowFreq(String minShouldMatchLowFreq) {
085    this.minShouldMatchLowFreq = minShouldMatchLowFreq;
086    return this;
087  }
088
089  /**
090   * Set the minimum should match for high frequency terms.
091   */
092  public TextCommonTerms minShouldMatchHighFreq(String minShouldMatchHighFreq) {
093    this.minShouldMatchHighFreq = minShouldMatchHighFreq;
094    return this;
095  }
096
097  /**
098   * Return true if low freq should use the AND operator.
099   */
100  public boolean isLowFreqOperatorAnd() {
101    return lowFreqOperatorAnd;
102  }
103
104  /**
105   * Return true if high freq should use the AND operator.
106   */
107  public boolean isHighFreqOperatorAnd() {
108    return highFreqOperatorAnd;
109  }
110
111  /**
112   * Return the cutoff frequency.
113   */
114  public double getCutoffFrequency() {
115    return cutoffFrequency;
116  }
117
118  /**
119   * Return the minimum to match.
120   */
121  public String getMinShouldMatch() {
122    return minShouldMatch;
123  }
124
125  /**
126   * Return the minimum to match for high frequency.
127   */
128  public String getMinShouldMatchHighFreq() {
129    return minShouldMatchHighFreq;
130  }
131
132  /**
133   * Return the minimum to match for low frequency.
134   */
135  public String getMinShouldMatchLowFreq() {
136    return minShouldMatchLowFreq;
137  }
138
139}