我在grails应用程序中使用可搜索的插件以下列方式搜索“Offering”实例。
在提供类
中使用以下映射搜索设置class Offering {
static searchable = {
only: ['title', 'description']
}
String title
String description
Category category
Location location
BigDecimal price
PricePeriod pricePeriod
static belongsTo = [user: SecUser]
static constraints = {
title(blank: false, maxSize: 100)
description(blank: false, maxSize: 10240)
category(nullable: false)
location(nullable: false)
price(nullable: true, scale: 2)
pricePeriod(nullable: true)
}
public String toString() {
return title
}
}
致电可搜索服务
def search = {
must(queryString(params.query))
}
def searchResult = searchableService.search(search, params)
正如预期的那样,它会从Offering实例的映射属性中返回适当的命中。一系列产品
我现在想做的不仅是搜索查询,还搜索位置的Offerings子元素。特别是子Location实例中的“locationName”字段。
因此,如果我通过查询“晚餐”和位置“布里斯班”进行搜索,我想获得一个与“儿童位置”实例相匹配的“晚餐”产品系列,其中“locationName”属性与“布里斯班”相匹配
有关使用可搜索插件从何处开始实现此类内容的任何想法?
位置等级
class Location {
String locationName
Location locationParent
String postcode
static hasMany = [locations: Location]
static constraints = {
locationName(blank: false, unique: true)
locationParent(nullable: true)
postcode(nullable: true)
}
public String toString() {
return locationName
}
}
感谢您的帮助
答案 0 :(得分:0)
我认为你想做的事情是:
class Offering {
...
static searchable = {
only: ['title', 'description']
location component: true
}
...
}
和
class Location {
...
static searchable = {
only: ['locationName']
location component: true
}
...
}