I am using the searchable plugin in my grails application to search for "Offering" instances in the following way.
Search setup with following mapping in Offering class
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
}
}
Call to searchable service
def search = {
must(queryString(params.query))
}
def searchResult = searchableService.search(search, params)
As expected this returns appropriate hits from the mapped properties of Offering instances. A collection of offerings
What I would like to do now is search not only by the search query but also the Offerings child element of location. Specifically the "locationName" field within the child Location instance.
So if I search by query "dinner" and location "Brisbane" I would like to get a collection of offerings matching "dinner" with a child location instance with the "locationName" property matching "Brisbane"
Any ideas on where to start to implement something like this using the searchable plugin?
Location class
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
}
}
Thanks for your help