public virtual int DoNestedTermConjunctions(IndexSearcher s, int termsInIndex, int maxOuterClauses, int maxClauses, int iter) { int ret = 0; long nMatches = 0; for (int i = 0; i < iter; i++) { int oClauses = Random.Next(maxOuterClauses - 1) + 2; BooleanQuery oq = new BooleanQuery(); for (int o = 0; o < oClauses; o++) { int nClauses = Random.Next(maxClauses - 1) + 2; // min 2 clauses BooleanQuery bq = new BooleanQuery(); BitSet termflag = new BitSet(termsInIndex); for (int j = 0; j < nClauses; j++) { int tnum; // don't pick same clause twice tnum = Random.Next(termsInIndex); if (termflag.Get(tnum)) { tnum = termflag.NextClearBit(tnum); } if (tnum < 0 || tnum >= 25) { tnum = termflag.NextClearBit(0); } termflag.Set(tnum); Query tq = new TermQuery(terms[tnum]); bq.Add(tq, Occur.MUST); } // inner oq.Add(bq, Occur.MUST); } // outer CountingHitCollector hc = new CountingHitCollector(); s.Search(oq, hc); nMatches += hc.Count; ret += hc.Sum; } if (Verbose) { Console.WriteLine("Average number of matches=" + (nMatches / iter)); } return(ret); }