• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Search

 
Rahim Nathwani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the requirment:
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.

My interpretation for the method find(String[] criteria):
1. criteria{null,null,null,null......} - Display all records
2. criteria{"Fr",null,null,null......} - Display all records that name starts with "Fr"
3. criteria{null,"Ed",null,null......} - Display all records that location starts with "Ed"
4. criteria{"Fred","Ed",null,null......} - Display all records that name starts with "Fr" AND location starts with "Ed"

I'm not sure if point number 4 is correct - Anyone have thought about this requirement?

Thanks
 
Rahim Nathwani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry number 4 has a typo:

4. criteria{"Fr","Ed",null,null......} - Display all records that name starts with "Fr" AND location starts with "Ed"

thanks
 
Tim Anlauf
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's excactly the way I have implemented it.
 
Rahim Nathwani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just realized something in my assignment

The instructions.html states:
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.

The DB intergace states:
// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)


public int[] find(String[] criteria) {
return null;
}

Which search do I do? Match exactly or "Fred" results in a return of "Freddy"?
 
Jeremy Botha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Rahim.

I followed the contract specified in the DBMain interface, and matched anything which started with the specified search term.

There are a number of WTF's in the documentation. I assume you're working on B&S?

Jeremy
 
Marcelo Ortega
Ranch Hand
Posts: 528
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i first read the instruction on this point i interpreted it as having a button where the user can click on "Search All" which will show all fields, and two JTextFields, one for name and another for location (with a "Search" button), where the user can specify the name and/or location criteria. After reading a couple of threads i noticed that i had interpreted the instructions incorrectly, and that i should allow the user to be able to specify a value for any of the database fields. Is this correct? My instructions state the same as the first post:
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


If i am right, this would be quit ugly for the GUI. Any thoughts?

Regards.
[ October 31, 2006: Message edited by: Marcelo Ortega ]
 
Rahim Nathwani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jeremy,

You got it with the WTF --- Too many

I'm working on UrlyBird - Room rental. I have decided exactly what you did as far as the search. I am searching anything which started with the specified search term. So if the search is "Fr" --> returns "French", "Fred" ---> NOT "fred" ie. Case sensitive

Marcelo,

I have understood the search as you have. I don't think that we need a search on every column. Love for someone who has passed the certification doing it this way to conform.
 
Marcelo Ortega
Ranch Hand
Posts: 528
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rahim,
If this is so, then the findByCriteria(String[] criteria) method is quit stupid, because it says that field n matches criteria[n], and if we are only providing values for the name and location, what happens to the rest of the positions in the array?? I think explicitly setting them to null is pretty dum, don't you think?

Anyone got a different view on this?

Regards.
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marcelo Ortega:
Hi Rahim,
If this is so, then the findByCriteria(String[] criteria) method is quit stupid, because it says that field n matches criteria[n], and if we are only providing values for the name and location, what happens to the rest of the positions in the array?? I think explicitly setting them to null is pretty dum, don't you think?

Anyone got a different view on this?

Regards.



Yes but creating a String array will auutomatically set all the values to null, so you need only set the criteria fields you are interested in.


while the search method as called by the GUI only requires the name and location fields to be searchable, it seems natural that it should be implemented in a way that would make it easy to add new fields to search on if a future search enhancement is required (I think the GUI requirement hint at this point too, ie establishing a framework ...).

My criteria method is a case insensitive startWith comparison of each field. I think that a case sensitive approach is not very user friendly at all and that a case insensitive search is very justifiable on these grounds.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic