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());
}
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());
}
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());
}
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);
}
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());
}
Aggregations