use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestBQL method testQueryPredicate.
@Test
public void testQueryPredicate() {
String bql = "select * from linden where query is 'title:a' and id = 233";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getFilter().isSetBooleanFilter());
Assert.assertEquals(2, lindenRequest.getFilter().getBooleanFilter().getFilters().size());
Assert.assertTrue(lindenRequest.getFilter().getBooleanFilter().getFilters().get(0).getFilter().isSetQueryFilter());
bql = "select * from linden by query is 'abc' and query is 'def' where id = 1 or id = 3";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getQuery().isSetBooleanQuery());
Assert.assertEquals(2, lindenRequest.getQuery().getBooleanQuery().getQueriesSize());
Assert.assertTrue(lindenRequest.getFilter().isSetBooleanFilter());
Assert.assertEquals(2, lindenRequest.getFilter().getBooleanFilter().getFilters().size());
bql = "select * from linden by query is 'title:abc bcd' disableCoord OP(AND)";
lindenRequest = compiler.compile(bql).getSearchRequest();
LindenQueryStringQueryBuilder builder = new LindenQueryStringQueryBuilder();
builder.setQuery("title:abc bcd").setOperator(Operator.AND);
builder.setDisableCoord(true);
LindenQuery expected = builder.build();
Assert.assertEquals(expected, lindenRequest.getQuery());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestBQL method testMatchAll.
@Test
public void testMatchAll() {
String bql = "select * from linden";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getQuery().isSetMatchAllQuery());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestBQL method testSource.
@Test
public void testSource() {
String bql = "select * from linden source explain";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.isSource());
Assert.assertTrue(lindenRequest.isExplain());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestBQL method testDisableCoord.
@Test
public void testDisableCoord() {
String bql = "select * from linden by query is 'abc' disableCoord false";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.getQuery().getQueryString().disableCoord);
bql = "select * from linden by query is 'abc' and query is 'def' disableCoord false";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().disableCoord);
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getQueryString().disableCoord);
bql = "select * from linden by query is 'abc' and query is 'def' andDisableCoord";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getQuery().getBooleanQuery().disableCoord);
bql = "select * from linden by query is 'abc' and query is 'def' disableCoord andDisableCoord";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getQuery().getBooleanQuery().disableCoord);
Assert.assertTrue(lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getQueryString().disableCoord);
bql = "select * from linden by query is 'abc' disableCoord and query is 'def' disableCoord false andDisableCoord false";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().disableCoord);
Assert.assertTrue(lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getQueryString().disableCoord);
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getQueryString().disableCoord);
bql = "select * from linden by query is 'abc' disableCoord false and query is 'def' disableCoord true andDisableCoord false";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().disableCoord);
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getQueryString().disableCoord);
Assert.assertTrue(lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getQueryString().disableCoord);
bql = "select * from linden by a = 'abc' and id = 123 andDisableCoord or b = 'def' orDisableCoord false";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().disableCoord);
Assert.assertTrue(lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBooleanQuery().disableCoord);
bql = "select * from linden by a = 'qm' and id = 123 andDisableCoord false or query is 'def' disableCoord orDisableCoord false";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().disableCoord);
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBooleanQuery().disableCoord);
Assert.assertTrue(lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getQueryString().disableCoord);
bql = "select * from linden by a = 'qm' and id = 123 or query is 'def' disableCoord orDisableCoord false";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().disableCoord);
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBooleanQuery().disableCoord);
Assert.assertTrue(lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getQueryString().disableCoord);
bql = "select * from linden by a = 'qm' and (id = 123 or query is 'def' orDisableCoord) andDisableCoord false";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().disableCoord);
Assert.assertTrue(lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBooleanQuery().disableCoord);
bql = "select * from linden by a = 'qm' or id = 123 or query is 'def' disableCoord false orDisableCoord";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getQuery().getBooleanQuery().disableCoord);
Assert.assertFalse(lindenRequest.getQuery().getBooleanQuery().getQueries().get(2).getQuery().getQueryString().disableCoord);
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestBQL method testFlexibleQuery.
@Test
public void testFlexibleQuery() {
String bql = "select * from linden by flexible_query is 'test' match 1 in (title, name^0.9)\n" + "using model test (Float a = 1, Long b = 2)\n" + "begin\n" + " return 1f;\n" + "end\n" + "where id = 231\n";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getQuery().isSetFlexQuery());
LindenFlexibleQuery lindenFlexibleQuery = new LindenFlexibleQuery().setQuery("test").setFields(Arrays.asList(new LindenSearchField("title"), new LindenSearchField("name").setBoost(0.9))).setModel(new LindenScoreModel().setName("test").setFunc("return 1f;").setParams(Arrays.asList(new LindenInputParam("a").setValue(new LindenValue().setDoubleValue(1)), new LindenInputParam("b").setValue(new LindenValue().setLongValue(2))))).setMatchRatio(1);
Assert.assertEquals(lindenFlexibleQuery, lindenRequest.getQuery().getFlexQuery());
// test full match
bql = "select * from linden by flexible_query is 'test' full_match in (title, name^0.9)\n" + "using model test (Float a = 1, Long b = 2)\n" + "begin\n" + " return 1f;\n" + "end\n" + "where id = 231\n";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getQuery().isSetFlexQuery());
lindenFlexibleQuery = new LindenFlexibleQuery().setQuery("test").setFields(Arrays.asList(new LindenSearchField("title"), new LindenSearchField("name").setBoost(0.9))).setFullMatch(true).setModel(new LindenScoreModel().setName("test").setFunc("return 1f;").setParams(Arrays.asList(new LindenInputParam("a").setValue(new LindenValue().setDoubleValue(1)), new LindenInputParam("b").setValue(new LindenValue().setLongValue(2)))));
Assert.assertEquals(lindenFlexibleQuery, lindenRequest.getQuery().getFlexQuery());
}
Aggregations