Search in sources :

Example 1 with LindenFlexibleQueryBuilder

use of com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder in project linden by XiaoMi.

the class TestLindenGroupSearch method groupSearchTest1.

@Test
public void groupSearchTest1() throws IOException {
    String function = "    float sum = 0;\n" + "    for (int i = 0; i < getFieldLength(); ++i) {\n" + "      for (int j = 0; j < getTermLength(); ++j) {\n" + "        sum += getScore(i, j) * rank();\n" + "      }\n" + "    }\n" + "    return sum;";
    LindenQuery query = new LindenFlexibleQueryBuilder().setQuery("lucene").addField("title").addModel("test", function).build();
    LindenSearchRequest request = new LindenSearchRequest().setQuery(query).setSource(false).setExplain(false);
    request.setGroupParam(new GroupParam("cat1").setGroupInnerLimit(2));
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(true, result.isSuccess());
    Assert.assertEquals(5, result.getTotalHits());
    Assert.assertEquals(3, result.getTotalGroups());
    Assert.assertEquals(3, result.getHitsSize());
    Assert.assertEquals(2, result.getHits().get(0).getGroupHitsSize());
    Assert.assertEquals(1, result.getHits().get(1).getGroupHitsSize());
    Assert.assertEquals(2, result.getHits().get(2).getGroupHitsSize());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenFlexibleQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) GroupParam(com.xiaomi.linden.thrift.common.GroupParam) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 2 with LindenFlexibleQueryBuilder

use of com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder in project linden by XiaoMi.

the class TestLindenCore method flexibleQueryTest.

@Test
public void flexibleQueryTest() throws IOException {
    String function = "    float sum = 0;\n" + "    for (int i = 0; i < getFieldLength(); ++i) {\n" + "      for (int j = 0; j < getTermLength(); ++j) {\n" + "        sum += 100 * getScore(i, j) * rank();\n" + "      }\n" + "    }\n" + "    return sum;";
    LindenQuery flexQuery = new LindenFlexibleQueryBuilder().setQuery("lucene").addField("title").addModel("test", function).build();
    LindenResult result = lindenCore.search(new LindenSearchRequest().setQuery(flexQuery));
    Assert.assertEquals(4, result.getTotalHits());
    flexQuery = new LindenFlexibleQueryBuilder().setQuery("lucene 1").addField("title").addModel("test", function).setFullMatch(true).build();
    result = lindenCore.search(new LindenSearchRequest().setQuery(flexQuery));
    Assert.assertEquals(1, result.getTotalHits());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenFlexibleQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 3 with LindenFlexibleQueryBuilder

use of com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder in project linden by XiaoMi.

the class TestLindenCore method flexibleQueryEmptyFieldTest.

@Test
public void flexibleQueryEmptyFieldTest() throws IOException {
    String function = "   if (tagnum() != 0) {\n" + "      return 10f;\n" + "    } else if (tagstr().length > 0) {\n" + "      return 100f;\n" + "    } else {\n" + "      return 1f;\n" + "    }";
    LindenQuery flexQuery = new LindenFlexibleQueryBuilder().setQuery("lucene").addField("title").addModel("test", function).build();
    LindenResult result = lindenCore.search(new LindenSearchRequest().setQuery(flexQuery));
    Assert.assertEquals(4, result.getTotalHits());
    Assert.assertEquals("3", result.getHits().get(0).getId());
    Assert.assertEquals(100f, result.getHits().get(0).getScore(), 0.01);
    Assert.assertEquals("2", result.getHits().get(1).getId());
    Assert.assertEquals(10f, result.getHits().get(1).getScore(), 0.01);
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenFlexibleQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Aggregations

LindenFlexibleQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder)3 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)3 LindenResult (com.xiaomi.linden.thrift.common.LindenResult)3 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)3 Test (org.junit.Test)3 GroupParam (com.xiaomi.linden.thrift.common.GroupParam)1