美文网首页
逸足迹-新发现-manticoresearch window的安

逸足迹-新发现-manticoresearch window的安

作者: lovefy | 来源:发表于2023-09-14 14:27 被阅读0次

    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

    相关文章

      网友评论

          本文标题:逸足迹-新发现-manticoresearch window的安

          本文链接:https://www.haomeiwen.com/subject/bmmmvdtx.html