2
votes

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?

3
Don, is Jean's 'answer' correct? I'm looking into this as well and I was wondering where you stood on this.Chad Gorshing

3 Answers

1
votes

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:

  1. Make 'details' searchable (which obviously you don't want to).
  2. 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.

0
votes

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.

0
votes

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.