- 浏览: 175294 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (321)
- eclipse (4)
- idea (2)
- Html (8)
- Css (14)
- Javascript (8)
- Jquery (6)
- Ajax Json (4)
- Bootstrap (0)
- EasyUI (0)
- Layui (0)
- 数据结构 (0)
- Java (46)
- DesPattern (24)
- Algorithm (2)
- Jdbc (8)
- Jsp servlet (13)
- Struts2 (17)
- Hibernate (11)
- Spring (5)
- S2SH (1)
- SpringMVC (4)
- SpringBoot (11)
- WebService CXF (4)
- Poi (2)
- JFreeChart (0)
- Shiro (6)
- Lucene (5)
- ElasticSearch (0)
- JMS ActiveMQ (3)
- HttpClient (5)
- Activiti (0)
- SpringCloud (11)
- Dubbo (6)
- Docker (0)
- MySQL (27)
- Oracle (18)
- Redis (5)
- Mybatis (11)
- SSM (1)
- CentOS (10)
- Ant (2)
- Maven (4)
- Log4j (7)
- XML (5)
最新评论
1. 中文分词
2. 高亮显示
2. 高亮显示
New maven project -> Create a simple project -> Group Id: com.andrew.lucene Artifact Id: Lucene05 Version: 0.0.1-SNAPSHOT Packaging: jar
pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.andrew.lucene</groupId> <artifactId>Lucene05</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> <version>5.3.1</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-queryparser</artifactId> <version>5.3.1</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-analyzers-common</artifactId> <version>5.3.1</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-analyzers-smartcn</artifactId> <version>5.3.1</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-highlighter</artifactId> <version>5.3.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> </dependencies> </project>
Indexer.java代码 package com.andrew.lucene; import java.nio.file.Paths; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.IntField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; public class Indexer { private Integer ids[] = { 1, 2, 3 }; private String citys[] = { "青岛", "南京", "上海" }; private String descs[] = { "青岛是一个美丽的城市。", "南京是一个有文化的城市。南京是一个文化的城市南京,简称宁,是江苏省会,地处中国东部地区,长江下游,濒江近海。全市下辖11个区,总面积6597平方公里,2013年建成区面积752.83平方公里,常住人口818.78万,其中城镇人口659.1万人。[1-4] “江南佳丽地,金陵帝王州”,南京拥有着6000多年文明史、近2600年建城史和近500年的建都史,是中国四大古都之一,有“六朝古都”、“十朝都会”之称,是中华文明的重要发祥地,历史上曾数次庇佑华夏之正朔,长期是中国南方的政治、经济、文化中心,拥有厚重的文化底蕴和丰富的历史遗存。[5-7] 南京是国家重要的科教中心,自古以来就是一座崇文重教的城市,有“天下文枢”、“东南第一学”的美誉。截至2013年,南京有高等院校75所,其中211高校8所,仅次于北京上海;国家重点实验室25所、国家重点学科169个、两院院士83人,均居中国第三。[8-10] 。", "上海是一个繁华的城市。" }; private Directory dir; // 获取IndexWriter实例 private IndexWriter getWriter() throws Exception { // Analyzer analyzer=new StandardAnalyzer(); // 标准分词器 SmartChineseAnalyzer analyzer = new SmartChineseAnalyzer(); IndexWriterConfig iwc = new IndexWriterConfig(analyzer); IndexWriter writer = new IndexWriter(dir, iwc); return writer; } // 生成索引 private void index(String indexDir) throws Exception { dir = FSDirectory.open(Paths.get(indexDir)); IndexWriter writer = getWriter(); for (int i = 0; i < ids.length; i++) { Document doc = new Document(); doc.add(new IntField("id", ids[i], Field.Store.YES)); doc.add(new StringField("city", citys[i], Field.Store.YES)); doc.add(new TextField("desc", descs[i], Field.Store.YES)); writer.addDocument(doc); // 添加文档 } writer.close(); } public static void main(String[] args) throws Exception { new Indexer().index("E:\\lucene6"); } }
Searcher.java代码 package com.andrew.lucene; import java.io.StringReader; import java.nio.file.Paths; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; 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.Fragmenter; import org.apache.lucene.search.highlight.Highlighter; import org.apache.lucene.search.highlight.QueryScorer; import org.apache.lucene.search.highlight.SimpleHTMLFormatter; import org.apache.lucene.search.highlight.SimpleSpanFragmenter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; public class Searcher { public static void search(String indexDir, String q) throws Exception { Directory dir = FSDirectory.open(Paths.get(indexDir)); IndexReader reader = DirectoryReader.open(dir); IndexSearcher is = new IndexSearcher(reader); // Analyzer analyzer=new StandardAnalyzer(); // 标准分词器 SmartChineseAnalyzer analyzer = new SmartChineseAnalyzer(); QueryParser parser = new QueryParser("desc", analyzer); Query query = parser.parse(q); long start = System.currentTimeMillis(); TopDocs hits = is.search(query, 10); long end = System.currentTimeMillis(); System.out.println("匹配 " + q + " ,总共花费" + (end - start) + "毫秒" + "查询到" + hits.totalHits + "个记录"); QueryScorer scorer = new QueryScorer(query); Fragmenter fragmenter = new SimpleSpanFragmenter(scorer); SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter("<b><font color='red'>", "</font></b>"); Highlighter highlighter = new Highlighter(simpleHTMLFormatter, scorer); highlighter.setTextFragmenter(fragmenter); for (ScoreDoc scoreDoc : hits.scoreDocs) { Document doc = is.doc(scoreDoc.doc); System.out.println(doc.get("city")); System.out.println(doc.get("desc")); String desc = doc.get("desc"); if (desc != null) { TokenStream tokenStream = analyzer.tokenStream("desc", new StringReader(desc)); System.out.println(highlighter.getBestFragment(tokenStream, desc)); } } reader.close(); } public static void main(String[] args) { String indexDir = "E:\\lucene6"; String q = "南京文明"; try { search(indexDir, q); } catch (Exception e) { e.printStackTrace(); } } } 运行结果: 匹配 南京文明 ,总共花费53毫秒查询到1个记录 南京 南京是一个有文化的城市。南京是一个文化的城市南京,简称宁,是江苏省会,地处中国东部地区,长江下游,濒江近海。全市下辖11个区,总面积6597平方公里,2013年建成区面积752.83平方公里,常住人口818.78万,其中城镇人口659.1万人。[1-4] “江南佳丽地,金陵帝王州”,南京拥有着6000多年文明史、近2600年建城史和近500年的建都史,是中国四大古都之一,有“六朝古都”、“十朝都会”之称,是中华文明的重要发祥地,历史上曾数次庇佑华夏之正朔,长期是中国南方的政治、经济、文化中心,拥有厚重的文化底蕴和丰富的历史遗存。[5-7] 南京是国家重要的科教中心,自古以来就是一座崇文重教的城市,有“天下文枢”、“东南第一学”的美誉。截至2013年,南京有高等院校75所,其中211高校8所,仅次于北京上海;国家重点实验室25所、国家重点学科169个、两院院士83人,均居中国第三。[8-10] 。 人口818.78万,其中城镇人口659.1万人。[1-4] “江南佳丽地,金陵帝王州”,<b><font color='red'>南京</font></b>拥有着6000多年<b><font color='red'>文明</font></b>史、近2600年建城史和近500年的建都史,是中国四大古都之一,有“六朝古都”、“十朝都
相关推荐
lucene.NET 中文分词 高亮 lucene.NET 中文分词 高亮 lucene.NET 中文分词 高亮 lucene.NET 中文分词 高亮
利用IKAnalyzer结合LUCENE.4.9进行中文分词的高亮显示。
使用visual studio 开发的lucene.net和盘古分词实现全文检索。并按照lucene的得分算法进行多条件检索并按照得分算法计算匹配度排序。 可以输入一句话进行检索。 lucene.net的版本为2.9.2 盘古分词的版本为2.3.1 并...
lucene.net+盘古分词实现全文搜索,数据匹配,关键词高亮显示等等
基于爬虫和lucene构建的重大新闻网,爬虫爬到数据在后台用lucene做分词处理,呈现到前台,再通过lucene搜索引擎查询出来 ,关键词高亮
Lucene.Net.dll Highlighter.Net.dll
项目中代码包含了lucene的增删改查,中文词分器、luke查看工具、高亮显示等,mysql数据库等,作为新手学习lucene完全够用了,如果想深入学习,需要对其中属性等深入研究,请自行百度。
Struts2.3+spring4+hibernate4+Lucene4.7+IKAnalyzer,中文分词,高亮显示,附带MySQL8000条测试数据。仅供学习参考
NULL 博文链接:https://llying.iteye.com/blog/570208
lucene的用法,里面包含基本的用法还有分词,还有高亮显示,并且有JAR包
盘古中文分词+lucene.net2.3.1的详细示例 lucene.net2.3.1+盘古分词 Demo
分词、盘古分词、搜索关键词高亮显示。包含了lucene的基本操作
(4) 中文分词效果 19 4.2 分词原理 21 (1) TokenStream 21 (2) Tokenizer 22 (3) TokenFilter 23 4.3 分词属性 23 (1) 分词属性查看 24 (2) 分词属性对比 25 4.4 自定义分词器 26 (1) 自定义Stop分词器 26 (2) 实现...
lucene需要用到的基本架包 核心包 高亮 中文分词,希望有所帮助。je-analysis1.5.3.jar lucene-highlighter-3.0.0.jar lucene-core-3.0.0.jar lucene-memory-3.0.0.jar
其中包括了lucene的jar包还有IK分词器的jar包并且介绍了怎么使用lucene然后有如何进行高亮显示等..
Lucene5.3.1相关jar包,中文分词器,结果高亮; Lucene5.3.1相关jar包
文档中包含Lucene4.0.0版本jar包,中文分词器jar包,Lucene实例代码 1:建立索引 2:各种搜索方式方法 3:删除索引 4:检查索引文件 5:恢复删除的索引 6:强制删除 7:更新索引 8:合并索引 9:高亮回显 供大家参考...
分词时完全按照标准分词来进行,这样保证了在和一些高亮显示组件如highlighter一起使用时,能准确无误的将命中进行高亮显示,避免了Google高亮显示的 Bug;配置文件的存放支持相对路径,这样更灵活,更方便应用在一些...
全文检索介绍 索引 分词 Lucene介绍 Lucene应用详解 索引器 检索器 条件查询 实用工具及高亮器 Lucene综合应用——仿搜索引擎