Search in sources :

Example 71 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenGroupSearch method groupSearchTest2.

@Test
public void groupSearchTest2() throws IOException {
    String bql = "select title,field1,cat1,rank from linden by flexible_query is 'lucene' in (title, field1)" + " USING MODEL test" + " begin " + "    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;" + " end " + " group by cat1 TOP 3" + " limit 0,10 " + " source explain";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    Assert.assertEquals(true, request.isSetGroupParam());
    Assert.assertEquals("cat1", request.getGroupParam().getGroupField());
    Assert.assertEquals(3, request.getGroupParam().getGroupInnerLimit());
    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());
    bql = "select * from linden order by rank group by cat1 TOP 3 limit 0,10 source";
    request = bqlCompiler.compile(bql).getSearchRequest();
    Assert.assertEquals(true, request.isSetGroupParam());
    Assert.assertEquals("cat1", request.getGroupParam().getGroupField());
    Assert.assertEquals(3, request.getGroupParam().getGroupInnerLimit());
    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("10.3", result.getHits().get(0).getGroupHits().get(0).getFields().get("rank"));
    Assert.assertEquals("4.5", result.getHits().get(0).getGroupHits().get(1).getFields().get("rank"));
    Assert.assertEquals(1, result.getHits().get(1).getGroupHitsSize());
    Assert.assertEquals("10.0", result.getHits().get(1).getGroupHits().get(0).getFields().get("rank"));
    Assert.assertEquals(2, result.getHits().get(2).getGroupHitsSize());
    Assert.assertEquals("4.0", result.getHits().get(2).getGroupHits().get(0).getFields().get("rank"));
    Assert.assertEquals("1.2", result.getHits().get(2).getGroupHits().get(1).getFields().get("rank"));
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 72 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenSnippet method passageLimitTest.

@Test
public void passageLimitTest() throws IOException {
    String bql = "SELECT * FROM linden by query is 'title:小米6' or query is 'body:小米6' snippet title, body";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals("新发布的<b>小米</b><b>6</b>如何? 想买<b>小米</b><b>6</b>吗? 4月28日开抢<b>小米</b><b>6</b>. 哪里抢<b>小米</b><b>6</b>? 告诉你也没用, 反正你都买不到<b>小米</b><b>6</b>", result.getHits().get(0).getSnippets().get("title").getSnippet());
    Assert.assertEquals("<b>小米</b><b>6</b>号称7年巅峰之作,新一代性能怪兽。中国首发骁龙835处理器+标配6GB内存,安兔兔综合跑分184292,<b>小米</b><b>6</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 73 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenSnippet method flexibleQueryTest.

@Test
public void flexibleQueryTest() throws IOException {
    String bql = "SELECT * FROM LINDEN BY flexible_query is \"test best\" in (title, body) USING MODEL simplest BEGIN\n" + "   float sum = 0f;\n" + "    for (int i = 0; i < getFieldLength(); ++i) {\n" + "        for (int j = 0; j < getTermLength(); ++j) {\n" + "            if (isMatched(i, j)) {\n" + "                sum += getScore(i, j);\n" + "            }\n" + "        } \n" + "    } \n" + "    return sum;\n" + "END\n" + "snippet title, body Limit 0, 10\n";
    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 74 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenSortingMergePolicy method testEarlyTermination.

@Test
public void testEarlyTermination() throws IOException {
    String bql = "select * from linden by query is \"title:(lucene 2)\" in top 3 limit 10 source";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(8, result.getHits().size());
    Assert.assertEquals("7", result.getHits().get(0).getId());
    bql = "select * from linden by query is \"title:(lucene 13)\" in top 3 limit 10 source";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(8, result.getHits().size());
    Assert.assertEquals("13", result.getHits().get(0).getId());
    bql = "select * from linden by query is \"title:(lucene 13)\" in top 2 order by rank limit 10 source";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(7, result.getHits().size());
    Assert.assertEquals("7", result.getHits().get(0).getId());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 75 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenUpdate method updateDocValueTest.

@Test
public void updateDocValueTest() throws Exception {
    // update document id3
    // using default update type: doc_value
    handleRequest("{\"type\": \"update\", \"content\": {\"id\":3, \"field1\":\"ccc_c\", \"cat2\":33.5}}");
    lindenCore.refresh();
    String bql = "select * from linden by query is \'title:\"lucene 3\"\' source";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(1, result.getHitsSize());
    Assert.assertEquals("{\"field1\":\"ccc_c\",\"cat2\":33.5,\"cat1\":3,\"rank\":4.5,\"id\":\"3\",\"title\":\"lucene 3\",\"tagstr\":\"ok\"}", result.getHits().get(0).getSource());
    // this case won't go docvalue path, since tagstr is not only docvalue but also indexed
    handleRequest("{\"type\": \"update\", \"content\": {\"id\":3, \"tagstr\":\"not ok\"}}");
    lindenCore.refresh();
    bql = "select * from linden where tagstr = 'not ok' source";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(1, result.getHitsSize());
    Assert.assertEquals("{\"field1\":\"ccc_c\",\"cat2\":33.5,\"cat1\":3,\"rank\":4.5,\"id\":\"3\",\"title\":\"lucene 3\",\"tagstr\":\"not 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)

Aggregations

LindenResult (com.xiaomi.linden.thrift.common.LindenResult)79 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)69 Test (org.junit.Test)69 IOException (java.io.IOException)7 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)5 JSONObject (com.alibaba.fastjson.JSONObject)4 Stopwatch (com.google.common.base.Stopwatch)4 MultiLindenCoreImpl (com.xiaomi.linden.core.search.MultiLindenCoreImpl)3 LindenFlexibleQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder)3 LindenDeleteRequest (com.xiaomi.linden.thrift.common.LindenDeleteRequest)3 LindenHit (com.xiaomi.linden.thrift.common.LindenHit)3 LindenRequest (com.xiaomi.linden.thrift.common.LindenRequest)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 FlexibleQuery (com.xiaomi.linden.lucene.query.flexiblequery.FlexibleQuery)2 Response (com.xiaomi.linden.thrift.common.Response)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 DisjunctionMaxQuery (org.apache.lucene.search.DisjunctionMaxQuery)2 FilteredQuery (org.apache.lucene.search.FilteredQuery)2 Query (org.apache.lucene.search.Query)2