Search in sources :

Example 31 with LindenSearchRequest

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());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenFlexibleQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) GroupParam(com.xiaomi.linden.thrift.common.GroupParam) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 32 with LindenSearchRequest

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());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 33 with LindenSearchRequest

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());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 34 with LindenSearchRequest

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());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 35 with LindenSearchRequest

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();
}
Also used : LindenServiceInfo(com.xiaomi.linden.thrift.common.LindenServiceInfo) 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

LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)95 Test (org.junit.Test)90 LindenResult (com.xiaomi.linden.thrift.common.LindenResult)69 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)13 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)9 LindenBooleanQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder)5 LindenBooleanFilter (com.xiaomi.linden.thrift.common.LindenBooleanFilter)5 IOException (java.io.IOException)5 JSONObject (com.alibaba.fastjson.JSONObject)4 LindenBooleanSubFilter (com.xiaomi.linden.thrift.common.LindenBooleanSubFilter)4 LindenDeleteRequest (com.xiaomi.linden.thrift.common.LindenDeleteRequest)4 LindenScoreModel (com.xiaomi.linden.thrift.common.LindenScoreModel)4 Stopwatch (com.google.common.base.Stopwatch)3 MultiLindenCoreImpl (com.xiaomi.linden.core.search.MultiLindenCoreImpl)3 LindenFlexibleQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder)3 LindenFacet (com.xiaomi.linden.thrift.common.LindenFacet)3 LindenFacetDimAndPath (com.xiaomi.linden.thrift.common.LindenFacetDimAndPath)3 LindenFacetParam (com.xiaomi.linden.thrift.common.LindenFacetParam)3 LindenRequest (com.xiaomi.linden.thrift.common.LindenRequest)3 LindenTerm (com.xiaomi.linden.thrift.common.LindenTerm)3