| Author |
basic search - help
|
Deyna Cegielski
Ranch Hand
Joined: Nov 24, 2004
Posts: 60
|
|
ive been implementing a basic search function which given a specified keyword searching a column in a database for records that contain the keyword. problem is the search is case sensitive and does not take into consideration that the keyword may be a substring. for instance, forename = David will only return this record if you specify "David" "david, dav" does not work but i want it to. any advice? at the moment i am using string.contentsEquals(stringbuffer) for my evaluations, ive had a look through the API and cannot find much to help me thanks
|
 |
Alana Sparx
Ranch Hand
Joined: Feb 14, 2006
Posts: 121
|
|
Are you basically comparing two Strings to see if they are the same, despite differences in capitalisation, or where one starts with the value of the other? There are methods on the String class that do this. Also, if your passing the String 'dav' to an SQL statement, you could use the sql 'like' command. Oracle also has an UPPER statement you could use. hope this helps
|
 |
Deyna Cegielski
Ranch Hand
Joined: Nov 24, 2004
Posts: 60
|
|
|
would like the case to be case insensitive, and to be able to type in a substring of a word and return all results containing that substring. i completely forgot about the like cause in mysql (not used it in a while) i shall have a look in my book see what i can do with it.
|
 |
Alana Sparx
Ranch Hand
Joined: Feb 14, 2006
Posts: 121
|
|
I suspect that you'll also want to determine if the flavour of SQL you're using supports an 'UPPER' clause. That way you can do your search in one statement. Otherwise, you'll need to change the case of your search string (using the appropriate String API methods) and perform: a search for the String as passed in; a search in lowercase; a search in uppercase; title case? random case? arrrgggg!!
|
 |
Deyna Cegielski
Ranch Hand
Joined: Nov 24, 2004
Posts: 60
|
|
|
hehe, its all sorted, thanks for the help!
|
 |
 |
|
|
subject: basic search - help
|
|
|