Search in sources :

Example 56 with LindenResult

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);
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 57 with LindenResult

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());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 58 with LindenResult

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());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 59 with LindenResult

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"));
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) JSONObject(com.alibaba.fastjson.JSONObject) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 60 with LindenResult

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());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Aggregations

LindenResult (com.xiaomi.linden.thrift.common.LindenResult)79 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)69 Test (org.junit.Test)69 IOException (java.io.IOException)7 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)5 JSONObject (com.alibaba.fastjson.JSONObject)4 Stopwatch (com.google.common.base.Stopwatch)4 MultiLindenCoreImpl (com.xiaomi.linden.core.search.MultiLindenCoreImpl)3 LindenFlexibleQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder)3 LindenDeleteRequest (com.xiaomi.linden.thrift.common.LindenDeleteRequest)3 LindenHit (com.xiaomi.linden.thrift.common.LindenHit)3 LindenRequest (com.xiaomi.linden.thrift.common.LindenRequest)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 FlexibleQuery (com.xiaomi.linden.lucene.query.flexiblequery.FlexibleQuery)2 Response (com.xiaomi.linden.thrift.common.Response)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 DisjunctionMaxQuery (org.apache.lucene.search.DisjunctionMaxQuery)2 FilteredQuery (org.apache.lucene.search.FilteredQuery)2 Query (org.apache.lucene.search.Query)2