001package io.ebean.search;
002
003/**
004 * Options for the text match expression.
005 */
006public class MultiMatch extends AbstractMatch {
007
008  /**
009   * The MultiMatch type.
010   */
011  public enum Type {
012    BEST_FIELDS,
013    MOST_FIELDS,
014    CROSS_FIELDS,
015    PHRASE,
016    PHRASE_PREFIX
017  }
018
019  protected final String[] fields;
020
021  protected Type type = Type.BEST_FIELDS;
022
023  protected double tieBreaker;
024
025  /**
026   * Create with the given fields.
027   */
028  public static MultiMatch fields(String... fields) {
029    return new MultiMatch(fields);
030  }
031
032  /**
033   * Construct with a set of fields.
034   */
035  public MultiMatch(String... fields) {
036    this.fields = fields;
037  }
038
039  /**
040   * Set the type of query.
041   */
042  public MultiMatch type(Type type) {
043    this.type = type;
044    return this;
045  }
046
047  /**
048   * Set the tieBreaker to use.
049   */
050  public MultiMatch tieBreaker(double tieBreaker) {
051    this.tieBreaker = tieBreaker;
052    return this;
053  }
054
055  /**
056   * Use the AND operator (rather than OR).
057   */
058  public MultiMatch opAnd() {
059    operatorAnd = true;
060    return this;
061  }
062
063  /**
064   * Use the OR operator (rather than AND).
065   */
066  public MultiMatch opOr() {
067    operatorAnd = false;
068    return this;
069  }
070
071  /**
072   * Set the minimum should match value.
073   */
074  public MultiMatch minShouldMatch(String minShouldMatch) {
075    this.minShouldMatch = minShouldMatch;
076    return this;
077  }
078
079  /**
080   * Set the boost.
081   */
082  public MultiMatch boost(double boost) {
083    this.boost = boost;
084    return this;
085  }
086
087  /**
088   * Set the zero terms.
089   */
090  public MultiMatch zeroTerms(String zeroTerms) {
091    this.zeroTerms = zeroTerms;
092    return this;
093  }
094
095  /**
096   * Set the cutoff frequency.
097   */
098  public MultiMatch cutoffFrequency(double cutoffFrequency) {
099    this.cutoffFrequency = cutoffFrequency;
100    return this;
101  }
102
103  /**
104   * Set the max expansions (for phrase prefix only).
105   */
106  public MultiMatch maxExpansions(int maxExpansions) {
107    this.maxExpansions = maxExpansions;
108    return this;
109  }
110
111  /**
112   * Set the Analyzer to use for this expression.
113   */
114  public MultiMatch analyzer(String analyzer) {
115    this.analyzer = analyzer;
116    return this;
117  }
118
119  /**
120   * Set the rewrite to use.
121   */
122  public MultiMatch rewrite(String rewrite) {
123    this.rewrite = rewrite;
124    return this;
125  }
126
127  /**
128   * Return the type.
129   */
130  public Type getType() {
131    return type;
132  }
133
134  /**
135   * Return the fields to search.
136   */
137  public String[] getFields() {
138    return fields;
139  }
140
141  /**
142   * Return the tie breaker.
143   */
144  public double getTieBreaker() {
145    return tieBreaker;
146  }
147
148}