当前位置:   article > 正文

ManticoreSearch_manticore search

manticore search

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

目录

一、索引结构

二、windows安装manticoresearch

2.1 下载manticoresearch:

2.2 运行安装程序

2.3 配置manticoresearch

2.4 启动manticoresearch

2.5 启动验证

三、springcloud集成manticoresearch

3.1 添加maven依赖

四、基本操作

4.1 创建索引

4.2 添加数据 

4.3 检索数据 

4.4 统计数据


一、索引结构

manticoresearch使用倒排索引结构来支持高效的全文搜索

倒排索引是一种将文档中的每个单词映射到包含该单词的文档的数据结构

二、windows安装manticoresearch

2.1 下载manticoresearch:

Manticore Search

https://github.com/manticoresoftware/manticoresearch

2.2 运行安装程序

2.3 配置manticoresearch

编辑manticore.conf,修改监听端口、索引路径等

2.4 启动manticoresearch

执行bin目录下的searchd.exe文件

2.5 启动验证

访问http://localhost:9308/

三、springcloud集成manticoresearch

3.1 添加maven依赖

  1. <dependency>
  2. <groupId>io.manticoresearch</groupId>
  3. <artifactId>manticoresearch-java</artifactId>
  4. <version>1.0.0</version>
  5. </dependency>

3.2 创建manticoresearch客户端bean 

  1. @Configuration
  2. public class ManticoreSearchConfig {
  3. @Bean
  4. public ManticoreSearchClient manticoreSearchClient() {
  5. // 创建并返回 ManticoreSearch 客户端实例
  6. return new ManticoreSearchClient("localhost", 9308);
  7. }
  8. }

3.3 使用manticoresearch客户端 

  1. @Service
  2. public class SearchService {
  3. @Autowired
  4. private ManticoreSearchClient manticoreSearchClient;
  5. @Autowired
  6. public SearchService(ManticoreSearchClient manticoreSearchClient) {
  7. this.manticoreSearchClient = manticoreSearchClient;
  8. }
  9. public void searchDocuments(String indexName, String query) {
  10. SearchRequest searchRequest = new SearchRequest(indexName);
  11. // 设置搜索请求参数
  12. // ...
  13. // 发送搜索请求
  14. SearchResponse searchResponse = manticoreSearchClient.search(searchRequest);
  15. // 处理搜索结果
  16. // ...
  17. }
  18. }

四、基本操作

4.1 创建索引

  1. // 设置索引配置
  2. IndexSettingsRequest settingsRequest = new IndexSettingsRequest("my_index");
  3. settingsRequest.setSettings(new IndexSettings().setRtMemLimit("256M"));
  4. // 发送设置请求
  5. IndexSettingsResponse settingsResponse = client.indexSettings(settingsRequest);

4.2 添加数据 

  1. // 创建批量请求
  2. BulkRequest bulkRequest = new BulkRequest("my_index");
  3. // 添加数据项
  4. bulkRequest.add(new BulkDataItem().setId("1").setFields(Collections.singletonMap("title", "Document 1")));
  5. bulkRequest.add(new BulkDataItem().setId("2").setFields(Collections.singletonMap("title", "Document 2")));
  6. // 执行批量请求
  7. BulkResponse bulkResponse = client.bulk(bulkRequest);

4.3 检索数据 

  1. // 创建搜索请求
  2. SearchRequest searchRequest = new SearchRequest("my_index");
  3. // 创建查询条件
  4. BoolQueryBuilder boolQuery = new BoolQueryBuilder();
  5. boolQuery.must(new MatchQueryBuilder("title", "Document"));
  6. searchRequest.setQuery(boolQuery);
  7. // 设置排序
  8. SortQueryBuilder sortQuery = new SortQueryBuilder();
  9. sortQuery.addSort(new SortParam("title", SortQuery.SortOrder.ASC));
  10. searchRequest.setSort(sortQuery);
  11. // 发送搜索请求
  12. SearchResponse searchResponse = client.search(searchRequest);

4.4 统计数据

  1. // 创建搜索请求
  2. SearchRequest searchRequest = new SearchRequest("my_index");
  3. // 创建查询条件
  4. QueryBuilder queryBuilder = new TermQueryBuilder("title", "Document");
  5. QueryParam queryParam = new QueryParam(queryBuilder);
  6. searchRequest.setQuery(queryParam);
  7. // 发送搜索请求
  8. SearchResponse searchResponse = client.search(searchRequest);
  9. long totalCount = searchResponse.getTotal();

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号