【Lucene4.8教程之四】分析
来源:互联网 发布:淘宝直播快速申请成功 编辑:程序博客网 时间:2024/05/01 07:39
1、基础内容
(1)相关概念
分析(Analysis),在Lucene中指的是将域(Field)文本转换成最基本的索引表示单元--项(Term)的过程。在搜索过程中,这些项用于决定什么样的文档能够匹配查词条件。
分析器对分析操作进行了封装,它通过执行若干操作,将文本转化成语汇单元,这个处理过程也称为语汇单元化过程(tokenization),而从文本洲中提取的文本块称为语汇单元(token)。词汇单元与它的域名结合后,就形成了项。
(2)何时使用分析器
- 建立索引期间
- Directory returnIndexDir = FSDirectory.open(indexDir);
- IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_48,
- new StandardAnalyzer(Version.LUCENE_48));
- IndexWriter writer = new IndexWriter(returnIndexDir, iwc);
- 使用QueryParser对象进行搜索时
- QueryParser parser = new QueryParser(Version.LUCENE_48, "contents",
- new SimpleAnalyzer(Version.LUCENE_48));
- 在搜索中高亮显示结果时
(3)常用的4个分析器:
- WhitespaceAnalyzer, as the name implies, simply splits text into tokens on whitespace characters and makes no other effort to normalize the tokens.
- SimpleAnalyzer first splits tokens at non-letter characters, then lowercases each token. Be careful! This analyzer quietly discards numeric characters.
- StopAnalyzer is the same as SimpleAnalyzer, except it removes common words (called stop words, described more in section XXX). By default it removes common words in the English language (the, a, etc.), though you can pass in your own set.
- StandardAnalyzer is Lucene’s most sophisticated core analyzer. It has quite a bit of logic to identify certain kinds of tokens, such as company names,
四、其它内容
在创建IndexWriter时,需要指定分析器,如:
- <span> </span>IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_48,
- <span> </span>new StandardAnalyzer(Version.LUCENE_48));
- <span> </span>writer = new IndexWriter(returnIndexDir, iwc);
- writer.addDocument(doc, new SimpleAnalyzer(Version.LUCENE_48));
0 0
- 【Lucene4.8教程之四】分析
- 【Lucene4.8教程之四】分析
- 【Lucene4.8教程之四】分析
- 【Lucene4.8教程之二】索引
- 【Lucene4.8教程之三】搜索
- 【Lucene4.8教程之五】Luke
- 【Lucene4.8教程之二】索引
- 【Lucene4.8教程之三】搜索
- 【Lucene4.8教程之二】索引
- 【Lucene4.8教程之三】搜索
- 【Lucene4.8教程之五】Luke
- lucene4.7 之排序(四)
- Lucene4源代码分析之二:Lucene简介
- Lucene4.10使用教程(四):lucene的Search
- Lucene4.10使用教程(四):lucene的Search
- Lucene4.10使用教程(四):lucene的Search(转)
- Lucene4.10使用教程(四):lucene的Search
- 【Lucene4.8教程之六】QueryParser与Query子类:如何生成Query对象
- typedef函数指针用法
- CentOS6.5下通过Shell创建、备份、还原MySQL数据库
- C语言将一个简单的文件压缩
- MATLAB函数图像坐标轴刻度改变
- Android开发学习笔记——编译和运行原理(1)
- 【Lucene4.8教程之四】分析
- [学习笔记]Java继承机制
- 技术记录1 android Activity去掉标题和欢迎界面的延时跳转代码
- C++学习笔记(第9章->内存模型和名称空间)
- bootstrap中的div
- Python 之 @property
- Makefile(八)
- SQL中case when 语法
- 【Lucene4.8教程之五】QueryParser与Query子类:如何生成Query对象