private String generateWhere ( String [ ] words , boolean allWords , boolean ignoreCase , boolean noMatchWhole ) { String result = "" ; // if all words must match use AND between the different conditions String join ; if ( allWords ) { join = " AND " ; } else { join = " OR " ; } // end of else for ( int wordInd = 0 ; wordInd < words . length ; wordInd ++ ) { String oneCondition = "" ; for ( int col = 0 ; col < columns . length ; col ++ ) { if ( oneCondition != "" ) { oneCondition += " OR " ; } if ( ignoreCase ) { if ( noMatchWhole ) { oneCondition += "LOWER(" + columns [ col ] + ") LIKE '%" + words [ wordInd ] . toLowerCase ( ) + "%'" ; } else { oneCondition += "LOWER(" + columns [ col ] + ") LIKE '" + words [ wordInd ] . toLowerCase ( ) + "'" ; } } else { if ( noMatchWhole ) { oneCondition += columns [ col ] + " LIKE '%" + words [ wordInd ] + "%'" ; } else { oneCondition += columns [ col ] + " LIKE '" + words [ wordInd ] + "'" ; } } } if ( result != "" ) { result += join ; } result += "(" + oneCondition + ")" ; } if ( result != "" ) { result = " WHERE " + result ; } // end of if (result != "") // System.out.println("result: "+result); return result ; }
generate the Where - condition for the words