[英]Lucene how to add a Term to a Term[]
I have this sample (just a snip where the MultiPhraseQuery is built): 我有这个示例(只是在其中构建MultiPhraseQuery的一个片段):
// *** MultiPhraseQuery ***
MultiPhraseQuery mQuery = new MultiPhraseQuery();
// *** TermL1 ***
mQuery.add(new Term[] {
new Term("abstract", "quick"),
new Term("abstract", "fast")
});
// *** TermL2 ***
Term t1 = new Term("abstract", "fox");
Term t2 = new Term("abstract", "rabbit");
Term[] termL2 = new Term[] {
t1, t2
};
mQuery.add(termL2);
I'd like to build TermL2 with an iterative method (like a loop) to allow to add a dynamic number of terms (t1, t2, t..., tn). 我想用迭代方法(如循环)构建TermL2,以允许添加动态数量的术语(t1,t2,t ...,tn)。 It doesn't seem to be such an hard problem but I haven't any found a solution since a while now. 这似乎不是一个难题,但是从现在开始我一直没有找到解决方案。
int n;
//Set this variable to the # of terms
String nextTerm;
Term[] termL2 = new Term[n];
for (int i = 0; i < n; i++) {
nextTerm = blahblah; //here you set your next term
termL2[i] = new Term("abstract", nextTerm);
}
mQuery.add(termL2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.