mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
#594 - ElasticSearch - Use AbstractTextExpression
This commit is contained in:
1 parent
93680f5d19
commit
75a84af3f8
8 files changed
+150
-374
No files matched your search
@@ -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