Search in sources :

Example 16 with LindenResult

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

the class TestLindenFieldCache method doubleListTest.

@Test
public void doubleListTest() throws IOException {
    String bql = "select * from linden by query is \"title:lucene\" " + "using score model test " + "begin " + "  int base = doc();\n" + "  for (double d : ids_double()) {\n" + "    if (d != (double)(base++)) {\n" + "      return -1.0;\n" + "    }\n" + "  }\n" + "  return 1.0;\n" + "end";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(10, result.getTotalHits());
    for (int i = 0; i < 10; ++i) {
        Assert.assertTrue(result.getHits().get(i).score > 0.0);
    }
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 17 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult 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 18 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult 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 19 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult 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 20 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult 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)

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