package com.congge.controller;
import com.congge.config.MyIKAnalyzer;
import com.congge.entity.Content;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.*;
import org.apache.lucene.queryparser.classic.MultiFieldQueryParser;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.highlight.*;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Paths;
import java.util.*;
@RestController
public class IndexController {
//localhost:8083/createIndex
@GetMapping("/createIndex")
public String createIndex() throws IOException {
List<Content> list1 = new ArrayList<>();
list1.add(new Content("1", "Java面向对象", "10", "Java面向对象从入门到精通,简单上手"));
list1.add(new Content("2", "Java面向对象java", "10", "Java面向对象从入门到精通,简单上手"));
list1.add(new Content("3", "Java面向编程", "15", "Java面向对象编程书籍"));
list1.add(new Content("4", "JavaScript入门", "18", "JavaScript入门编程书籍"));
list1.add(new Content("5", "深入理解Java编程", "13", "十三四天掌握Java基础"));
list1.add(new Content("6", "从入门到放弃_Java", "20", "一门从入门到放弃的书籍"));
list1.add(new Content("7", "Head First Java", "30", "《Head First Java》是一本完整地面向对象(object-oriented,OO)程序设计和Java的学习指导用书"));
list1.add(new Content("7", "Java 核心技术:卷1 基础知识", "22", "全书共14章,包括Java基本的程序结构、对象与类、继承、接口与内部类、图形程序设计、事件处理、Swing用户界面组件"));
list1.add(new Content("9", "Java 编程思想", "12", "本书赢得了全球程序员的广泛赞誉,即使是最晦涩的概念,在Bruce Eckel的文字亲和力和小而直接的编程示例面前也会化解于无形"));
list1.add(new Content("10", "Java开发实战经典", "51", "本书是一本综合讲解Java核心技术的书籍,在书中使用大量的代码及案例进行知识点的分析与运用"));
list1.add(new Content("11", "Effective Java", "10","本书介绍了在Java编程中57条极具实用价值的经验规则,这些经验规则涵盖了大多数开发人员每天所面临的问题的解决方案"));
list1.add(new Content("12", "分布式 Java 应用:基础与实践", "15", "本书介绍了编写分布式Java应用涉及的众多知识点,分为了基于Java实现网络通信、RPC;基于SOA实现大型分布式Java应用"));
list1.add(new Content("13", "http权威指南", "11", "超文本传输协议(Hypertext Transfer Protocol,HTTP)是在万维网上进行通信时所使用的协议方案"));
list1.add(new Content("14", "Spring", "15", "这是啥,还需要学习吗?Java程序员必备书籍"));
list1.add(new Content("15", "深入理解 Java 虚拟机", "18", "作为一位Java程序员,你是否也曾经想深入理解Java虚拟机,但是却被它的复杂和深奥拒之门外"));
list1.add(new Content("16", "springboot实战", "11", "完成对于springboot的理解,是每个Java程序员必备的姿势"));
list1.add(new Content("17", "springmvc学习", "72", "springmvc学习指南"));
list1.add(new Content("18", "vue入门到放弃", "20", "vue入门到放弃书籍信息"));
list1.add(new Content("19", "vue入门到精通", "20", "vue入门到精通相关书籍信息"));
list1.add(new Content("20", "vue之旅", "20", "由浅入深地全面介绍vue技术,包含大量案例与代码"));
list1.add(new Content("21", "vue实战", "20", "以实战为导向,系统讲解如何使用 "));
list1.add(new Content("22", "vue入门与实践", "20", "现已得到苹果、微软、谷歌等主流厂商全面支持"));
list1.add(new Content("23", "Vue.js应用测试", "20", "Vue.js创始人尤雨溪鼎力推荐!Vue官方测试工具作者亲笔撰写,Vue.js应用测试完全学习指南"));
list1.add(new Content("24", "PHP和MySQL Web开发", "20", "本书是利用PHP和MySQL构建数据库驱动的Web应用程序的权威指南"));
list1.add(new Content("25", "Web高效编程与优化实践", "20", "从思想提升和内容修炼两个维度,围绕前端工程师必备的前端技术和编程基础"));
list1.add(new Content("26", "Vue.js 2.x实践指南", "20", "本书旨在让初学者能够快速上手vue技术栈,并能够利用所学知识独立动手进行项目开发"));
list1.add(new Content("27", "初始vue", "20", "解开vue的面纱"));
list1.add(new Content("28", "什么是vue", "20", "一步一步的了解vue相关信息"));
list1.add(new Content("29", "深入浅出vue", "20", "深入浅出vue,慢慢掌握"));
list1.add(new Content("30", "三天vue实战", "20", "三天掌握vue开发"));
list1.add(new Content("31", "不知火舞", "20", "不知名的vue"));
list1.add(new Content("32", "娜可露露", "20", "一招秒人"));
list1.add(new Content("33", "宫本武藏", "20", "我就是一个超级兵"));
list1.add(new Content("34", "vue宫本vue", "20", "我就是一个超级兵"));
// 创建文档的集合
Collection<Document> docs = new ArrayList<>();
for (int i = 0; i < list1.size(); i++) {
//contentMapper.insertSelective(list1.get(i));
// 创建文档对象
Document document = new Document();
//StringField会创建索引,但是不会被分词,TextField,即创建索引又会被分词。
document.add(new StringField("id", (i + 1) + "", Field.Store.YES));
document.add(new StringField("title", list1.get(i).getTitle(), Field.Store.YES));
document.add(new StringField("price", list1.get(i).getPrice(), Field.Store.YES));
document.add(new TextField("descs", list1.get(i).getDescs(), Field.Store.YES));
docs.add(document);
}
// 索引目录类,指定索引在硬盘中的位置,我的设置为D盘的indexDir文件夹
Directory directory = FSDirectory.open(FileSystems.getDefault().getPath("D:\\Lucene\\indexDir"));
// 引入IK分词器
Analyzer analyzer = new MyIKAnalyzer();
// 索引写出工具的配置对象,这个地方就是最上面报错的问题解决方案
IndexWriterConfig conf = new IndexWriterConfig(analyzer);
// 设置打开方式:OpenMode.APPEND 会在索引库的基础上追加新索引。OpenMode.CREATE会先清空原来数据,再提交新的索引
conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
// 创建索引的写出工具类。参数:索引的目录和配置信息
IndexWriter indexWriter = new IndexWriter(directory, conf);
// 把文档集合交给IndexWriter
indexWriter.addDocuments(docs);
// 提交
indexWriter.commit();
// 关闭
indexWriter.close();
return "success";
}
//localhost:8083/searchText?text=一
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
springcloud整合openfeign完整代码 (216个子文件)
application.yaml.bk 697B
application.yaml.bk 697B
IndexController.class 17KB
IndexContentController.class 12KB
QueryContentController.class 9KB
ContentService.class 6KB
SentinelController.class 5KB
BookController.class 5KB
OrderController.class 4KB
CheckAuthGatewayFilterFactory.class 4KB
DepartTest.class 3KB
MySearcher.class 3KB
MyIndexer.class 3KB
StockController.class 3KB
OrderController.class 3KB
Content.class 3KB
Book.class 2KB
IndexUtils.class 2KB
MyIKTokenizer.class 2KB
Depart.class 2KB
BookDao.class 2KB
OrderController.class 2KB
MyBlockException.class 2KB
User.class 2KB
FilePathTest.class 2KB
LogFilter.class 2KB
CheckAuthRoutePredicateFactory.class 2KB
OrderController.class 2KB
CheckAuthRoutePredicateFactory$Config.class 2KB
KafkaTopicProperties.class 2KB
CustomRule.class 2KB
CheckAuthGatewayFilterFactory$Config.class 2KB
OrderController.class 2KB
OrderController.class 2KB
MakeIndexer.class 1KB
CheckAuthRoutePredicateFactory$1.class 1KB
ListTest.class 1KB
KafkaTopicConfiguration.class 1KB
BookService.class 1KB
FeignInterceptor.class 1KB
MyIKAnalyzer.class 1KB
ProductController.class 1KB
SentinelApp.class 970B
FlowController.class 852B
StockController.class 845B
ConfigController.class 832B
SerchIndexer.class 815B
ContentDao.class 814B
JavaTest.class 780B
NacosConfigApp.class 761B
FallBackService.class 757B
FeignSentinelApp.class 757B
FeignOrderApp.class 748B
StockApp1.class 746B
StockApp.class 743B
OrderApp.class 743B
StockFeignService.class 708B
RestConfig.class 698B
RestConfig.class 698B
RestConfig.class 698B
BalancerOrderApp.class 694B
SentinelOrderApp.class 694B
RibbonOrderApp.class 688B
GatewayApp01.class 682B
LucenceApp.class 676B
App.class 655B
RibbonRandomRuleConfig.class 625B
FeignConfig.class 607B
FeignConfig.class 607B
StockFeignService.class 606B
UserService.class 571B
InitIndexer.class 500B
openfeign-order.iml 80B
gateway-01.iml 80B
mycloud.iml 80B
sentinel-test.iml 80B
ribbon-order.iml 80B
lucence-test-1.0-SNAPSHOT.jar 37KB
nacos-order-1.0-SNAPSHOT.jar 5KB
IndexController.java 20KB
IndexContentController.java 13KB
QueryContentController.java 9KB
ContentService.java 6KB
SentinelController.java 5KB
ChineseSearch.java 4KB
MyIndexer.java 4KB
ChineseIndexer.java 3KB
OrderController.java 3KB
Indexer.java 3KB
BookController.java 3KB
MySearcher.java 2KB
DepartTest.java 2KB
MyIKTokenizer.java 2KB
CustomRule.java 2KB
FilePathTest.java 2KB
StockController.java 2KB
IndexUtils.java 2KB
OrderController.java 2KB
MyBlockException.java 2KB
CheckAuthGatewayFilterFactory.java 1KB
共 216 条
- 1
- 2
- 3
资源评论
小码农叔叔
- 粉丝: 6w+
- 资源: 85
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功