SearchTerm buildAnyTerm(String fieldName, String value) {
   SearchTerm term = new SearchTerm();
   term.setOperator("=");
   term.setFieldName(fieldName);
   term.setValue(value.toLowerCase().trim());
   return term;
 }
 BooleanClause partialMatch(SearchTerm s, int slop) {
   String[] phrase = getPhrase(s.getValue().toLowerCase().trim());
   PhraseQuery query = new PhraseQuery();
   BooleanClause partialMatchClause = null;
   query.setSlop(slop);
   for (int i = 0; i < phrase.length; i++) {
     query.add(new Term(s.getFieldName(), phrase[i].toLowerCase().trim()));
   }
   if (s.getOperator().equalsIgnoreCase("=")) {
     partialMatchClause = new BooleanClause(query, BooleanClause.Occur.MUST);
   } else if (s.getOperator().equalsIgnoreCase("-")) {
     partialMatchClause = new BooleanClause(query, BooleanClause.Occur.MUST_NOT);
   }
   return partialMatchClause;
 }
  BooleanQuery orPhraseQuery(List<SearchTerm> orSearchTerms) {
    BooleanQuery orTerms = new BooleanQuery();
    orTerms.setMaxClauseCount(dvnMaxClauseCount);
    for (Iterator it = orSearchTerms.iterator(); it.hasNext(); ) {
      SearchTerm elem = (SearchTerm) it.next();
      String[] phrase = getPhrase(elem.getValue().toLowerCase().trim());
      if (phrase.length > 1) {
        BooleanClause partialMatchClause = null;
        PhraseQuery phraseQuery = new PhraseQuery();
        phraseQuery.setSlop(3);

        for (int i = 0; i < phrase.length; i++) {
          phraseQuery.add(new Term(elem.getFieldName(), phrase[i].toLowerCase().trim()));
        }
        orTerms.add(phraseQuery, BooleanClause.Occur.SHOULD);
      } else {
        Term t = new Term(elem.getFieldName(), elem.getValue().toLowerCase().trim());
        TermQuery orQuery = new TermQuery(t);
        orTerms.add(orQuery, BooleanClause.Occur.SHOULD);
      }
    }
    return orTerms;
  }
 BooleanQuery andSearchTermClause(List<SearchTerm> andSearchTerms) {
   BooleanQuery andTerms = new BooleanQuery();
   andTerms.setMaxClauseCount(dvnMaxClauseCount);
   Query rQuery = null;
   for (Iterator it = andSearchTerms.iterator(); it.hasNext(); ) {
     SearchTerm elem = (SearchTerm) it.next();
     if (elem.getOperator().equals("<")) {
       Term end = new Term(elem.getFieldName(), elem.getValue().toLowerCase().trim());
       Term begin = null;
       rQuery = new RangeQuery(begin, end, true);
       andTerms.add(rQuery, BooleanClause.Occur.MUST);
     } else if (elem.getOperator().equals(">")) {
       Term end = null;
       Term begin = new Term(elem.getFieldName(), elem.getValue().toLowerCase().trim());
       rQuery = new RangeQuery(begin, end, true);
       andTerms.add(rQuery, BooleanClause.Occur.MUST);
     } else if (elem.getFieldName().equalsIgnoreCase("any")) {
       andTerms = buildAnyQuery(elem.getValue().toLowerCase().trim());
     } else {
       String[] phrase = getPhrase(elem.getValue().toLowerCase().trim());
       if (phrase.length > 1) {
         PhraseQuery phraseQuery = new PhraseQuery();
         phraseQuery.setSlop(0);
         andTerms.add(partialMatch(elem, 3));
       } else {
         Term t = new Term(elem.getFieldName(), elem.getValue().toLowerCase().trim());
         TermQuery andQuery = new TermQuery(t);
         if (elem.getOperator().equals("=")) {
           andTerms.add(andQuery, BooleanClause.Occur.MUST);
         } else if (elem.getOperator().equalsIgnoreCase("-")) {
           andTerms.add(andQuery, BooleanClause.Occur.MUST_NOT);
         }
       }
     }
   }
   return andTerms;
 }