use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenCore method lindenBQLScoreModelTest.
@Test
public void lindenBQLScoreModelTest() throws IOException {
String bql = "select * from linden by query is \"title:lucene\" " + "using score model test(long aa = 100000000000000, String title = ['a', 'b'], long a = 10, Double b = [1, 2, 3, 4]) " + "begin " + " float sum = 0;\n" + " for (Double m : b) {\n" + " sum += m;\n" + " }" + "writeExplanation(\"rank:%.2f, a:%d\", rank(), a); " + "return sum + rank() * 10 * a; " + "end explain";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(4, result.getTotalHits());
Assert.assertEquals(1040f, result.getHits().get(0).getScore(), 0.1f);
Assert.assertTrue(result.getHits().get(0).getExplanation().toString().contains("value:1040.0, description:rank:10.30, a:10"));
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenCore method lindenScoreModelTest.
@Test
public void lindenScoreModelTest() throws IOException {
String func = " return rank() * 10;";
LindenScoreModel model = new LindenScoreModel().setName("test").setFunc(func);
LindenSearchRequest request = new LindenSearchRequest().setQuery(LindenQueryBuilder.buildTermQuery("title", "lucene").setScoreModel(model));
LindenResult result = lindenCore.search(request);
Assert.assertEquals(4, result.getTotalHits());
Assert.assertEquals(103f, result.getHits().get(0).getScore(), 0.1f);
// bad score model function
func = " return rank() * 10 + a;";
model = new LindenScoreModel().setName("test").setFunc(func);
request = new LindenSearchRequest().setQuery(LindenQueryBuilder.buildTermQuery("title", "lucene").setScoreModel(model));
try {
lindenCore.search(request);
} catch (Exception e) {
// do nothing
}
try {
lindenCore.search(request);
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("score model test compile failed, please check score model code"));
}
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenCore method bqlNullTest.
@Test
public void bqlNullTest() throws Exception {
String bql = "select * from linden where cat1 is null";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
bql = "select * from linden by cat1 is not null";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(4, result.getTotalHits());
bql = "select * from linden where cat1 is null";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
bql = "select * from linden where title is not null";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(4, result.getTotalHits());
bql = "select * from linden by cat1 is null";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
bql = "select * from linden where cat3 is null";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(6, result.getTotalHits());
bql = "select * from linden where cat3 is not null";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(0, result.getTotalHits());
bql = "select * from linden where tagstr is null";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(3, result.getTotalHits());
bql = "select * from linden where tagstr is not null";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(3, result.getTotalHits());
bql = "select * from linden where id is not null";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(6, result.getTotalHits());
bql = "select * from linden where hotwords is not null";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(0, result.getTotalHits());
bql = "select * from linden where hotwords is null";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(6, result.getTotalHits());
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenCore method lindenBQLScoreModelPluginParamTest.
@Test
public void lindenBQLScoreModelPluginParamTest() throws IOException {
String bql = "select * from linden by flexible_query is \"lucene\" in (title) " + "using model Plugin com.xiaomi.linden.core.plugin.MockedScoreModelV1(Long param1 = $long1," + "String exp = \"$exp\"" + ")" + " source explain $exp";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(4, result.getTotalHits());
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenCore method bqlInTest.
@Test
public void bqlInTest() throws IOException {
String bql = "select * from linden where cat1 in (1, 3)";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
bql = "select * from linden where cat1 in (1)";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(1, result.getTotalHits());
bql = "select * from linden where cat1 in (1, 3) except(3)";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(1, result.getTotalHits());
bql = "select * from linden where cat2 in (1.5, 3.5)";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
bql = "select * from linden where cat2 > 1.5 and cat2 in () except(3.5)";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
}
Aggregations