【Lucene4.8教程之四】分析

【Lucene4.8教程之四】分析

大家好,又见面了,我是全栈君。

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中加入文档时。能够针对该文档指定一个分析器,如

writer.addDocument(doc, new SimpleAnalyzer(Version.LUCENE_48));


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/115433.html原文链接:https://javaforall.net

(0)
上一篇 2022年2月4日 下午3:00
下一篇 2022年2月4日 下午3:00


相关推荐

  • linux中的ens33配置

    linux中的ens33配置vim etc sysconfig network scripts ifg ens33TYPE Ethernet 网卡类型 为以太网 PROXY METHOD none 代理方式 关闭状态 BROWSER ONLY no 只是浏览器 否 BOOTPROTO dhcp 网卡协议 DHCP 动态主机配置协议 DEFROUTE yes 默认路由 是 IPV4 FAILURE FATA

    2026年3月18日
    2
  • 《论语》全文

    《论语》全文论语 全文 nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp 学而第一子曰 学而时习之 不亦悦乎 有朋自远方来 不亦乐乎 人不知而不愠 不亦君子乎 有子曰 其为人也孝悌而好犯上者 鲜矣 不好犯上而好作乱者 未之有也 君子务本 本立而道生 孝悌也者 其为仁之本与 子曰 巧言令色 鲜矣仁 曾子曰 吾日三省乎吾身 为人谋而不忠乎 与

    2026年3月17日
    3
  • Hbase面试题(持续更新)「建议收藏」

    Hbase面试题(持续更新)「建议收藏」1、每天百亿数据存入HBase,如何保证数据的存储正确和在规定的时间里全部录入完毕,不残留数据1)百亿数据:证明数据量非常大2)存入HBase:证明是跟HBase的写入数据有关3)保证数据的正确:要设计正确的数据结构保证正确性4)在规定时间内完成:对存入速度是有要求的那么针对以上的四个问题我们来一一分析1)数据量百亿条,什么概念呢?假设一整天60x60x24=86400秒都在写入数据,那么每秒的写入条数高达100万条,HBase当然是支持不了每秒百万条数据的,所以这百亿条数据可能不是通过实时

    2022年5月31日
    40
  • linux下的find文件查找命令与grep文件内容查找命令

    linux下的find文件查找命令与grep文件内容查找命令

    2021年10月14日
    51
  • 【python】pandas读取csv格式数据时header参数设置

    【python】pandas读取csv格式数据时header参数设置写在前面使用 pandas 中 read csv 读取 csv 数据时 对于有表头的数据 将 header 设置为空 None 会报错 pandas libs parsers pyxinpandas libs parsers raise parser error ParserError Errortokeniz Cerror Expected4fie

    2026年3月26日
    2
  • java文件上传下载接口_java 文件上传下载

    java文件上传下载接口_java 文件上传下载翻新十年前的老项目,文件上传改为调用接口方式,记录一下子~~~java后台代码://取配置文件中的上传目录@Value(“${uploadPath}”)Stringpath;//文件上传接口@RequestMapping(value=”upload”)@ResponseBodypublicStringgetMobileAuthCode(HttpServletRequestreques…

    2022年5月15日
    44

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号