use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenCore method lindenBQLScoreModelParamTest.
@Test
public void lindenBQLScoreModelParamTest() throws IOException {
String bql = "select * from linden by query is \"title:lucene\" " + "using score model test(Long param1 = $long1, Map<String, Double> dict = {'中文': 1.0, 'b': 2.0})" + "begin\n" + "double sum = 0;\n" + "sum += dict.get(\"中文\");\n" + "for (String entry : dict.keySet()) {\n" + "sum += dict.get(entry);\n" + "}\n" + "return sum;\n" + "end explain";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(4, result.getTotalHits());
Assert.assertEquals(4.0, result.getHits().get(0).getScore(), 0.1f);
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenCore method termQueryTest.
@Test
public void termQueryTest() throws Exception {
String bql = "select * from linden where title='lucene'";
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 testRangeQuery.
@Test
public void testRangeQuery() throws IOException {
String bql = "select * from linden where cat1 = 3";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(1, result.getTotalHits());
bql = "select * from linden where cat1 > 3";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(1, result.getTotalHits());
bql = "select * from linden where cat1 < 3";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
bql = "select * from linden where cat1 >= 3";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
bql = "select * from linden where cat1 < 3 and cat1 > 1";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(1, result.getTotalHits());
bql = "select * from linden where cat1 between 1 AND 3";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(3, result.getTotalHits());
bql = "select * from linden where cat2 > 3.5";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(1, result.getTotalHits());
bql = "select * from linden where cat2 < 3.5";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
bql = "select * from linden where cat2 between 1.5 AND 3.5";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(3, result.getTotalHits());
bql = "select * from linden by cat2 < 3.5";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
bql = "select * from linden by cat2 between 1.5 AND 3.5";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(3, result.getTotalHits());
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenDynamicField method testDynamicField.
@Test
public void testDynamicField() throws IOException {
String bql = "select id,name,level,log,host,shard,cost.long,mgroup,num.float,count.int,val.double from linden by " + " query is 'name:appstore' where query is 'cost.long:{30 TO 340]' " + " source ";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(0, result.getHitsSize());
bql = "select id,name,level,log,host,shard,cost.long,mgroup,num.float,count.int,val.double from linden by " + " query is 'name:appstore cost.long:{30 TO 340]' " + " source ";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
JSONObject hit0Source = JSON.parseObject(result.hits.get(0).getSource());
Assert.assertEquals("1", hit0Source.getString("id"));
Assert.assertEquals(30L, hit0Source.getLongValue("cost"));
bql = "select id,name,level,log,host,shard,cost.long,mgroup,num.float,count.int,val.double from linden by " + " query is 'name:appstore' where query is 'cost.long:[30 TO 340]' " + " source ";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
hit0Source = JSON.parseObject(result.hits.get(0).getSource());
Assert.assertEquals("1", hit0Source.getString("id"));
Assert.assertEquals(30L, hit0Source.getLongValue("cost"));
bql = "select id,name,level,log,host,shard,cost.long,mgroup,num.float,count.int,val.double from linden by " + " query is '+name:appstore +cost.long:{30 TO 340]' " + " source ";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(0, result.getHitsSize());
bql = "select id,name,level,log,host,shard,cost.long,mgroup,num.float,count.int,val.double from linden by " + " query is 'name:appstore' where query is 'num.float:[3 TO 340]' " + " source ";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
hit0Source = JSON.parseObject(result.hits.get(0).getSource());
Assert.assertEquals("1", hit0Source.getString("id"));
Assert.assertEquals(7.7f, hit0Source.getFloatValue("num"), 0.01);
bql = "select id,name,level,log,host,shard,cost.long,mgroup,num.float,count.int,val.double from linden by " + " query is 'name:appstore' where query is 'count.int:[3 TO 340]' " + " source ";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
hit0Source = JSON.parseObject(result.hits.get(0).getSource());
Assert.assertEquals("1", hit0Source.getString("id"));
Assert.assertEquals(3, hit0Source.getIntValue("count"));
bql = "select id,name,level,log,host,shard,cost.long,mgroup,num.float,count.int,val.double from linden by " + " query is 'name:appstore' where query is 'val.double:[3 TO 340]' " + " source ";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
hit0Source = JSON.parseObject(result.hits.get(0).getSource());
Assert.assertEquals("1", hit0Source.getString("id"));
Assert.assertEquals(10.0, hit0Source.getDoubleValue("val"), 0.01);
bql = "select id,name,level,log,host,shard,cost.long,mgroup,num.float,count.int,val.double from linden by " + " query is 'name:appstore' order by val.double source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
hit0Source = JSON.parseObject(result.hits.get(0).getSource());
Assert.assertEquals("1", hit0Source.getString("id"));
Assert.assertEquals(10.0, hit0Source.getDoubleValue("val"), 0.01);
Assert.assertEquals("10.0", result.getHits().get(0).getFields().get("val"));
bql = "select text.string from linden by query is 'name:appstore' source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
hit0Source = JSON.parseObject(result.hits.get(0).getSource());
Assert.assertEquals("1", hit0Source.getString("id"));
Assert.assertEquals("this is a tokenized string field", hit0Source.getString("text"));
bql = "select text from linden by query is 'name:appstore' source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
hit0Source = JSON.parseObject(result.hits.get(0).getSource());
Assert.assertEquals("1", hit0Source.getString("id"));
Assert.assertEquals("this is a tokenized string field", hit0Source.getString("text"));
bql = "select text from linden by query is 'text:field' source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
hit0Source = JSON.parseObject(result.hits.get(0).getSource());
Assert.assertEquals("1", hit0Source.getString("id"));
Assert.assertEquals("this is a tokenized string field", hit0Source.getString("text"));
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenFacet method facetTest2.
// test with query
@Test
public void facetTest2() 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' browse by Author, PublishDate";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(4, result.getTotalHits());
Assert.assertEquals(2, result.getFacetResultsSize());
// Author facet
Assert.assertEquals("LindenFacetResult(dim:Author, value:4, childCount:1, " + "labelValues:[LindenLabelAndValue(label:Lisa, value:4)])", result.getFacetResults().get(0).toString());
// PublishDate facet
Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:4, childCount:2, " + "labelValues:[LindenLabelAndValue(label:2010, value:2), LindenLabelAndValue(label:2012, value:2)])", result.getFacetResults().get(1).toString());
}
Aggregations