简体   繁体   English

更改StandardAnalyzer Lucene

[英]Change StandardAnalyzer Lucene

I'm trying to search documents by title with StandardAnalyzer of lucene 4.10.3. 我正在尝试使用Lucene 4.10.3的StandardAnalyzer按标题搜索文档。 I read the quotes from a file and the I add the double quotation marks for constructing the query with this: 我从文件中读取了引号,并添加了双引号以使用此构造查询:

Query query = parser.parse("\""+doc.get("title")+"\"");

The problem is that when it reads the quote PHILIPPINES SAYS DEBT PACT "BETTER THAN MEXICO'S lucene returns this error 问题是,当它读取报价“菲律宾说债务协议”时,“比墨西哥的lucene更好的返回此错误

Cannot parse '"PHILIPPINES SAYS DEBT PACT "BETTER THAN MEXICO'S"': Lexical error at line 1, column 52.  Encountered: <EOF> after : ""

How can I solve it? 我该如何解决?

Thanks! 谢谢!

The problem is that the quote in the text you are searching for needs to be escaped. 问题在于您要搜索的文本中的引号需要转义。 You can escape text to be searched using QueryParser.escape : 您可以使用QueryParser.escape转义要搜索的文本:

Query query = parser.parse("\"" + QueryParser.escape(doc.get("title")) + "\"");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM