use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenCore method testScoreModelPlugin.
@Test
public void testScoreModelPlugin() throws IOException {
String bql = "select * from linden where title='lucene'" + " using score model plugin com.xiaomi.linden.core.plugin.TestScoreModelStrategy" + "(Long param1 = $long1, Map<String, Double> dict = {'中文': 1.0, 'b': 2.0});";
LindenSearchRequest searchRequest = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(searchRequest);
Assert.assertEquals(4, result.getTotalHits());
Assert.assertEquals(14.3, result.getHits().get(0).getScore(), 0.01);
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenCore method likeTest.
@Test
public void likeTest() throws Exception {
String bql = "select * from linden by field1 like \"aa*\" source boost by 2";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
Query query = QueryConstructor.constructQuery(request.getQuery(), lindenConfig);
Assert.assertTrue(query instanceof WildcardQuery);
Assert.assertEquals("field1:aa*^2.0", query.toString());
LindenResult result = lindenCore.search(request);
Assert.assertEquals(1, result.getTotalHits());
bql = "select * from linden by field1 not like \"aaa*\" source";
request = bqlCompiler.compile(bql).getSearchRequest();
query = QueryConstructor.constructQuery(request.getQuery(), lindenConfig);
Assert.assertTrue(query instanceof BooleanQuery);
Assert.assertEquals("+*:* -field1:aaa*", query.toString());
result = lindenCore.search(request);
Assert.assertEquals(5, result.getTotalHits());
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenCore method testSearchById.
@Test
public void testSearchById() throws IOException {
String bql = "select * from linden where id in ('1', '2', '3')";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(3, result.getTotalHits());
bql = "select * from linden where id = '1'";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(1, result.getTotalHits());
bql = "select * from linden by id = '1'";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(1, result.getTotalHits());
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenCore method testDisMax.
@Test
public void testDisMax() throws InterruptedException, IOException {
String bql = "select * from linden source | select * from linden source";
LindenSearchRequest lindenRequest = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(lindenRequest);
Assert.assertEquals(6, result.getTotalHits());
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenCore method testFlexibleFilter.
@Test
public void testFlexibleFilter() throws Exception {
String bql = "select name from linden where flexible_query is 'qq音乐' full_match in (name^1.5) \n" + "USING MODEL test \n" + "begin\n" + " return score();\n" + "end\n" + "order by score,id limit $offset, $length source";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
Filter filter = FilterConstructor.constructFilter(request.getFilter(), lindenConfig);
Assert.assertEquals("QueryWrapperFilter(FlexibleQuery([name^1.5]:[qq,音,乐]fullMatch))", filter.toString());
bql = "select name from linden \n" + "by flexible_query is \"lucene\" in (title^1.2) \n" + "USING MODEL test1 \n" + "begin \n" + " return score() + 1;\n" + "end\n" + "where flexible_query is 'ddd' full_match in (field1)\n" + "USING MODEL filter_func begin return 1f; end \n" + "order by score,id limit $offset, $length source";
request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(1, result.getHitsSize());
Assert.assertEquals(1f, result.getHits().get(0).getScore(), DELTA5);
Assert.assertEquals("4", result.getHits().get(0).getId());
}
Aggregations