1

您好,我正在http://grails.org/Searchable+Plugin+-+Mapping+-+Class+Property+Mapping阅读 grails 可搜索插件的标准文档,其中描述了可搜索的引用和组件。

在页面上讨论的经典场景中,如果我有

class News {
    static searchable = true
    static hasMany = [comments: Comment]
    String text
}

class Comment {
    static searchable = true
    String text
}

如果我正在搜索,News.search("a phrase", params)我必须在此查询中进行哪些更改,以便将“短语”搜索到新闻和新闻评论中?

4

1 回答 1

1

尝试配置commentscomponent

class News {
  static searchable = true
  static hasMany = [comments: Comment]
  String text
  static searchable = {
    comments component: [prefix:'comment']
  }
}

这允许您通过 搜索特定评论News.search("componenttext:phrase", params),但 afaikNews.search("a phrase", params)也会搜索评论。

顺便说一句:你已经发现卢克了吗?http://code.google.com/p/luke/这个工具会在你使用 lucene 索引时帮助你很多。例如,它向您展示了 lucene 如何看待您的 grails 域类。

于 2012-09-29T19:42:04.033 回答