Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes And/or search logic 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 "And/or search logic" Watch "And/or search logic" New topic
Author

And/or search logic

Petr Hejl
Ranch Hand

Joined: Feb 26, 2006
Posts: 68
Hello,
I would like to discuss and/or logic for search. My instructions say that gui should allow user to search "for records where the name and/or location fields exactly match values specified by the user".

It doesn't seem so clear to me now. The statement consist of two in real:
...where the name and location fields exactly match values...
...where the name or location fields exactly match values...

I'm not sure if the second should be programmed as "or" match. Or in gui as "xor" - user can select name xor ( ) location. Its common end user logic.

If it would be real or logic it could be difficult to user to understand - and there would be no clear way how to search (for example) for name only.

Thanks for your opinions.
P.
[ October 15, 2006: Message edited by: Petr Hejl ]
Bhavik Patel
Ranch Hand

Joined: Jul 12, 2004
Posts: 155
from the previous discussions ,
i have concluded the following

if only name is entered -- search for name records
if only location is entered -- search for location records
if name and location is entered -- search for the record that matches naem & location both.


SCJP 1.4<br />SCWCD 1.4(91%)<br />Working on SCJD -Bodgitt & Scrapper Constructions...<br /> <br />"It takes 43 muscles to frown & 17 to smile but it doen't take any to just sit there with a dumb look on your face .. Keep Smiling "
Petr Hejl
Ranch Hand

Joined: Feb 26, 2006
Posts: 68
In such case you can't (theoretically) search for name "", can you?
Bhavik Patel
Ranch Hand

Joined: Jul 12, 2004
Posts: 155
in the gui if you don't specify any criteria ( lets say name & location are empty -- blank in the gui ) you return all records..
Petr Hejl
Ranch Hand

Joined: Feb 26, 2006
Posts: 68
Any other opinions please?

Should I implement true or logic or is this enough?

1) name and location not empty (and)
2) name not empty, location empty (or - search for name)
3) name empty, location not empty (or - search for location)
4) name and location empty (search all)

Do you implement selection through combo boxes (this has issues if we consider data can change)?
Niels de Feijter
Greenhorn

Joined: Aug 25, 2006
Posts: 5
Originally posted by Petr Hejl:

1) name and location not empty (and)
2) name not empty, location empty (or - search for name)
3) name empty, location not empty (or - search for location)
4) name and location empty (search all)

[/QB]


This is the way I have implemented it (I have the exact same requirement). Don't know if it is valid though, I have not submitted yet.
Joe Zhou
Ranch Hand

Joined: Oct 18, 2006
Posts: 34
I would like to add a case:
5) Name not empty and Location not empty ( search by OR)
Any record having specified Name or Location should be returned by the search.
Bhavik Patel
Ranch Hand

Joined: Jul 12, 2004
Posts: 155
I dont see any logical for case 5..

if you got amazon.com and enter author ="XYZ" and TITLE="ABC" .. Do you expect to get results for any books from XYZ author... You are specifically aksing
for contractor working at this location whose name is this.. I believe this case should be only AND. If you see the previous posts , theres a huge discussion on this topic.
Joe Zhou
Ranch Hand

Joined: Oct 18, 2006
Posts: 34
Not sure how your 'Instruction.html' states the user interface.
Check the following requirement:

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.

For no matter what values for name/location, the logic should include 'and/or'
Petr Hejl
Ranch Hand

Joined: Feb 26, 2006
Posts: 68
It is exactly what I'm asking for To implement _real_ or or not to implement it?
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
My instructions.html file clearly 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 think the search mechanism that we implement must allow the user to search by:

1. just name
2. just location
3. name and location
4. name or location

Since the findByCriteria() proposed by Sun in the assignment searches all records that look like the provided criteria we'll have to provide empty Strings values for all the values in the findByCriteria() method, except for those fileds we are looking for.

Once we have the result set, we remove all the values not matching the business criteria.
Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
I add a flag (UI == checkbox) so that the user can select whether he wants to use AND search or an OR search in that way it is on him to select rather than we presuming things based on empty values for the various fields.


-Sam Codean<br />SCJP 1.4 (98%)<br />SCJD 5.0 (87.5%)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: And/or search logic
 
Similar Threads
name and/or location search
NX:Contractor Search Requirement
The bug-prone findByCriteria
A discrepancy in the specifications?
GUI in B&S