Grails searchable plugin
In my Grails app, I have the following domain class that is indexed by the Searchable plugin:
class Foo implements Serializable {
BookletCategory bookletCategory
Date lastUpdated
static hasMany = [details: BookletRootDetail]
static searchable = {
bookletCategory component开发者_如何转开发: true
id name: 'bookletRootId'
lastUpdated index: 'no'
}
}
When I retrieve instances of this class, the details property is always null, even though there are details instances in the database. My conclusion is that the details field is not being stored in the Lucene index. I tried adding this field to the index without making it a searchable property by adding the following to the searchable closure:
details index: 'no'
However it seems this is only valid for simple properties such as lastUpdated. Is there any way that I can ensure this property is populated when I retrieve instances of Foo from the index? Ideally I would like to do this without actually making details a searchable field?
Well, you can't retrieve an object that is not searchable itself, that's how it works, because you are not really touching the DB with the Searchable plugin. So you have two options:
- Make 'details' searchable (which obviously you don't want to).
Refresh
the objects. The problem is that you have to call refresh() on every single object of the list, and it implies a query to the DB, it's inefficient.
Right now, there are no other solutions to this problem.
I don't think you can do what you are trying to do. Assuming BookletRootDetail has a belongsTo clause (i.e. reference back to the parent), you could index the id, and make a second search query for the details corrsponding to the Foo's id.
You need to make sure that BookletRootDetail is searchable and then in Foo put it as a searchable component.
Something like:
class Foo implements Serializable {
BookletCategory bookletCategory
Date lastUpdated
static hasMany = [details: BookletRootDetail]
static searchable = {
bookletCategory component: true
id name: 'bookletRootId'
lastUpdated index: 'no'
details component: true
}
}
Then
class BookletRootDetail {
static searchable = true
}
You don't need BookletRootDetail to have a belongsTo relation with Foo.
精彩评论