Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the search method

 
Mika Tapanainen
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roel De Nijs
Sheriff
Posts: 9934
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9934
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Almost forgot to say: the find method in my Data class is a case-insensitive search
 
Mika Tapanainen
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9934
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mika,

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

Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic