gpt4 book ai didi

在 Grails 应用程序中按查询和位置搜索

转载 作者:行者123 更新时间:2023-12-02 14:54:42 27 4
gpt4 key购买 nike

我在我的 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)

正如预期的那样,这会从产品实例的映射属性中返回适当的命中。供品集合

我现在想做的不仅是通过搜索查询,而且还通过位置的产品子元素进行搜索。特别是子 Location 实例中的“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
}
}

谢谢你的帮助

最佳答案

我认为你想要做的事情是这样的:

class Offering {

...

static searchable = {
only: ['title', 'description']
location component: true
}

...
}


class Location {

...

static searchable = {
only: ['locationName']
location component: true
}

...
}

关于在 Grails 应用程序中按查询和位置搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11394755/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com