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());
}
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());
}
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);
}
Aggregations