mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
#594 - ElasticSearch - multi match support
This commit is contained in:
1 parent
34dcc98908
commit
faf7df1c69
12 files changed
+524
-95
No files matched your search
@@ -4,6 +4,7 @@ import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.TextExpressionList;
|
||||
import com.avaje.ebean.TextJunction;
|
||||
import com.avaje.ebean.search.Match;
|
||||
import com.avaje.ebean.search.MultiMatch;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
import com.avaje.ebeaninternal.api.SpiTextJunction;
|
||||
|
||||
@@ -47,6 +48,16 @@ class DTextJunction<T> extends JunctionExpression<T> implements SpiTextJunction<
|
||||
return exprList.match(propertyName, search, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextExpressionList<T> multiMatch(String query, String... properties) {
|
||||
return exprList.multiMatch(query, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextExpressionList<T> multiMatch(String query, MultiMatch options) {
|
||||
return exprList.multiMatch(query, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextJunction<T> must() {
|
||||
return exprList.must();
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.avaje.ebean.TextExpressionList;
|
||||
import com.avaje.ebean.TextJunction;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.search.Match;
|
||||
import com.avaje.ebean.search.MultiMatch;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionFactory;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
|
||||
@@ -44,6 +45,11 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
|
||||
return new TextMatchExpression(propertyName, search, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression textMultiMatch(String query, MultiMatch options) {
|
||||
return new TextMultiMatchExpression(query, options);
|
||||
}
|
||||
|
||||
public Expression jsonExists(String propertyName, String path) {
|
||||
return new JsonPathExpression(propertyName, path, Op.EXISTS, null);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.avaje.ebeaninternal.server.expression;
|
||||
import com.avaje.ebean.*;
|
||||
import com.avaje.ebean.event.BeanQueryRequest;
|
||||
import com.avaje.ebean.search.Match;
|
||||
import com.avaje.ebean.search.MultiMatch;
|
||||
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
|
||||
import com.avaje.ebeaninternal.api.ManyWhereJoins;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
@@ -864,6 +865,17 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T>, SpiTextEx
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextExpressionList<T> multiMatch(String query, String... fields) {
|
||||
return multiMatch(query, new MultiMatch().fields(fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextExpressionList<T> multiMatch(String query, MultiMatch options) {
|
||||
add(expr.textMultiMatch(query, options));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextJunction<T> must() {
|
||||
return textJunction(TextJunction.Type.MUST);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.avaje.ebeaninternal.server.expression;
|
||||
import com.avaje.ebean.LikeType;
|
||||
import com.avaje.ebean.TextJunction;
|
||||
import com.avaje.ebean.search.Match;
|
||||
import com.avaje.ebean.search.MultiMatch;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -98,6 +99,11 @@ public interface DocQueryContext {
|
||||
*/
|
||||
void writeMatch(String propName, String search, Match options) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a Multi-match expression.
|
||||
*/
|
||||
void writeMultiMatch(String search, MultiMatch options) throws IOException;
|
||||
|
||||
/**
|
||||
* Start a Bool which may contain some of Must, Must Not, Should.
|
||||
*/
|
||||
@@ -117,4 +123,5 @@ public interface DocQueryContext {
|
||||
* End the Bool group.
|
||||
*/
|
||||
void endBoolGroup() throws IOException;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -44,9 +45,9 @@ public class TextMatchExpression extends AbstractExpression {
|
||||
public void queryPlanHash(HashQueryPlanBuilder builder) {
|
||||
builder.add(TextMatchExpression.class).add(propName).add(search);
|
||||
if (options != null) {
|
||||
builder.add(options.isAnd());
|
||||
builder.add(options.getBoost());
|
||||
builder.add(options.getMinShouldMatch());
|
||||
builder.add(options.isPhrase());
|
||||
builder.add(options.isPhrasePrefix());
|
||||
addHash(builder, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,4 +73,20 @@ public class TextMatchExpression extends AbstractExpression {
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
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 {
|
||||
|
||||
private final String search;
|
||||
|
||||
private final MultiMatch options;
|
||||
|
||||
public TextMultiMatchExpression(String search, MultiMatch options) {
|
||||
super(null);
|
||||
this.search = search;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDocQuery(DocQueryContext context) throws IOException {
|
||||
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