This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

search method in business layer

 
Ethem Yuksel
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all,
There are many topics mentioned about search algorithm. But i need a few code fragments how to accomplish the search function in business layer not in data. Data layer will make a search with the all fields starts with criteria[n]. Business layer will filter data's find results with the "equals". This is clear.

But how is it supposed to be combine these two items? What should be the simplest way? I have written something but looking forward to something simpler.

Thanks..
 
K. Tsang
Bartender
Pie
Posts: 3225
12
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Ethem, why you want to implement the search in the "business layer" when searching is one of those required methods in the Data class?

Business layer will filter data's find results with the "equals". This is clear.


What you mean by "equals"? Are you using the comparator or comparable interface to do the searching? Some code will help others what you done so far.
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ethem Yuksel wrote:What should be the simplest way? I have written something but looking forward to something simpler.

Well, what did you implement so far? Maybe we could help you improve it.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:why you want to implement the search in the "business layer" when searching is one of those required methods in the Data class?

I would imagine that he would want to do this because of the different requirements.

The Data layer only requires a "begins with" matching.
The presentation layer requires an "exact match".

Therefore you must have different logic in two separate areas.

Andrew
 
Ethem Yuksel
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Andrew, exactly right you are.
@Alec, my implementation is as the following. It is working but it really sucks How can i make it simpler? Regards...
 
Fola Fadairo
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Looks okay to me. I find it readable and easy to understand, especially for a junior programmer.


 
Kevin Florish
Ranch Hand
Posts: 181
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fola

Not sure what the spec requirements are for your assignment.

I have done B&S 2.2.1 and the implementation of the DBAccess interface requires a possible search on all fields.

I use a Contractor class as an O-O framework which helps with the search functionality and use booleans for each field passed.

If the passed field is set to true then I check the value against my active Contractor record. Its a bit long winded but easy for a junior programmer to understand. Here's a snippet of code to explain what I mean.



 
Fola Fadairo
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Kevin,
I have URLyBird. The thread is about the search requirements on the business side. Part of the requirements state:

"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 understand this to mean, String.equals(...) or String.equalsIgnoreCase(...). The code I posted demonstrates the way which appears most intuitive to me. There are probably easier and more efficient ways to do it, but I like the simplicity of the code.

The find method returns an array of integers, so the code will not work as posted, one will still have some fun providing a working implementation.

Regards,
Fola

 
Bert Bates
author
Sheriff
Posts: 8898
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

It's always a tough call when to say that a thread is getting a little too detailed in this forum... this one is making me a bit uncomfortable, let's back off the details a bit!

Thanks,

Bert
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ethem Yuksel wrote:@Alec, my implementation is as the following. It is working but it really sucks How can i make it simpler?

What I did is very similar to yours, just that I did not provide "OR" functionality (which makes everything much simpler ).
I also used a Filter object instead of plain parameters or the query[] you're using. This makes everything much easier to extend later with new criteria.
You should also break down your code into more methods, to make it easier to understand and manage.
 
Nicolas Zozol
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin Florish wrote:



Hi,
This implementation is absolutely logical, but the definition of the find says that search seek the start of the field.


Aren't you afraid to fail with this search ? Should this be an option (and therefore it brings no more points !) ? One point however is that the interface method documentation doesn't say must.
 
Roel De Nijs
Sheriff
Posts: 9189
77
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nicolas,

I actually don't see the problem. The comments of the find-method: criteria[n] matches any field value that begins with criteria[n]. And that's what the code of Kevin Florish exactly does! So why would he be afraid to fail? I also used the startsWith-method, just like him.

Kind regards,
Roel
 
Nicolas Zozol
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:Hi Nicolas,

I actually don't see the problem. The comments of the find-method: criteria[n] matches any field value that begins with criteria[n]. And that's what the code of Kevin Florish exactly does! So why would he be afraid to fail? I also used the startsWith-method, just like him.

Kind regards,
Roel


Oups, I read too fast Because specilities was separate, I thought it had a special treatment : the one I was discussing of, and working on. Like lot of scientists says, you read what your brain is ready to read....
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic