Grails searchable插件

时间:2009-12-10 23:21:45

标签: grails lucene grails-plugin compass-lucene

在我的Grails应用程序中,我有以下由Searchable插件索引的域类:

class Foo implements Serializable {

    BookletCategory bookletCategory
    Date lastUpdated
    static hasMany = [details: BookletRootDetail]

    static searchable = {
        bookletCategory component: true
        id name: 'bookletRootId'
        lastUpdated index: 'no'
    }
}

当我检索此类的实例时,即使数据库中有详细信息实例,details属性也始终为null。我的结论是详细信息字段没有存储在Lucene索引中。我尝试通过将以下内容添加到可搜索的闭包中,将此字段添加到索引而不使其成为可搜索的属性:

details index: 'no'

然而,它似乎只适用于简单属性,例如lastUpdated。当我从索引中检索Foo的实例时,有什么方法可以确保填充此属性?理想情况下,我希望这样做而不会将细节变成可搜索的字段?

3 个答案:

答案 0 :(得分:1)

好吧,你无法检索一个本身无法搜索的对象,这就是它的工作方式,因为你并没有真正触及可搜索插件的数据库。所以你有两个选择:

  1. 使'详细信息'可搜索(显然你不想这样)。
  2. Refresh对象。问题是你必须在列表的每个对象上调用refresh(),这意味着对数据库的查询,这是低效的。
  3. 目前,没有其他解决方案可以解决这个问题。

答案 1 :(得分:0)

我认为你不能做你想做的事。假设BookletRootDetail有一个belongsTo子句(即引用回父项),你可以索引id,并对与Foo的id相对应的细节进行第二次搜索查询。

答案 2 :(得分:0)

您需要确保BookletRootDetail是可搜索的,然后在Foo中将其作为可搜索的组件。

类似的东西:

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
    }
}

然后

class BookletRootDetail {
  static searchable = true
}

您不需要BookletRootDetail与Foo拥有belongsTo关系。