private String computeSelectScore ( List < String > searchFields ) throws Exception { StringWriter sw = new StringWriter ( ) ; PrintWriter pw = new PrintWriter ( sw ) ; if ( 0 == searchFields . size ( ) ) { throw new Exception ( "Must supply at least one search field" ) ; } else if ( 1 == searchFields . size ( ) ) { pw . print ( "coalesce(nullif(position(lower(?) IN lower(" ) ; pw . print ( searchFields . get ( 0 ) ) ; pw . print ( ")), 0), 9999)" ) ; } else { int loop ; for ( loop = 0 ; loop < searchFields . size ( ) - 1 ; ++ loop ) { pw . print ( "least(coalesce(nullif(position(lower(?) IN lower(" ) ; pw . print ( searchFields . get ( loop ) ) ; pw . print ( ")), 0), 9999)," ) ; } pw . print ( "coalesce(nullif(position(lower(?) IN lower(" ) ; pw . print ( searchFields . get ( loop ) ) ; pw . print ( ")), 0), 9999)" ) ; for ( loop = 0 ; loop < searchFields . size ( ) - 1 ; ++ loop ) { pw . print ( ")" ) ; } } pw . flush ( ) ; return sw . toString ( ) ; }
Create a SQL fragment that can be used to compute a score based on a search .