use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestLindenFacet method facetTest3.
// test with query and filter
@Test
public void facetTest3() throws Exception {
LindenSearchRequest request = new LindenSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(13, result.getTotalHits());
String bql = "select * from linden by query is 'Title:Lisa' where Language='en' browse by Author, PublishDate";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
Assert.assertEquals(2, result.getFacetResultsSize());
// Author facet
Assert.assertEquals("LindenFacetResult(dim:Author, value:2, childCount:1, " + "labelValues:[LindenLabelAndValue(label:Lisa, value:2)])", result.getFacetResults().get(0).toString());
// PublishDate facet
Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:2, childCount:1, " + "labelValues:[LindenLabelAndValue(label:2012, value:2)])", result.getFacetResults().get(1).toString());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestLindenFieldCache method intListTest.
@Test
public void intListTest() throws IOException {
String bql = "select * from linden by query is \"title:lucene\" " + "using score model test " + "begin " + " float sum = 0;\n" + " for (int a : ids_int()) {\n" + " sum += a;\n" + " }\n" + " return sum;\n" + "end";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(10, result.getTotalHits());
Assert.assertEquals(30, result.getHits().get(0).getScore(), 0.1f);
bql = "select * from linden where ids_int = 2 " + "using score model test " + "begin " + " float sum = 0;\n" + " for (int a : ids_int()) {\n" + " sum += a;\n" + " }\n" + " return sum;\n" + "end";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(3, result.getTotalHits());
Assert.assertEquals(9, result.getHits().get(0).getScore(), 0.1f);
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestLindenGroupSearch method groupSearchTest3.
// dynamic field
@Test
public void groupSearchTest3() throws IOException {
String bql = "select * from linden order by rank group by cat1.STRING TOP 3 limit 0,10 source";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
Assert.assertEquals(true, request.isSetGroupParam());
Assert.assertEquals("cat1", request.getGroupParam().getGroupField());
Assert.assertEquals(3, request.getGroupParam().getGroupInnerLimit());
LindenResult result = lindenCore.search(request);
Assert.assertEquals(true, result.isSuccess());
Assert.assertEquals(5, result.getTotalHits());
Assert.assertEquals(3, result.getTotalGroups());
Assert.assertEquals(3, result.getHitsSize());
Assert.assertEquals(2, result.getHits().get(0).getGroupHitsSize());
Assert.assertEquals("10.3", result.getHits().get(0).getGroupHits().get(0).getFields().get("rank"));
Assert.assertEquals("4.5", result.getHits().get(0).getGroupHits().get(1).getFields().get("rank"));
Assert.assertEquals(1, result.getHits().get(1).getGroupHitsSize());
Assert.assertEquals("10.0", result.getHits().get(1).getGroupHits().get(0).getFields().get("rank"));
Assert.assertEquals(2, result.getHits().get(2).getGroupHitsSize());
Assert.assertEquals("4.0", result.getHits().get(2).getGroupHits().get(0).getFields().get("rank"));
Assert.assertEquals("1.2", result.getHits().get(2).getGroupHits().get(1).getFields().get("rank"));
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestLindenGroupSearch method groupSearchTest2.
@Test
public void groupSearchTest2() throws IOException {
String bql = "select title,field1,cat1,rank from linden by flexible_query is 'lucene' in (title, field1)" + " USING MODEL test" + " begin " + " float sum = 0;\n" + " for (int i = 0; i < getFieldLength(); ++i) {\n" + " for (int j = 0; j < getTermLength(); ++j) {\n" + " sum += getScore(i, j) * rank();\n" + " }\n" + " }\n" + " return sum;" + " end " + " group by cat1 TOP 3" + " limit 0,10 " + " source explain";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
Assert.assertEquals(true, request.isSetGroupParam());
Assert.assertEquals("cat1", request.getGroupParam().getGroupField());
Assert.assertEquals(3, request.getGroupParam().getGroupInnerLimit());
LindenResult result = lindenCore.search(request);
Assert.assertEquals(true, result.isSuccess());
Assert.assertEquals(5, result.getTotalHits());
Assert.assertEquals(3, result.getTotalGroups());
Assert.assertEquals(3, result.getHitsSize());
Assert.assertEquals(2, result.getHits().get(0).getGroupHitsSize());
Assert.assertEquals(1, result.getHits().get(1).getGroupHitsSize());
Assert.assertEquals(2, result.getHits().get(2).getGroupHitsSize());
bql = "select * from linden order by rank group by cat1 TOP 3 limit 0,10 source";
request = bqlCompiler.compile(bql).getSearchRequest();
Assert.assertEquals(true, request.isSetGroupParam());
Assert.assertEquals("cat1", request.getGroupParam().getGroupField());
Assert.assertEquals(3, request.getGroupParam().getGroupInnerLimit());
result = lindenCore.search(request);
Assert.assertEquals(true, result.isSuccess());
Assert.assertEquals(5, result.getTotalHits());
Assert.assertEquals(3, result.getTotalGroups());
Assert.assertEquals(3, result.getHitsSize());
Assert.assertEquals(2, result.getHits().get(0).getGroupHitsSize());
Assert.assertEquals("10.3", result.getHits().get(0).getGroupHits().get(0).getFields().get("rank"));
Assert.assertEquals("4.5", result.getHits().get(0).getGroupHits().get(1).getFields().get("rank"));
Assert.assertEquals(1, result.getHits().get(1).getGroupHitsSize());
Assert.assertEquals("10.0", result.getHits().get(1).getGroupHits().get(0).getFields().get("rank"));
Assert.assertEquals(2, result.getHits().get(2).getGroupHitsSize());
Assert.assertEquals("4.0", result.getHits().get(2).getGroupHits().get(0).getFields().get("rank"));
Assert.assertEquals("1.2", result.getHits().get(2).getGroupHits().get(1).getFields().get("rank"));
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestLindenSnippet method passageLimitTest.
@Test
public void passageLimitTest() throws IOException {
String bql = "SELECT * FROM linden by query is 'title:小米6' or query is 'body:小米6' snippet title, body";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals("新发布的<b>小米</b><b>6</b>如何? 想买<b>小米</b><b>6</b>吗? 4月28日开抢<b>小米</b><b>6</b>. 哪里抢<b>小米</b><b>6</b>? 告诉你也没用, 反正你都买不到<b>小米</b><b>6</b>", result.getHits().get(0).getSnippets().get("title").getSnippet());
Assert.assertEquals("<b>小米</b><b>6</b>号称7年巅峰之作,新一代性能怪兽。中国首发骁龙835处理器+标配6GB内存,安兔兔综合跑分184292,<b>小米</b><b>6</b>超越再竖立安卓标杆。", result.getHits().get(0).getSnippets().get("body").getSnippet());
}
Aggregations