use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenFieldCache method doubleListTest.
@Test
public void doubleListTest() throws IOException {
String bql = "select * from linden by query is \"title:lucene\" " + "using score model test " + "begin " + " int base = doc();\n" + " for (double d : ids_double()) {\n" + " if (d != (double)(base++)) {\n" + " return -1.0;\n" + " }\n" + " }\n" + " return 1.0;\n" + "end";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(10, result.getTotalHits());
for (int i = 0; i < 10; ++i) {
Assert.assertTrue(result.getHits().get(i).score > 0.0);
}
}
use of com.xiaomi.linden.thrift.common.LindenResult 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.common.LindenResult in project linden by XiaoMi.
the class TestLindenSnippet method multiTest.
@Test
public void multiTest() throws IOException {
String bql = "SELECT * FROM linden by query is 'title:test AND body:best' snippet title, body";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals("This is a <b>test</b>. Just a <b>test</b> highlighting from postings. ", result.getHits().get(0).getSnippets().get("title").getSnippet());
Assert.assertEquals("I am hoping for <b>best</b>", result.getHits().get(0).getSnippets().get("body").getSnippet());
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenSnippet method basicTest.
@Test
public void basicTest() throws IOException {
String bql = "SELECT * FROM linden by query is 'title:test' snippet title";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals("This is a <b>test</b>. Just a <b>test</b> highlighting from postings. ", result.getHits().get(0).getSnippets().get("title").getSnippet());
bql = "SELECT * FROM linden by query is 'title:highlighting' snippet title";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals("<b>Highlighting</b> the first term. ", result.getHits().get(0).getSnippets().get("title").getSnippet());
bql = "SELECT * FROM linden by query is 'title:游戏' snippet title";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals("8科技早点:猎豹机版<b>游戏</b>MX2忽视小米1代6", result.getHits().get(0).getSnippets().get("title").getSnippet());
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenUpdate method updateIndex.
@Test
public void updateIndex() throws Exception {
// update document 3
handleRequest("{\"type\": \"update\", \"content\": {\"id\":3, \"tagnum\":[10]}}");
lindenCore.refresh();
String bql = "select * from linden by query is 'id:3' source";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(1, result.getHitsSize());
Assert.assertEquals("{\"field1\":\"ccc\",\"cat2\":3.5,\"tagnum\":[10],\"cat1\":3,\"rank\":4.5,\"id\":\"3\",\"title\":\"lucene 3\",\"tagstr\":\"ok\"}", result.getHits().get(0).getSource());
handleRequest("{\"type\": \"update\", \"content\": {\"id\":3, \"tagnum\":[6,7]}}");
lindenCore.refresh();
result = lindenCore.search(request);
Assert.assertEquals(1, result.getHitsSize());
Assert.assertEquals("{\"field1\":\"ccc\",\"cat2\":3.5,\"tagnum\":[6,7],\"cat1\":3,\"rank\":4.5,\"id\":\"3\",\"title\":\"lucene 3\",\"tagstr\":\"ok\"}", result.getHits().get(0).getSource());
}
Aggregations