Search 在Grails应用程序中按查询和位置进行搜索
我在grails应用程序中使用可搜索插件,以以下方式搜索“提供”实例 在提供类中使用以下映射搜索设置Search 在Grails应用程序中按查询和位置进行搜索,search,grails,grails-searchable,Search,Grails,Grails Searchable,我在grails应用程序中使用可搜索插件,以以下方式搜索“提供”实例 在提供类中使用以下映射搜索设置 class Offering { static searchable = { only: ['title', 'description'] } String title String description Category category Location location BigDecimal price
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)
正如预期的那样,这将从提供实例的映射属性返回适当的命中。供品集
我现在要做的不仅仅是通过搜索查询进行搜索,而且还要通过location的子元素进行搜索。特别是子位置实例中的“locationName”字段
因此,如果我通过查询“晚餐”和位置“布里斯班”进行搜索,我希望获得一个与“晚餐”相匹配的产品集合,其中包含一个子位置实例,其“locationName”属性与“布里斯班”相匹配
关于从哪里开始使用searchable插件实现类似的东西,有什么想法吗
位置类
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
}
}
谢谢你的帮助我想你想做的是:
class Offering {
...
static searchable = {
only: ['title', 'description']
location component: true
}
...
}
及
class Location {
...
static searchable = {
only: ['locationName']
location component: true
}
...
}