Search in sources :

Example 6 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenCore method lindenBQLScoreModelTest.

@Test
public void lindenBQLScoreModelTest() throws IOException {
    String bql = "select * from linden by query is \"title:lucene\" " + "using score model test(long aa = 100000000000000, String title = ['a', 'b'], long a = 10, Double b = [1, 2, 3, 4]) " + "begin " + "    float sum = 0;\n" + "    for (Double m : b) {\n" + "      sum += m;\n" + "    }" + "writeExplanation(\"rank:%.2f, a:%d\", rank(), a); " + "return sum + rank() * 10 * a; " + "end explain";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(4, result.getTotalHits());
    Assert.assertEquals(1040f, result.getHits().get(0).getScore(), 0.1f);
    Assert.assertTrue(result.getHits().get(0).getExplanation().toString().contains("value:1040.0, description:rank:10.30, a:10"));
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 7 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenCore method lindenScoreModelTest.

@Test
public void lindenScoreModelTest() throws IOException {
    String func = " return rank() * 10;";
    LindenScoreModel model = new LindenScoreModel().setName("test").setFunc(func);
    LindenSearchRequest request = new LindenSearchRequest().setQuery(LindenQueryBuilder.buildTermQuery("title", "lucene").setScoreModel(model));
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(4, result.getTotalHits());
    Assert.assertEquals(103f, result.getHits().get(0).getScore(), 0.1f);
    // bad score model function
    func = " return rank() * 10 + a;";
    model = new LindenScoreModel().setName("test").setFunc(func);
    request = new LindenSearchRequest().setQuery(LindenQueryBuilder.buildTermQuery("title", "lucene").setScoreModel(model));
    try {
        lindenCore.search(request);
    } catch (Exception e) {
    // do nothing
    }
    try {
        lindenCore.search(request);
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().contains("score model test compile failed, please check score model code"));
    }
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) IOException(java.io.IOException) LindenScoreModel(com.xiaomi.linden.thrift.common.LindenScoreModel) Test(org.junit.Test)

Example 8 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenCore method bqlNullTest.

@Test
public void bqlNullTest() throws Exception {
    String bql = "select * from linden where cat1 is null";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    bql = "select * from linden by cat1 is not null";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(4, result.getTotalHits());
    bql = "select * from linden where cat1 is null";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    bql = "select * from linden where title is not null";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(4, result.getTotalHits());
    bql = "select * from linden by cat1 is null";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    bql = "select * from linden where cat3 is null";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(6, result.getTotalHits());
    bql = "select * from linden where cat3 is not null";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(0, result.getTotalHits());
    bql = "select * from linden where tagstr is null";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(3, result.getTotalHits());
    bql = "select * from linden where tagstr is not null";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(3, result.getTotalHits());
    bql = "select * from linden where id is not null";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(6, result.getTotalHits());
    bql = "select * from linden where hotwords is not null";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(0, result.getTotalHits());
    bql = "select * from linden where hotwords is null";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(6, result.getTotalHits());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 9 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenCore method lindenBQLScoreModelPluginParamTest.

@Test
public void lindenBQLScoreModelPluginParamTest() throws IOException {
    String bql = "select * from linden by flexible_query is \"lucene\" in (title) " + "using model Plugin com.xiaomi.linden.core.plugin.MockedScoreModelV1(Long param1 = $long1," + "String exp = \"$exp\"" + ")" + " source explain $exp";
    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 10 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenCore method bqlInTest.

@Test
public void bqlInTest() throws IOException {
    String bql = "select * from linden where cat1 in (1, 3)";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    bql = "select * from linden where cat1 in (1)";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(1, result.getTotalHits());
    bql = "select * from linden where cat1 in (1, 3) except(3)";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(1, result.getTotalHits());
    bql = "select * from linden where cat2 in (1.5, 3.5)";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    bql = "select * from linden where cat2 > 1.5 and cat2 in () except(3.5)";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
}
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