use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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.LindenSearchRequest 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.LindenSearchRequest 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());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestLindenCore method flexibleQueryEmptyFieldTest.
@Test
public void flexibleQueryEmptyFieldTest() throws IOException {
String function = " if (tagnum() != 0) {\n" + " return 10f;\n" + " } else if (tagstr().length > 0) {\n" + " return 100f;\n" + " } else {\n" + " return 1f;\n" + " }";
LindenQuery flexQuery = new LindenFlexibleQueryBuilder().setQuery("lucene").addField("title").addModel("test", function).build();
LindenResult result = lindenCore.search(new LindenSearchRequest().setQuery(flexQuery));
Assert.assertEquals(4, result.getTotalHits());
Assert.assertEquals("3", result.getHits().get(0).getId());
Assert.assertEquals(100f, result.getHits().get(0).getScore(), 0.01);
Assert.assertEquals("2", result.getHits().get(1).getId());
Assert.assertEquals(10f, result.getHits().get(1).getScore(), 0.01);
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestLindenCore method basicTest.
@Test
public void basicTest() throws Exception {
LindenSearchRequest request = new LindenSearchRequest().setQuery(LindenQueryBuilder.buildTermQuery("title", "lucene"));
LindenResult result = lindenCore.search(request);
Assert.assertEquals(4, result.getTotalHits());
}
Aggregations