如何使用多短语查询? [英] how to use a multiphrasequery?

查看:16
本文介绍了如何使用多短语查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://lucene.apache.org/java/2_3_1/api/core/org/apache/lucene/search/MultiPhraseQuery.html

对于示例Microsoft app*",他说使用 IndexReader.term() 但返回 TermEnum,我如何将它放入 MultiPhraseQueryParser ?

for the example "Microsoft app*", he says use IndexReader.term() but that returns TermEnum, how do I put it in MultiPhraseQueryParser ?

或者有人告诉我如何在 Microsoft 应用程序* 上以更好的方式搜索超过 7.5 GB 的索引!!

Or someone tell me how do I do a search on Microsoft app* in a better way over a 7.5 GB index!!

推荐答案

您需要迭代 TermEnum 以获取条款.您可以迭代 TermEnum 以获取以app"开头的术语,如下所示.

You need to iterate on TermEnum to get the terms. You can iterate on the TermEnum to get terms starting with "app" as follows.

    TermEnum te = reader.terms(new Term("field", "app"));
    List<Term> termList = new LinkedList<Term>();       
    while(te.next()) {
        Term t = te.term();
        if (!t.field().equals("field") || !t.text().startsWith("app")) {
            break;
        }
        termList.add(t);
    }
    Term[] terms = termList.toArray(new Term[0]);

这篇关于如何使用多短语查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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