Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Best way of handling multiple search Criteria

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Ankit Mishra
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
author & internet detective
Posts: 40213
816
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic