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