2014-06-05 58 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' 
    } 
}