1.什么時manticore search
Manticore Search 是一個使用 C++ 開發的高性能搜索引擎,創建于 2017 年,其前身是 Sphinx Search 。Manticore Search 充分利用了 Sphinx,顯著改進了它的功能,修復了數百個錯誤,幾乎完全重寫了代碼并保持開源。這一切使 Manticore Search 成為一個現代,快速,輕量級和功能齊全的數據庫,具有出色的全文搜索功能。Manticore Search目前在GitHub收獲5.7k star,擁有大批忠實用戶。同時開源者在GitHub介紹中明確說明了該項目是是Elasticsearch的良好替代品,在不久的將來就會取代ELK中的E。
image (3).png
github的地址
https://github.com/manticoresoftware/manticoresearch
2.優勢
在特殊場景的情況下,他對比現有的解決方案的對比
image.png
3.如何安裝
github上給了多種安裝方式,由于我這里使用的時window,所以使用的是window安裝
image (1).png
window安裝官方文檔
https://manual.manticoresearch.com/Installation/Windows
下載安裝
image (10).png
安裝完后,打開cmd(一定要以管理員的方式運行cmd,不然權限不足)
輸入
D:\Manticore\bin\searchd.exe --install --config D:\Manticore\etc\manticoresearch\manticore.conf --servicename Manticore
這里是我安裝的路徑,實際以自己的路徑為主
image (4).png
啟動服務
image (5).png
在mysql bin目錄下指定 manticore地址
mysql -P9306 -h127.0.0.1
image (6).png
4.java編寫用例
首先我們使用的是maven,我們要引入最新的manticoresearch的client的包
<dependency>
<groupId>com.manticoresearch</groupId>
<artifactId>manticoresearch</artifactId>
<version>3.3.0</version>
<scope>compile</scope>
</dependency>
引入maven依賴后我們開始寫用例,manticoresearch官方文檔https://manual.manticoresearch.com/Introduction
例如創建表
ApiClient defaultClient = Configuration.getDefaultApiClient();
//你的manticoresearch服務器地址
defaultClient.setBasePath("http://127.0.0.1:9308");
UtilsApi utilsApi = new UtilsApi(defaultClient);
try {
List<Object> list = utilsApi.sql("CREATE TABLE forum(title text, content text, author_id int, forum_id int, post_date timestamp)", true);
// Create SearchRequest
System.out.println(JSONObject.toJSONString(list));
} catch (ApiException e) {
System.err.println("Exception when calling SearchApi#search");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
其中地址可以在manticoresearch的安裝目錄的\etc\manticoresearch下的manticore.conf 里面查看
image (7).png
創建表后,我們還可以根據sql的show tables查詢我們創建的表
ApiClient defaultClient = Configuration.getDefaultApiClient();
//你的manticoresearch服務器地址
defaultClient.setBasePath("http://127.0.0.1:9308");
UtilsApi utilsApi = new UtilsApi(defaultClient);
try {
List<Object> list = utilsApi.sql("SHOW TABLES", true);
// Create SearchRequest
System.out.println(JSONObject.toJSONString(list));
} catch (ApiException e) {
System.err.println("Exception when calling SearchApi#search");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
結果如下
image (8).png
插入數據,我們可以根據sql插入,也可以根據它給的api插入
ApiClient defaultClient = Configuration.getDefaultApiClient();
//你的manticoresearch服務器地址
defaultClient.setBasePath("http://127.0.0.1:9308");
IndexApi indexApi = new IndexApi(defaultClient);
try {
InsertDocumentRequest newdoc = new InsertDocumentRequest();
HashMap<String,Object> doc = new HashMap<String,Object>(){{
put("title","第一個");
}};
newdoc.index("forum").id(1L).setDoc(doc);
SuccessResponse sqlresult = indexApi.insert(newdoc);
System.out.println(JSONObject.toJSONString(sqlresult));
} catch (ApiException e) {
System.err.println("Exception when calling SearchApi#search");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
插入完后可以使用提供的api進行查詢
ApiClient defaultClient = Configuration.getDefaultApiClient();
//你的manticoresearch服務器地址
defaultClient.setBasePath("http://127.0.0.1:9308");
SearchApi searchApi = new SearchApi(defaultClient);
try {
SearchResponse searchResponse = searchApi.search(new SearchRequest().index("forum"));
System.out.println(JSONObject.toJSONString(searchResponse));
} catch (ApiException e) {
System.err.println("Exception when calling SearchApi#search");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
結果如下
image (9).png