mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-06 08:33:18 +00:00
#589 - ElasticSearch - refactor to DocQueryContext
This commit is contained in:
1 parent
da8766533f
commit
37b86f2191
32 files changed
+155
-788
No files matched your search
@@ -1,19 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class BaseElasticTest extends BaseTestCase {
|
||||
|
||||
public ElasticExpressionContext context() throws IOException {
|
||||
|
||||
BeanDescriptor<Order> desc = getBeanDescriptor(Order.class);
|
||||
return new ElasticExpressionContext(Ebean.json(), desc);
|
||||
}
|
||||
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SimpleExpressionElasticTest extends BaseElasticTest {
|
||||
|
||||
@Test
|
||||
public void writeElastic() throws Exception {
|
||||
|
||||
SimpleExpression eqExp = new SimpleExpression("name", Op.EQ, "rob");
|
||||
|
||||
ElasticExpressionContext context = context();
|
||||
eqExp.writeElastic(context);
|
||||
|
||||
String json = context.flush();
|
||||
|
||||
assertThat(json).isEqualTo("{\"term\":{\"name\":\"rob\"}}");
|
||||
}
|
||||
}
|
||||
-82
@@ -1,82 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.querydefn;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionList;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
import com.avaje.ebeaninternal.server.expression.BaseElasticTest;
|
||||
import com.avaje.ebeaninternal.server.expression.ElasticExpressionContext;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DefaultOrmQueryElasticTest extends BaseElasticTest {
|
||||
|
||||
@Test
|
||||
public void writeElastic_on_SpiExpressionList() throws IOException {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.where().eq("customer.name", "Rob")
|
||||
.query();
|
||||
|
||||
SpiQuery<Order> spiQuery = (SpiQuery<Order>)query;
|
||||
|
||||
SpiExpressionList<Order> whereExpressions = spiQuery.getWhereExpressions();
|
||||
|
||||
ElasticExpressionContext context = context();
|
||||
JsonGenerator json = context.json();
|
||||
json.writeStartObject();
|
||||
json.writeFieldName("filter");
|
||||
|
||||
whereExpressions.writeElastic(context);
|
||||
|
||||
json.writeEndObject();
|
||||
|
||||
assertThat(context.flush()).isEqualTo("{\"filter\":{\"term\":{\"customer.name\":\"Rob\"}}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeElastic() throws IOException {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.select("status, customer.name, details.product.id")
|
||||
.where().eq("customer.name", "Rob")
|
||||
.query();
|
||||
|
||||
SpiQuery<Order> spiQuery = (SpiQuery<Order>)query;
|
||||
|
||||
ElasticExpressionContext context = context();
|
||||
spiQuery.writeElastic(context);
|
||||
|
||||
assertThat(context.flush()).isEqualTo("{\"fields\":[\"status\",\"customer.name\",\"details.product.id\"],\"query\":{\"filtered\":{\"filter\":{\"term\":{\"customer.name\":\"Rob\"}}}}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asElasticQuery() throws IOException {
|
||||
|
||||
String elasticQuery = Ebean.find(Order.class)
|
||||
.select("status")
|
||||
.where().eq("customer.name", "Rob")
|
||||
.query().asElasticQuery();
|
||||
|
||||
|
||||
assertThat(elasticQuery).isEqualTo("{\"fields\":[\"status\"],\"query\":{\"filtered\":{\"filter\":{\"term\":{\"customer.name\":\"Rob\"}}}}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asElasticQuery_firstRowsMaxRows() throws IOException {
|
||||
|
||||
String elasticQuery = Ebean.find(Order.class)
|
||||
.select("status")
|
||||
.setFirstRow(3)
|
||||
.setMaxRows(100)
|
||||
.where().eq("customer.name", "Rob")
|
||||
.query().asElasticQuery();
|
||||
|
||||
assertThat(elasticQuery).isEqualTo("{\"from\":3,\"size\":100,\"fields\":[\"status\"],\"query\":{\"filtered\":{\"filter\":{\"term\":{\"customer.name\":\"Rob\"}}}}}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user