Search in sources :

Example 6 with LindenDeleteRequest

use of com.xiaomi.linden.thrift.common.LindenDeleteRequest 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();
}
Also used : LindenDeleteRequest(com.xiaomi.linden.thrift.common.LindenDeleteRequest) LindenResult(com.xiaomi.linden.thrift.common.LindenResult) JSONObject(com.alibaba.fastjson.JSONObject) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) MultiLindenCoreImpl(com.xiaomi.linden.core.search.MultiLindenCoreImpl) Test(org.junit.Test)

Aggregations

LindenDeleteRequest (com.xiaomi.linden.thrift.common.LindenDeleteRequest)6 Test (org.junit.Test)5 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)4 LindenResult (com.xiaomi.linden.thrift.common.LindenResult)3 JSONObject (com.alibaba.fastjson.JSONObject)2 MultiLindenCoreImpl (com.xiaomi.linden.core.search.MultiLindenCoreImpl)2 LindenTerm (com.xiaomi.linden.thrift.common.LindenTerm)2 LindenBooleanFilter (com.xiaomi.linden.thrift.common.LindenBooleanFilter)1 LindenBooleanQuery (com.xiaomi.linden.thrift.common.LindenBooleanQuery)1 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)1 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)1 LindenRange (com.xiaomi.linden.thrift.common.LindenRange)1 LindenTermFilter (com.xiaomi.linden.thrift.common.LindenTermFilter)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1