mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#594 - ElasticSearch - Use AbstractTextExpression
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package com.avaje.ebean.search;
|
||||
|
||||
/**
|
||||
* Options for the text match and multi match expressions.
|
||||
*/
|
||||
public abstract class AbstractMatch {
|
||||
|
||||
protected boolean and;
|
||||
|
||||
protected String analyzer;
|
||||
|
||||
protected double boost;
|
||||
|
||||
protected String minShouldMatch;
|
||||
|
||||
protected int maxExpansions;
|
||||
|
||||
protected String zeroTerms;
|
||||
|
||||
protected double cutoffFrequency;
|
||||
|
||||
protected String fuzziness;
|
||||
|
||||
protected int prefixLength;
|
||||
|
||||
protected String rewrite;
|
||||
|
||||
/**
|
||||
* Return true if using the AND operator otherwise using the OR operator.
|
||||
*/
|
||||
public boolean isAnd() {
|
||||
return and;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the boost.
|
||||
*/
|
||||
public double getBoost() {
|
||||
return boost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the minimum should match.
|
||||
*/
|
||||
public String getMinShouldMatch() {
|
||||
return minShouldMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the zero terms option.
|
||||
*/
|
||||
public String getZeroTerms() {
|
||||
return zeroTerms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cutoff frequency.
|
||||
*/
|
||||
public double getCutoffFrequency() {
|
||||
return cutoffFrequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the max expansions.
|
||||
*/
|
||||
public int getMaxExpansions() {
|
||||
return maxExpansions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the analyzer.
|
||||
*/
|
||||
public String getAnalyzer() {
|
||||
return analyzer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fuzziness.
|
||||
*/
|
||||
public String getFuzziness() {
|
||||
return fuzziness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the prefix length.
|
||||
*/
|
||||
public int getPrefixLength() {
|
||||
return prefixLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rewrite option.
|
||||
*/
|
||||
public String getRewrite() {
|
||||
return rewrite;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
package com.avaje.ebean.search;
|
||||
|
||||
/**
|
||||
* Options for the text match expression.
|
||||
*/
|
||||
public abstract class BaseMatch {
|
||||
|
||||
protected boolean and;
|
||||
|
||||
protected String analyzer;
|
||||
|
||||
protected double boost;
|
||||
|
||||
protected String minShouldMatch;
|
||||
|
||||
protected int maxExpansions;
|
||||
|
||||
protected String zeroTerms;
|
||||
|
||||
protected double cutoffFrequency;
|
||||
|
||||
protected String fuzziness;
|
||||
|
||||
protected int prefixLength;
|
||||
|
||||
protected String rewrite;
|
||||
|
||||
/**
|
||||
* Return true if using the AND operator otherwise using the OR operator.
|
||||
*/
|
||||
public boolean isAnd() {
|
||||
return and;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the boost.
|
||||
*/
|
||||
public double getBoost() {
|
||||
return boost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the minimum should match.
|
||||
*/
|
||||
public String getMinShouldMatch() {
|
||||
return minShouldMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the zero terms option.
|
||||
*/
|
||||
public String getZeroTerms() {
|
||||
return zeroTerms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cutoff frequency.
|
||||
*/
|
||||
public double getCutoffFrequency() {
|
||||
return cutoffFrequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the max expansions.
|
||||
*/
|
||||
public int getMaxExpansions() {
|
||||
return maxExpansions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the analyzer.
|
||||
*/
|
||||
public String getAnalyzer() {
|
||||
return analyzer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fuzziness.
|
||||
*/
|
||||
public String getFuzziness() {
|
||||
return fuzziness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the prefix length.
|
||||
*/
|
||||
public int getPrefixLength() {
|
||||
return prefixLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rewrite option.
|
||||
*/
|
||||
public String getRewrite() {
|
||||
return rewrite;
|
||||
}
|
||||
|
||||
protected boolean baseEquals(BaseMatch baseMatch) {
|
||||
|
||||
if (and != baseMatch.and) return false;
|
||||
if (Double.compare(baseMatch.boost, boost) != 0) return false;
|
||||
if (maxExpansions != baseMatch.maxExpansions) return false;
|
||||
if (Double.compare(baseMatch.cutoffFrequency, cutoffFrequency) != 0) return false;
|
||||
if (prefixLength != baseMatch.prefixLength) return false;
|
||||
if (analyzer != null ? !analyzer.equals(baseMatch.analyzer) : baseMatch.analyzer != null) return false;
|
||||
if (minShouldMatch != null ? !minShouldMatch.equals(baseMatch.minShouldMatch) : baseMatch.minShouldMatch != null) return false;
|
||||
if (zeroTerms != null ? !zeroTerms.equals(baseMatch.zeroTerms) : baseMatch.zeroTerms != null) return false;
|
||||
if (fuzziness != null ? !fuzziness.equals(baseMatch.fuzziness) : baseMatch.fuzziness != null) return false;
|
||||
return rewrite != null ? rewrite.equals(baseMatch.rewrite) : baseMatch.rewrite == null;
|
||||
}
|
||||
|
||||
protected int baseHashCode() {
|
||||
|
||||
int result;
|
||||
long temp;
|
||||
result = (and ? 1 : 0);
|
||||
result = 31 * result + (analyzer != null ? analyzer.hashCode() : 0);
|
||||
temp = Double.doubleToLongBits(boost);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
result = 31 * result + (minShouldMatch != null ? minShouldMatch.hashCode() : 0);
|
||||
result = 31 * result + maxExpansions;
|
||||
result = 31 * result + (zeroTerms != null ? zeroTerms.hashCode() : 0);
|
||||
temp = Double.doubleToLongBits(cutoffFrequency);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
result = 31 * result + (fuzziness != null ? fuzziness.hashCode() : 0);
|
||||
result = 31 * result + prefixLength;
|
||||
result = 31 * result + (rewrite != null ? rewrite.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.avaje.ebean.search;
|
||||
/**
|
||||
* Options for the text match expression.
|
||||
*/
|
||||
public class Match extends BaseMatch {
|
||||
public class Match extends AbstractMatch {
|
||||
|
||||
protected boolean phrase;
|
||||
|
||||
@@ -125,23 +125,4 @@ public class Match extends BaseMatch {
|
||||
return phrasePrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Match match = (Match) o;
|
||||
|
||||
if (phrase != match.phrase) return false;
|
||||
if (phrasePrefix != match.phrasePrefix) return false;
|
||||
return baseEquals(match);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (phrase ? 1 : 0);
|
||||
result = 31 * result + (phrasePrefix ? 1 : 0);
|
||||
result = 31 * result + baseHashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.avaje.ebean.search;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Options for the text match expression.
|
||||
*/
|
||||
public class MultiMatch extends BaseMatch {
|
||||
public class MultiMatch extends AbstractMatch {
|
||||
|
||||
/**
|
||||
* The MultiMatch type.
|
||||
@@ -154,33 +152,4 @@ public class MultiMatch extends BaseMatch {
|
||||
return tieBreaker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
MultiMatch that = (MultiMatch) o;
|
||||
|
||||
if (Double.compare(that.tieBreaker, tieBreaker) != 0) return false;
|
||||
if (type != that.type) return false;
|
||||
if (fields.length != that.fields.length) return false;
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
if (!fields[i].equals(that.fields[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return baseEquals(that);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result;
|
||||
long temp;
|
||||
result = type.hashCode();
|
||||
result = 31 * result + Arrays.hashCode(fields);
|
||||
temp = Double.doubleToLongBits(tieBreaker);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
result = 31 * result + baseHashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
/**
|
||||
* Base class for TextExpressions that are only executable by doc store.
|
||||
* <p>
|
||||
* This means they can not be part of a SQL query nor do they use the built in query plan cache etc.
|
||||
* </p>
|
||||
*/
|
||||
public abstract class AbstractTextExpression extends AbstractExpression {
|
||||
|
||||
protected AbstractTextExpression(String propName) {
|
||||
super(propName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSql(SpiExpressionRequest request) {
|
||||
throw new IllegalStateException("Not implemented - DocStore/Elastic only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
throw new IllegalStateException("Not implemented - DocStore/Elastic only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queryPlanHash(HashQueryPlanBuilder builder) {
|
||||
throw new IllegalStateException("Not implemented - query plan caching done explicitly by the doc store");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
throw new IllegalStateException("Not implemented - query plan caching done explicitly by the doc store");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameByPlan(SpiExpression other) {
|
||||
throw new IllegalStateException("Not implemented - query plan caching done explicitly by the doc store");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameByBind(SpiExpression other) {
|
||||
throw new IllegalStateException("Not implemented - query plan caching done explicitly by the doc store");
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,13 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
import com.avaje.ebean.search.BaseMatch;
|
||||
import com.avaje.ebean.search.Match;
|
||||
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Full text MATCH expression.
|
||||
*/
|
||||
public class TextMatchExpression extends AbstractExpression {
|
||||
public class TextMatchExpression extends AbstractTextExpression {
|
||||
|
||||
private final String search;
|
||||
|
||||
@@ -28,65 +24,4 @@ public class TextMatchExpression extends AbstractExpression {
|
||||
context.writeMatch(propName, search, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSql(SpiExpressionRequest request) {
|
||||
throw new IllegalStateException("Not implemented - DocStore/Elastic only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
throw new IllegalStateException("Not implemented - DocStore/Elastic only");
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on the type and propertyName.
|
||||
*/
|
||||
@Override
|
||||
public void queryPlanHash(HashQueryPlanBuilder builder) {
|
||||
builder.add(TextMatchExpression.class).add(propName).add(search);
|
||||
if (options != null) {
|
||||
builder.add(options.isPhrase());
|
||||
builder.add(options.isPhrasePrefix());
|
||||
addHash(builder, options);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return search.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameByPlan(SpiExpression other) {
|
||||
if (!(other instanceof TextMatchExpression)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TextMatchExpression that = (TextMatchExpression) other;
|
||||
return this.propName.equals(that.propName)
|
||||
&& this.search.equals(that.search)
|
||||
&& this.options == null ? that.options == null : options.equals(that.options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameByBind(SpiExpression other) {
|
||||
TextMatchExpression that = (TextMatchExpression) other;
|
||||
return search.equals(that.search);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the hash to the builder for the base/common options.
|
||||
*/
|
||||
public static void addHash(HashQueryPlanBuilder builder, BaseMatch options) {
|
||||
builder.add(options.isAnd());
|
||||
builder.add(options.getAnalyzer());
|
||||
builder.add(options.getBoost());
|
||||
builder.add(options.getCutoffFrequency());
|
||||
builder.add(options.getFuzziness());
|
||||
builder.add(options.getMaxExpansions());
|
||||
builder.add(options.getMinShouldMatch());
|
||||
builder.add(options.getPrefixLength());
|
||||
builder.add(options.getRewrite());
|
||||
builder.add(options.getZeroTerms());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-51
@@ -1,16 +1,13 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
import com.avaje.ebean.search.MultiMatch;
|
||||
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Full text Multi-Match expression.
|
||||
*/
|
||||
public class TextMultiMatchExpression extends AbstractExpression {
|
||||
public class TextMultiMatchExpression extends AbstractTextExpression {
|
||||
|
||||
private final String search;
|
||||
|
||||
@@ -27,51 +24,4 @@ public class TextMultiMatchExpression extends AbstractExpression {
|
||||
context.writeMultiMatch(search, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSql(SpiExpressionRequest request) {
|
||||
throw new IllegalStateException("Not implemented - DocStore/Elastic only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
throw new IllegalStateException("Not implemented - DocStore/Elastic only");
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on the type and propertyName.
|
||||
*/
|
||||
@Override
|
||||
public void queryPlanHash(HashQueryPlanBuilder builder) {
|
||||
builder.add(TextMultiMatchExpression.class).add(search);
|
||||
builder.add(options.getType());
|
||||
builder.add(options.getTieBreaker());
|
||||
String[] fields = options.getFields();
|
||||
builder.add(fields.length);
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
builder.add(fields[i]);
|
||||
}
|
||||
TextMatchExpression.addHash(builder, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return search.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameByPlan(SpiExpression other) {
|
||||
if (!(other instanceof TextMultiMatchExpression)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TextMultiMatchExpression that = (TextMultiMatchExpression) other;
|
||||
return this.search.equals(that.search)
|
||||
&& this.options == null ? that.options == null : options.equals(that.options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameByBind(SpiExpression other) {
|
||||
TextMultiMatchExpression that = (TextMultiMatchExpression) other;
|
||||
return search.equals(that.search);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user