find method and criteria with multiple not null values

Hi there,
I was working under find(Criteria[n]) method, and implemented couple scenarios, like:
1. if criteria has all null values – return all recNo from cache.
2. If criteria has only one real value and all rest are nulls -> return recNo matching single criteria.

But scenario when criteria has more than one not null value and potentially all values are not null puzzles me.
String[] criteria = {“Nice Place”, “My Town”, ” 2”, ”Y”, ”$200”, “2012/08/01”,null} ->

My interpretation of it is “select recNO from table where name=Nice Place AND city=My Town AND size = 2 AND price= 200 and etc.”
So, if database has hotel “Nice Place” in two locations: “My Town” and “Your Town”, only one record, can be returned, and only if , all rest criteria for size, price will match.

So, I have to create a count of internal matches between criteria and db record. So, if criteria has 5 values to search for – db record should have precisely 5 matching fields.

Is another interpretation like find any hotel with name =Nice Place OR location =My Town OR size= 2 OR price 200, etc will work?
Find in this case can return: x number of record Nice Place ( all different locations)
m number of record My Town ( all different hotels)
xx number of record size 2 ( all different hotels/ locations), etc
Any suggestion?

If instructions do not have specific search algorithm, you have to make decisions yourself and justify them in choices.txt. Think of some use cases that may happen with client and operator working with the application and implement the business logic accordingly.

Margarita Babkova
Ranch Hand

Joined: May 09, 2012
Posts: 32

posted Jun 10, 2012 11:26:32

0

ok i will try to implement db find method with all criterias and use AND instead of OR between elements.

I opted to have a match if one criterium matches a record (so using OR instead of AND). There are a lot of threads discuss this issue, so just decide for yourself what's best (or what's most logical to you) and stick with it.