Search in sources :

Example 56 with LindenSearchRequest

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());
}
Also used : LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) LindenQueryStringQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenQueryStringQueryBuilder) Test(org.junit.Test)

Example 57 with LindenSearchRequest

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());
}
Also used : LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 58 with LindenSearchRequest

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());
}
Also used : LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 59 with LindenSearchRequest

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);
}
Also used : LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 60 with LindenSearchRequest

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());
}
Also used : LindenInputParam(com.xiaomi.linden.thrift.common.LindenInputParam) LindenValue(com.xiaomi.linden.thrift.common.LindenValue) LindenSearchField(com.xiaomi.linden.thrift.common.LindenSearchField) LindenFlexibleQuery(com.xiaomi.linden.thrift.common.LindenFlexibleQuery) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) LindenScoreModel(com.xiaomi.linden.thrift.common.LindenScoreModel) Test(org.junit.Test)

Aggregations

LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)95 Test (org.junit.Test)90 LindenResult (com.xiaomi.linden.thrift.common.LindenResult)69 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)13 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)9 LindenBooleanQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder)5 LindenBooleanFilter (com.xiaomi.linden.thrift.common.LindenBooleanFilter)5 IOException (java.io.IOException)5 JSONObject (com.alibaba.fastjson.JSONObject)4 LindenBooleanSubFilter (com.xiaomi.linden.thrift.common.LindenBooleanSubFilter)4 LindenDeleteRequest (com.xiaomi.linden.thrift.common.LindenDeleteRequest)4 LindenScoreModel (com.xiaomi.linden.thrift.common.LindenScoreModel)4 Stopwatch (com.google.common.base.Stopwatch)3 MultiLindenCoreImpl (com.xiaomi.linden.core.search.MultiLindenCoreImpl)3 LindenFlexibleQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder)3 LindenFacet (com.xiaomi.linden.thrift.common.LindenFacet)3 LindenFacetDimAndPath (com.xiaomi.linden.thrift.common.LindenFacetDimAndPath)3 LindenFacetParam (com.xiaomi.linden.thrift.common.LindenFacetParam)3 LindenRequest (com.xiaomi.linden.thrift.common.LindenRequest)3 LindenTerm (com.xiaomi.linden.thrift.common.LindenTerm)3