2014-06-05 60 views
0

我使用grails可搜索插件来搜索我的领域类。但是,即使它们是简单类型的字符串,我仍然无法通过我的hasMany(技能和兴趣)字段进行搜索。这是我的域类:Grails可搜索插件hasMany

class EmpactUser { 

static searchable = [except: ['dateCreated','password','enabled','accountExpired','accountLocked','passwordExpired']] 

String username 
String password 
boolean enabled = true 
boolean accountExpired 
boolean accountLocked 
boolean passwordExpired 

String email 
String firstName 
String lastName 

String address 
String phoneNumber 
String description 

byte[] avatar 
byte[] resume 

Date dateCreated 

    static hasMany = [ 
     skills : String, 
     interests : String, // each user has the ability to list many skills and interests so that they can be matched with a project. 
] 

static constraints = { 
    username blank: false, unique: true 
    password blank: false 
    email email: true, blank: false 

    firstName blank: false 
    lastName blank: false 

    description nullable: true 
    address nullable: true 
    avatar nullable: true, maxSize: 1024 * 1024 * 10 
    resume nullable: true, maxSize: 1024 * 1024 * 10 
    phoneNumber nullable: true, matches: "/[(][+]d{3}[)]d+/", maxSize: 30 
} 




} 

这是我使用的搜索代码:

def empactUserList = EmpactUser.search(
      searchQuery, 
      [reload: false, result: "every", defaultOperator: "or"]) 

我这么想吗?

谢谢, Alan。

回答

0

可检索性与识别与String有很多关系时遇到了问题。解决方法是创建一个“属于”父对象的新域对象,并在父类中创建一个瞬态变量。以下代码可作为the example given in documentation的备用。

class Article { 
    static searchable = { 
     root true 
     keywords (component:true) 
    } 

    static transients = ['keywords'] 

    Set<ArticleKeyword> getKeywords() { 
     ArticleKeyword.findAllByArticle(this) as Set 
    } 
} 

class ArticleKeyword { 
    static searchable = { root false} 

    static constraints = {  
    } 

    String text 

    static belongsTo = [article:Article] 
    static mapping = { 
     text  type: 'text' 
    } 
}