use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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.LindenSearchRequest 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.LindenSearchRequest 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.LindenSearchRequest 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());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestLindenCore method notEqualTest.
@Test
public void notEqualTest() throws Exception {
String bql = "select * from linden where id <> '3'";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(5, result.getTotalHits());
bql = "select * from linden where field1 <> 'aaa'";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(5, result.getTotalHits());
bql = "select * from linden by field1 <> 'aaa'";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(5, result.getTotalHits());
}
Aggregations