Lucene Query的extractTerms的替代方法是什么? [英] What is an alternative for Lucene Query's extractTerms?

查看:132
本文介绍了Lucene Query的extractTerms的替代方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Lucene 4.6.0中,有extractTerms方法提供了从查询中提取术语的方法(查询Lucene 6.2.1 ).是否有有效的替代方法?

In Lucene 4.6.0 there was the method extractTerms that provided the extraction of terms from a query (Query 4.6.0). However, from Lucene 6.2.1, it does no longer exist (Query Lucene 6.2.1). Is there a valid alternative for it?

我需要解析由QueryParser构建的查询的术语(和对应字段).

What I'd need is to parse terms (and corrispondent fields) of a Query built by QueryParser.

推荐答案

也许不是最好的答案,但是一种方法是使用相同的分析器并标记查询字符串:

Maybe not the best answer but one way is to use the same analyzer and tokenize the query string:

Analyzer anal = new StandardAnalyzer();
TokenStream ts = anal.tokenStream("title", query); // string query
CharTermAttribute termAtt = ts.addAttribute(CharTermAttribute.class);
ts.reset();
while (ts.incrementToken()) {
    System.out.println(termAtt.toString());
}
anal.close();

这篇关于Lucene Query的extractTerms的替代方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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