wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes the search method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "the search method" Watch "the search method" New topic
Author

the search method

Mika Tapanainen
Ranch Hand

Joined: Jun 11, 2009
Posts: 95
Hello,

I'm not sure if I have implemented the search functionality correctly in my application (B&S).

The requirement says:

"It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user."

I have in my application the name and location fields and the search button.

1) When the search button is pressed and the name and location fields are empty then the application retrieves all the records for the user
2) When there is value only for the name field the application retrieves only the records where the name field matches
3) When there is value only for the location field the application retrieves only the records where the location field matches
4) If there are values for the name and location fields then both fields in the database has to match

What you think "exactly match" means? Is it ok to match from the beginning and also use the method String.equalsIgnoreCase?

BR,

Mika


SCJP, SCJD, SCEA
http://fi.linkedin.com/in/mikatapanainen
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

Howdy, Mika!

One question about your approach... in the 4th case, you have the search for name and location. When do you have the search for name or location, and both name and location are filled?

And by exactly, I assumed that it means the whole word, no matter the case. So, if the user tries to find a record where location = Sao Paulo, and there is a record in the database that has location = SAO PAULO, then this record will be retrieved, if the user chose name or location, for instance.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5300
    
  13

Hi Mika,

I had the same implementation as you: 4 possible search scenario's exactly described like you did in your initial post.

My interpretation of "exactly" was "exactly" (case-sensitive), so "Sao Paulo" is "Sao Paulo", not "SAO PAULO" or "sao paulo", but "Sao Paulo".

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

You know, one thing that occurred to me now is that maybe this could be a good place for the Policy pattern; you can have an interface called SearchPolicy, then you can have implementations for the search, like CaseSensitiveSearch... this way, it should be easier to change the way the search mechanism works, since some people choose to implement a case-sensitive search, and others choose to implement a case-insensitive search.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5300
    
  13

Almost forgot to say: the find method in my Data class is a case-insensitive search
Mika Tapanainen
Ranch Hand

Joined: Jun 11, 2009
Posts: 95
Hello,

and thanks for the answers.

Roberto Perillo wrote:
One question about your approach... in the 4th case, you have the search for name and location. When do you have the search for name or location, and both name and location are filled?


Roberto, if I have values for both name and location, currently I don't have "or search" for both values. I think (and hope) cases 2 and 3 above fullfill the "or search".
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5300
    
  13

Mika,

Like I already pointed out in my first post: a search on "name or location" is not required.

Kind regards,
Roel
 
GeeCON Prague 2014
 
subject: the search method