use of com.xiaomi.linden.core.search.MultiLindenCoreImpl 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();
}
use of com.xiaomi.linden.core.search.MultiLindenCoreImpl in project linden by XiaoMi.
the class TestMultiLindenCore method testTimeDivision.
@Test
public void testTimeDivision() throws Exception {
String path = FilenameUtils.concat(INDEX_DIR, "time/");
lindenConfig.setIndexDirectory(path).setMultiIndexDivisionType(LindenConfig.MultiIndexDivisionType.TIME_HOUR).setLindenCoreMode(LindenConfig.LindenCoreMode.MULTI).setMultiIndexMaxLiveIndexNum(10);
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(8, 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);
content.put("title", "test " + (400 + i));
json.put("content", content);
handleRequest(json.toJSONString());
}
lindenCore.commit();
lindenCore.refresh();
result = lindenCore.search(request);
Assert.assertEquals(500, result.getTotalHits());
Assert.assertEquals(10, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(500, lindenCore.getServiceInfo().getDocsNum());
bql = "delete from linden where query is 'title:400 title:401'";
LindenDeleteRequest deleteRequest = bqlCompiler.compile(bql).getDeleteRequest();
lindenCore.delete(deleteRequest);
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(498, lindenCore.getServiceInfo().getDocsNum());
lindenCore.close();
}
use of com.xiaomi.linden.core.search.MultiLindenCoreImpl in project linden by XiaoMi.
the class TestMultiLindenCore method testIndexNameDivision.
@Test
public void testIndexNameDivision() throws Exception {
String path = FilenameUtils.concat(INDEX_DIR, "name/");
lindenConfig.setIndexDirectory(path).setLindenCoreMode(LindenConfig.LindenCoreMode.MULTI).setMultiIndexDivisionType(LindenConfig.MultiIndexDivisionType.INDEX_NAME);
lindenCore = new MultiLindenCoreImpl(lindenConfig);
for (int i = 0; i < 400; ++i) {
JSONObject json = new JSONObject();
json.put("type", "index");
json.put("index", "multi_" + i / 50);
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(8, 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());
bql = "select * from multi_0 source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(50, result.getTotalHits());
bql = "select * from non-existed source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertFalse(result.isSuccess());
bql = "select * from multi_1, multi_2 source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(100, result.getTotalHits());
handleRequest("{\"type\":\"delete_index\", \"index\":\"multi_0\"}");
bql = "select * from multi_0 source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertFalse(result.isSuccess());
handleRequest("{\"type\":\"delete_index\", \"index\":\"multi_2\"}");
Assert.assertEquals(6, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(300, lindenCore.getServiceInfo().getDocsNum());
// delete doc 50, 200, 300, 390, 397, doc 0 and doc 100 doesn't exist since multi_0 and multi_1 index are deleted
bql = "delete from linden where query is 'title:0 title:50 title:100 title:200 title:300 title:390 title:397'";
LindenDeleteRequest deleteRequest = bqlCompiler.compile(bql).getDeleteRequest();
lindenCore.delete(deleteRequest);
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(295, lindenCore.getServiceInfo().getDocsNum());
lindenCore.close();
}
Aggregations