use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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.LindenSearchRequest 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.LindenSearchRequest 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.LindenSearchRequest 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());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestMultiLindenCore method testDocNumDivision.
@Test
public void testDocNumDivision() throws Exception {
String path = FilenameUtils.concat(INDEX_DIR, "size/");
lindenConfig.setIndexDirectory(path).setLindenCoreMode(LindenConfig.LindenCoreMode.HOTSWAP).setMultiIndexDivisionType(LindenConfig.MultiIndexDivisionType.DOC_NUM).setMultiIndexDocNumLimit(100).setMultiIndexMaxLiveIndexNum(4);
Deencapsulation.setField(DocNumLimitMultiIndexStrategy.class, "INDEX_CHECK_INTERVAL_MILLISECONDS", -10);
lindenCore = new MultiLindenCoreImpl(lindenConfig);
for (int i = 0; i < 400; ++i) {
JSONObject json = new JSONObject();
json.put("type", "index");
JSONObject content = new JSONObject();
content.put("id", i);
content.put("title", "test " + i);
json.put("content", content);
handleRequest(json.toJSONString());
}
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(4, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(400, lindenCore.getServiceInfo().getDocsNum());
String bql = "select * from linden source";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(400, result.getTotalHits());
for (int i = 0; i < 400; ++i) {
JSONObject json = new JSONObject();
json.put("type", "index");
JSONObject content = new JSONObject();
content.put("id", i + 400);
content.put("title", "test " + i);
json.put("content", content);
handleRequest(json.toJSONString());
}
lindenCore.commit();
lindenCore.refresh();
LindenServiceInfo serviceInfo = lindenCore.getServiceInfo();
Assert.assertEquals(4, serviceInfo.getIndexNamesSize());
Assert.assertEquals(400, serviceInfo.getDocsNum());
lindenCore.close();
}
Aggregations