Search in sources :

Example 6 with LindenScoreModel

use of com.xiaomi.linden.thrift.common.LindenScoreModel 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

LindenScoreModel (com.xiaomi.linden.thrift.common.LindenScoreModel)6 LindenInputParam (com.xiaomi.linden.thrift.common.LindenInputParam)4 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)4 Test (org.junit.Test)3 LindenFlexibleQuery (com.xiaomi.linden.thrift.common.LindenFlexibleQuery)2 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)2 LindenSearchField (com.xiaomi.linden.thrift.common.LindenSearchField)2 LindenValue (com.xiaomi.linden.thrift.common.LindenValue)2 GroupParam (com.xiaomi.linden.thrift.common.GroupParam)1 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)1 LindenResult (com.xiaomi.linden.thrift.common.LindenResult)1 LindenTerm (com.xiaomi.linden.thrift.common.LindenTerm)1 IOException (java.io.IOException)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1