wood burning stoves 2.0*
The moose likes JDBC and the fly likes Best way of handling multiple search Criteria Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Best way of handling multiple search Criteria" Watch "Best way of handling multiple search Criteria" New topic
Author

Best way of handling multiple search Criteria

Ankit Mishra
Ranch Hand

Joined: Jul 15, 2009
Posts: 40
Hi All,

I have one requirement - There are say 4 search criteria and using permutation I can have combination of these search criteria to drill down my search results.

What will be the best way to achieve this in the backend. I have used query to get the search results now how can I get the desired search result using java!


Regards,
Ankit Mishra (SCJP 5.0 93%), (SCWCD 5.0 97%)
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

Ankit Mishra wrote:... What will be the best way to achieve this in the backend. I have used query to get the search results now how can I get the desired search result using java!...

What you have got so far and where have you stuck in the code?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Ankit Mishra
Ranch Hand

Joined: Jul 15, 2009
Posts: 40
Thanks Bear, Sorry for the trouble!

@ Vijitha

I give you an example - I have 4 fields say date, name, age and marks.

now i have combinations to give me desired results for example:
Only date [gives a longer search result]
date + name
date + age
date + marks
date + name + age
date + name + marks
.................

I have one single query to get the desired search result!

What I am doing is extracting the complete result once which is say will get on the date search criteria a bigger chunk.

now, for other combinations I am currently maintaining one list in which i have the search result [bigger chunk] and then I am removing elements not needed with other combinations
for example:

I have got this list
name - a, b, c,d, e ,f
age - 12,13, 12,, 13, 14
marks- 78, 78, 78 ,78 ,78

so above is one complete list when i say on date say 10 oct 2010 and search only by age which is 12 so my result set should be:
name - a, d
age -12,12
marks-78,78

for this i am removing unwanted items

Any help in this regard will be helpful for me!

Please, Its urgent for me ...

Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

Wouldn't it be a performance issue to load all the data at once as your data grows? You may consider having multiple queries for each different criteria so that only the matching data are retrieved.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

I understood that you've used SQL query to get the data. Why do you need to reimplement it in Java?

Using SQL for this task would seem the best way to me. Databases were made exactly for answering questions like this.
Ankit Mishra
Ranch Hand

Joined: Jul 15, 2009
Posts: 40
Hi,
Thanks for your replies!
Ya that would be a performance hit that's why i put up this question. I am working with dynamic queries now searching on criteria basis now.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

You would build a SQL statement at runtime based on what they wanted to criteria. For example "where date = ? and name= ?". I agree witht he above posters that it is definitely best not to filter in Java afterwards.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best way of handling multiple search Criteria
 
Similar Threads
How to search a pattern in a large file using java
feedback on this proposed design
Retain search results
retain search and sorting results
How to retain search results