use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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.LindenSearchRequest 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.LindenSearchRequest 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());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestLindenFacet method facetTest9.
// test facet field index as normal field
@Test
public void facetTest9() throws Exception {
String bql = "select * from Linden where Author in ('Bob', 'Frank') source";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(3, result.getHitsSize());
bql = "select * from Linden where Author not in ('Bob', 'Frank') source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(10, result.getHitsSize());
bql = "select * from Linden query Author = 'Susan' source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(4, result.getHitsSize());
bql = "select * from Linden where Author > 'A' and Author < 'G' source";
// Bob and Frank
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(3, result.getHitsSize());
bql = "select * from Linden where Author is null source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getHitsSize());
bql = "select * from Linden where Author is not null source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(10, result.getHitsSize());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestLindenFacet method facetTest10.
// dynamic field
@Test
public void facetTest10() throws Exception {
String bql = "select * from Linden browse by Author.FACET, PublishDate.facet source";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(13, result.getTotalHits());
Assert.assertEquals(2, result.getFacetResultsSize());
Assert.assertEquals("LindenHit(id:1, score:1.0, source:{\"PublishDate\":\"2010/10/15\",\"Language\":\"cn\",\"Author\":\"Bob\",\"id\":\"1\"})", result.getHits().get(0).toString());
bql = "select Author from Linden browse by Author, PublishDate source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(result.getHits().get(0).toString(), "LindenHit(id:1, score:1.0, source:{\"Author\":\"Bob\",\"id\":\"1\"})");
bql = "select * from Linden browse by Author.FACET, PublishDate.FACET drill down PublishDate.FACET('2010')";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(4, result.getTotalHits());
Assert.assertEquals(2, result.getFacetResultsSize());
// PublishDate facet
Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:4, childCount:1, labelValues:[LindenLabelAndValue(label:2010, value:4)])", result.getFacetResults().get(1).toString());
bql = "select * from Linden browse by Author.FACET, PublishDate.FACET drill sideways PublishDate.FACET('2010')";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(4, result.getTotalHits());
Assert.assertEquals(2, result.getFacetResultsSize());
// PublishDate facet is not effected by drill down Path
Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:11, childCount:4, " + "labelValues:[LindenLabelAndValue(label:2010, value:4), LindenLabelAndValue(label:2012, value:3), " + "LindenLabelAndValue(label:1999, value:3), LindenLabelAndValue(label:2013, value:1)])", result.getFacetResults().get(1).toString());
}
Aggregations