how to use a multiphrasequery?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 03:44:46

问题


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

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

Edit :

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


回答1:


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]);


来源:https://stackoverflow.com/questions/5075304/how-to-use-a-multiphrasequery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!