use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestMultiLindenCore method testTimeDivision.
@Test
public void testTimeDivision() throws Exception {
String path = FilenameUtils.concat(INDEX_DIR, "time/");
lindenConfig.setIndexDirectory(path).setMultiIndexDivisionType(LindenConfig.MultiIndexDivisionType.TIME_HOUR).setLindenCoreMode(LindenConfig.LindenCoreMode.MULTI).setMultiIndexMaxLiveIndexNum(10);
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(8, 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);
content.put("title", "test " + (400 + i));
json.put("content", content);
handleRequest(json.toJSONString());
}
lindenCore.commit();
lindenCore.refresh();
result = lindenCore.search(request);
Assert.assertEquals(500, result.getTotalHits());
Assert.assertEquals(10, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(500, lindenCore.getServiceInfo().getDocsNum());
bql = "delete from linden where query is 'title:400 title:401'";
LindenDeleteRequest deleteRequest = bqlCompiler.compile(bql).getDeleteRequest();
lindenCore.delete(deleteRequest);
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(498, lindenCore.getServiceInfo().getDocsNum());
lindenCore.close();
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestMultiLindenCore method testIndexNameDivision.
@Test
public void testIndexNameDivision() throws Exception {
String path = FilenameUtils.concat(INDEX_DIR, "name/");
lindenConfig.setIndexDirectory(path).setLindenCoreMode(LindenConfig.LindenCoreMode.MULTI).setMultiIndexDivisionType(LindenConfig.MultiIndexDivisionType.INDEX_NAME);
lindenCore = new MultiLindenCoreImpl(lindenConfig);
for (int i = 0; i < 400; ++i) {
JSONObject json = new JSONObject();
json.put("type", "index");
json.put("index", "multi_" + i / 50);
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(8, 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());
bql = "select * from multi_0 source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(50, result.getTotalHits());
bql = "select * from non-existed source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertFalse(result.isSuccess());
bql = "select * from multi_1, multi_2 source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(100, result.getTotalHits());
handleRequest("{\"type\":\"delete_index\", \"index\":\"multi_0\"}");
bql = "select * from multi_0 source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertFalse(result.isSuccess());
handleRequest("{\"type\":\"delete_index\", \"index\":\"multi_2\"}");
Assert.assertEquals(6, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(300, lindenCore.getServiceInfo().getDocsNum());
// delete doc 50, 200, 300, 390, 397, doc 0 and doc 100 doesn't exist since multi_0 and multi_1 index are deleted
bql = "delete from linden where query is 'title:0 title:50 title:100 title:200 title:300 title:390 title:397'";
LindenDeleteRequest deleteRequest = bqlCompiler.compile(bql).getDeleteRequest();
lindenCore.delete(deleteRequest);
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(295, lindenCore.getServiceInfo().getDocsNum());
lindenCore.close();
}
Aggregations