为什么Lucene QueryParser需要分析器 [英] Why does Lucene QueryParser needs an Analyzer

查看:97
本文介绍了为什么Lucene QueryParser需要分析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Lucene的新手,正尝试使用QueryParser将原始字符串解析为Query.

I'm new to Lucene and trying to parse a raw string into a Query using the QueryParser.

我想知道为什么QueryParser.Parse()方法根本需要一个Analyzer参数?

I was wondering, why is the QueryParser.Parse() method needs an Analyzer parameter at all?

如果分析与查询有关,那么在处理常规Query对象(TermQueryBooleanQuery等)时也应指定Analyzer,否则,为什么QueryParser需要吗?

If analyzing is something that has to do with querying, then an Analyzer should be specified when dealing with regular Query objects as well (TermQuery, BooleanQuery etc), and if not, why is QueryParser requires it?

推荐答案

建立索引时,Lucene将文本分为原子单位(令牌).在此阶段中,可能会发生很多事情(例如,下套管,阻止词条,删除停用词等).最终结果是一个学期.

When indexing, Lucene divides the text into atomic units (tokens). During this phase many things can happen (e.g. lowercasing, stemming, removal of stopwords, etc.). The end result is a term.

然后,当您查询时,Lucene会对查询应用完全相同的算法,以便它可以将term与term进行匹配.

Then, when you query, Lucene applies exactly the same algorithm to the query so it can match term with a term.

问:为什么TermQuery不需要分析仪?
答:QueryParser对象解析查询字符串并生成TermQuery(也可以生成其他类型的查询,例如PhraseQuery). TermQuery已经包含与索引中相同形状的术语.如果您(作为程序员)完全确定自己的工作,则可以自己创建TermQuery,但是前提是您知道查询解析的确切顺序,并且知道术语在索引中的样子.

Q: Why doesn't TermQuery require analyzer?
A: QueryParser object parses query string and produces TermQuery (can also produce other types of queries, e.g. PhraseQuery). TermQuery already contains terms in the same shape as they are in the index. If you (as a programmer) are absolutely sure what you doing, you can create a TermQuery yourself -- but this assumes you know the exact sequence of query parsing and you know how terms look like in the index.

问:为什么BooleanQuery不需要分析仪?
答:BooleanQuery仅使用运算符(AND/OR/MUST/SHOULD等)联接其他查询.如果没有其他查询,它本身并没有真正的用处.

Q: Why doesn't BooleanQuery require analyzer?
A: BooleanQuery just joins other queries using operators (AND/OR/MUST/SHOULD, etc.). It's not really useful itself without any other queries.

这是一个非常的简化答案.我强烈建议您阅读信息检索简介书;它包含基于Lucene(和其他类似框架)编写的理论.这本书可在线免费获得.

This is a very simplified answer. I highly recommend reading Introduction to Information Retrieval book; it contains the theory based on which Lucene (and other similar frameworks) is written. This book is available online for free.

这篇关于为什么Lucene QueryParser需要分析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆