0

I have this sample (just a snip where the MultiPhraseQuery is built):

// *** 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). It doesn't seem to be such an hard problem but I haven't any found a solution since a while now.

Marco Evasi
  • 441
  • 2
  • 14
  • possible duplicate of [java dynamic array sizes?](http://stackoverflow.com/questions/1647260/java-dynamic-array-sizes) – femtoRgon Jun 29 '15 at 17:44

1 Answers1

1
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);
BoDidely
  • 504
  • 3
  • 13