private Query buildQueryForField(String fieldName,PriorityQueue<USField> q,BooleanQuery query){
  USField cur;
  int qterms=0;
  int maxTerms=maxQueryTermsPerField;
  if (maxTerms <= 0) {
    maxTerms=Integer.MAX_VALUE;
  }
  BooleanQuery tmpQuery=new BooleanQuery();
  double sumQuaredBoost=0.0f;
  while ((cur=q.pop()) != null) {
    Query tq=null;
    final Term term=new Term(cur.getFieldName(),cur.getWord());
    if (isPayloadField(cur.getFieldName())) {
      tq=new PayloadTermQuery(term,new AveragePayloadFunction(),true);
    }
 else {
      tq=new TermQuery(term);
    }
    float boost=cur.getScore();
    sumQuaredBoost+=boost * boost;
    tq.setBoost(boost);
    try {
      tmpQuery.add(tq,BooleanClause.Occur.SHOULD);
      qterms++;
    }
 catch (    BooleanQuery.TooManyClauses ignore) {
      break;
    }
    if (qterms >= maxTerms) {
      break;
    }
  }
  double vectorLength=Math.sqrt(sumQuaredBoost);
  if (vectorLength <= 0.0) {
    return query;
  }
  buildBoostedNormalizedQuery(fieldName,tmpQuery,query,vectorLength);
  return query;
}

private Query buildQueryForField ( String fieldName , PriorityQueue < USField > q , BooleanQuery query ) { USField cur ; int qterms = 0 ; int maxTerms = maxQueryTermsPerField ; if ( maxTerms <= 0 ) { maxTerms = Integer . MAX_VALUE ; } BooleanQuery tmpQuery = new BooleanQuery ( ) ; double sumQuaredBoost = 0.0f ; while ( ( cur = q . pop ( ) ) != null ) { Query tq = null ; final Term term = new Term ( cur . getFieldName ( ) , cur . getWord ( ) ) ; if ( isPayloadField ( cur . getFieldName ( ) ) ) { tq = new PayloadTermQuery ( term , new AveragePayloadFunction ( ) , true ) ; } else { tq = new TermQuery ( term ) ; } float boost = cur . getScore ( ) ; sumQuaredBoost += boost * boost ; tq . setBoost ( boost ) ; try { tmpQuery . add ( tq , BooleanClause . Occur . SHOULD ) ; qterms ++ ; } catch ( BooleanQuery . TooManyClauses ignore ) { break ; } if ( qterms >= maxTerms ) { break ; } } double vectorLength = Math . sqrt ( sumQuaredBoost ) ; if ( vectorLength <= 0.0 ) { return query ; } buildBoostedNormalizedQuery ( fieldName , tmpQuery , query , vectorLength ) ; return query ; }
build the more queryfromdocuments query from a priorityqueue and an initial boolean query
