0

I have a domain class User with all the instances like

[User : 1, User: 2, User : 3, User:4, User: 5, User: 6, User: 7, ...]

and an instance list userInstanceList with only a few objects, say

[User : 3, User:4]

My search term is in User : 4 and also in some other objects in User. When I search using

User.search(userInstanceList, searchTerm)

it returns all the objects in User with the searchTerm. How can I search objects only in userInstanceList

Syam
  • 575
  • 2
  • 8
  • 25
  • I'm not sure I understand exactly what userInstance is supposed to be in this case. Are you saying UserInstance is a subclass of User or are you just saying userInstance is a list holding a few specific instances of User? – Aaron Aug 01 '14 at 12:49
  • It's a list holding specific User instances – Syam Aug 01 '14 at 12:52

1 Answers1

1

If you want to restrict the search to only the things in the userInstanceList, you should be able to just use the in clause when searching.

User.findAll { 
   searchTerm && id in userInstanceList*.id
}

or

User.withCriteria {
    searchTerm
    inList id, userInstanceList*.id
}
Aaron
  • 546
  • 3
  • 8
  • I used _resultListFromSearch.findAll{it.id in userInstance*.id}_ to return a list containing common objects. – Syam Aug 01 '14 at 13:30
  • 1
    Yeah, I thought about suggesting that but I assumed you wanted to actually query the database again for some reason. Obviously searching the in-memory list is the better option from a performance standpoint. – Aaron Aug 01 '14 at 14:07