简体   繁体   English

如何使用域类实例进行搜索?

[英]How to search using a domain class instance?

I have a domain class User with all the instances like 我有一个具有所有实例的域类User

[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 还有一个实例列表userInstanceList,其中只有几个对象,例如

[User : 3, User:4]

My search term is in User : 4 and also in some other objects in User . 我的搜索词用户:4,并在用户的一些其他对象。 When I search using 当我使用搜索

User.search(userInstanceList, searchTerm)

it returns all the objects in User with the searchTerm . 它使用searchTerm返回User中的所有对象。 How can I search objects only in userInstanceList 如何仅在userInstanceList中搜索对象

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. 如果要将搜索限制为仅对userInstanceList中的内容进行搜索,则应该能够在搜索时仅使用in子句。

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

or 要么

User.withCriteria {
    searchTerm
    inList id, userInstanceList*.id
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM