问题
Hello I am reading the standard documentation for grails searcheable plugin at http://grails.org/Searchable+Plugin+-+Mapping+-+Class+Property+Mapping It describes searcheable references and components in that.
In the classic scenario discussed on the page if I have
class News {
static searchable = true
static hasMany = [comments: Comment]
String text
}
and
class Comment {
static searchable = true
String text
}
If I am searching by News.search("a phrase", params)
what do I have to change in this query so that "a phrase" is searched into news as well as comments of news?
回答1:
try to configure comments
as component
:
class News {
static searchable = true
static hasMany = [comments: Comment]
String text
static searchable = {
comments component: [prefix:'comment']
}
}
This allows you to search for a specific comments through News.search("componenttext:phrase", params)
, but afaik, News.search("a phrase", params)
will also search through the comments.
btw: have you already discovered luke? http://code.google.com/p/luke/ This tool will help you a lot while working with the lucene index. For instance, it shows you how lucene sees you grails domain class.
来源:https://stackoverflow.com/questions/12650402/grails-searcheable-plugin-search-in-inner-hasmany-class