Search in sources :

Example 71 with LindenSearchRequest

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

the class TestLindenCore method omitFreqsTest.

@Test
public void omitFreqsTest() throws IOException {
    String bql = "select * from linden by query is 'field2:aaa' explain";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals("tf(freq=1.0), with freq of:", result.getHits().get(0).getExplanation().getDetails().get(0).getDetails().get(0).getDescription());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 72 with LindenSearchRequest

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

the class TestLindenCore method testMultiIndexField.

@Test
public void testMultiIndexField() throws InterruptedException, IOException {
    String bql = "select * from linden where tagstr='MI4' source";
    LindenSearchRequest lindenRequest = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(lindenRequest);
    Assert.assertEquals(1, result.getTotalHits());
    Assert.assertEquals("6", result.getHits().get(0).getId());
    Assert.assertEquals(data6, result.getHits().get(0).getSource());
    bql = "select * from linden by tagstr='MI Note' source";
    lindenRequest = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(lindenRequest);
    Assert.assertEquals(1, result.getTotalHits());
    Assert.assertEquals("6", result.getHits().get(0).getId());
    bql = "select * from linden by tagstr='MI4C' source";
    lindenRequest = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(lindenRequest);
    Assert.assertEquals(1, result.getTotalHits());
    Assert.assertEquals("7", result.getHits().get(0).getId());
    Assert.assertEquals(data7, result.getHits().get(0).getSource());
    bql = "select * from linden where tagstr='MI Note Pro'";
    lindenRequest = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(lindenRequest);
    Assert.assertEquals(1, result.getTotalHits());
    Assert.assertEquals("7", result.getHits().get(0).getId());
    bql = "select * from linden source " + "using score model test " + "begin " + "  float sum = 0;\n" + "  for (String tag : tagstr()) {\n" + "    if (tag.equals(\"MI Note Pro\")) {\n" + "      sum += 10.0; \n" + "      }\n" + "  }\n" + "  return sum;\n" + "end";
    lindenRequest = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(lindenRequest);
    Assert.assertEquals(6, result.getTotalHits());
    Assert.assertEquals("7", result.getHits().get(0).getId());
    Assert.assertEquals(10.0, result.getHits().get(0).getScore(), 0.001);
    Assert.assertEquals("{\"id\":\"7\",\"tagstr\":[\"MI4C\",\"MI Note Pro\"]}", 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 73 with LindenSearchRequest

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

the class TestLindenCore method bqlFlexibleQueryTest.

@Test
public void bqlFlexibleQueryTest() throws IOException {
    String bql = "select * from linden by flexible_query is \"lucene 2\" in (title)\n" + "using model test(Float m = 10)\n" + "begin\n" + "    float sum = 0f;\n" + "    for (int i = 0; i < getFieldLength(); ++i) {\n" + "        for (int j = 0; j < getTermLength(); ++j) {\n" + "            sum += 10 * getScore(i, j);\n" + "            addTermExpl(i, j, 10, getExpl(\"[%.2f]\", sum));\n" + "        }\n" + "        addFieldExpl(i, 20, getExpl(\"[%.2f]\", sum * m));\n" + "    }\n" + "    return sum * m;\n" + "end explain";
    LindenSearchRequest lindenRequest = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(lindenRequest);
    Assert.assertEquals(4, result.getTotalHits());
    Assert.assertEquals("[158.20]        [FIELD:title MATCHED:2]", result.getHits().get(0).getExplanation().getDetails().get(0).getDescription());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 74 with LindenSearchRequest

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

the class TestLindenCore method lindenBQLScoreModelParamTest.

@Test
public void lindenBQLScoreModelParamTest() throws IOException {
    String bql = "select * from linden by query is \"title:lucene\" " + "using score model test(Long param1 = $long1, Map<String, Double> dict = {'中文': 1.0, 'b': 2.0})" + "begin\n" + "double sum = 0;\n" + "sum += dict.get(\"中文\");\n" + "for (String entry : dict.keySet()) {\n" + "sum += dict.get(entry);\n" + "}\n" + "return sum;\n" + "end explain";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(4, result.getTotalHits());
    Assert.assertEquals(4.0, result.getHits().get(0).getScore(), 0.1f);
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 75 with LindenSearchRequest

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

the class TestLindenCore method termQueryTest.

@Test
public void termQueryTest() throws Exception {
    String bql = "select * from linden where title='lucene'";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(4, result.getTotalHits());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) 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