These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Problem In Multiple Search Criteria with One TextBox
PostPosted: Sat Feb 20, 2010 4:37 am 
Newbie

Joined: Sat Feb 20, 2010 4:29 am
Posts: 2
Hii to all, I am facing a problem with Searching Functionality. In this functionality I have only one TextBox for searching. Basically searching would apply with following criteria s or Keywords.
-Searching Can be Done with
1. Employee's First Name
2. Employee's Last Name
3. Branch
4.Designation
5.City
6.State
7.Date of Birth
8. Date of Joining

On running module,Only Employee First Name is the keyword which is being used to search a Employees

string SearchQuery = txtSearch.Text;

IList<Employees> foundEmployees = session.CreateCriteria(typeof(Employees)).Add(Expression.Like("FirstName", "%" + SearchQuery + "%")).List<Employees>();

But I want all the above Keywords and using them in above query


Top
 Profile  
 
 Post subject: Re: Problem In Multiple Search Criteria with One TextBox
PostPosted: Fri Mar 05, 2010 4:57 am 
Newbie

Joined: Fri Mar 05, 2010 4:55 am
Posts: 1
Hi!
I have exactly the same problem as you have.
did you find a solution to this problem?

Best Regards
Svante


Top
 Profile  
 
 Post subject: Re: Problem In Multiple Search Criteria with One TextBox
PostPosted: Fri Mar 05, 2010 8:51 am 
Newbie

Joined: Tue Mar 02, 2010 6:40 am
Posts: 3
I had the same problem. I'm using Criteria and have something like this:

Code:
Criteria criteria = session.createCriteria(Cat.class);
criteria.add( Restrictions.or(
                       Restrictions.like("name", "%"+searchParam+"%").ignoreCase(),
                       Restrictions.like("color", "%"+searchParam+"%").ignoreCase()
                      
                       ));


This works but you can only add two Criterions. To compare more fields you can use Disjunction:

Code:
               criteria.add( Restrictions.disjunction()

                      .add(Restrictions.like("name", "%"+searchParam+"%").ignoreCase())                   
                      .add(Restrictions.like("color", "%"+searchParam+"%").ignoreCase())                  
                      .add(Restrictions.like("lastName", "%"+searchParam+"%").ignoreCase())
               
                      );


What I still don't get is how to add associated restrictions to a disjuction.

Code:
criteria.createCriteria("kittens").add( Restrictions.like("color", "%"+searchParam+"%").ignoreCase() );


How would you throw this in the mix?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.