Search in sources :

Example 21 with LindenSearchRequest

use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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 22 with LindenSearchRequest

use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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 23 with LindenSearchRequest

use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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 24 with LindenSearchRequest

use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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)

Example 25 with LindenSearchRequest

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

the class TestLindenCore method notEqualTest.

@Test
public void notEqualTest() throws Exception {
    String bql = "select * from linden where id <> '3'";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(5, result.getTotalHits());
    bql = "select * from linden where field1 <> 'aaa'";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(5, result.getTotalHits());
    bql = "select * from linden by field1 <> 'aaa'";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(5, result.getTotalHits());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Aggregations

LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)95 Test (org.junit.Test)90 LindenResult (com.xiaomi.linden.thrift.common.LindenResult)69 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)13 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)9 LindenBooleanQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder)5 LindenBooleanFilter (com.xiaomi.linden.thrift.common.LindenBooleanFilter)5 IOException (java.io.IOException)5 JSONObject (com.alibaba.fastjson.JSONObject)4 LindenBooleanSubFilter (com.xiaomi.linden.thrift.common.LindenBooleanSubFilter)4 LindenDeleteRequest (com.xiaomi.linden.thrift.common.LindenDeleteRequest)4 LindenScoreModel (com.xiaomi.linden.thrift.common.LindenScoreModel)4 Stopwatch (com.google.common.base.Stopwatch)3 MultiLindenCoreImpl (com.xiaomi.linden.core.search.MultiLindenCoreImpl)3 LindenFlexibleQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder)3 LindenFacet (com.xiaomi.linden.thrift.common.LindenFacet)3 LindenFacetDimAndPath (com.xiaomi.linden.thrift.common.LindenFacetDimAndPath)3 LindenFacetParam (com.xiaomi.linden.thrift.common.LindenFacetParam)3 LindenRequest (com.xiaomi.linden.thrift.common.LindenRequest)3 LindenTerm (com.xiaomi.linden.thrift.common.LindenTerm)3