Grails searcheble don't use field during fulltext search

105 views Asked by At

Domain (just simple example):

class House {
String address
String region
Long price
static searchable = { only = ['address', 'price', 'region'] }
} 

I want to search by address with price selector

Search query is:

"${address} AND price: [100 TO 1000]"

But if address='500' in search result will be Houses with price 500. I need to find house for address only by House.address + House.region

1

There are 1 answers

0
Rafael On BEST ANSWER

If I understood, you want to use the value of ${address} to query only on the address and region attributes.

In that case, based on the "complex" query string example at http://grails.org/Searchable+Plugin+-+Searching+-+String+Queries, your query string could be:

"+(address:${address} OR region:${address}) price:[100 TO 1000]"

  • Matches must have a ${address} value for address or a ${address} value for region, and have a value from 100 to 1000 for price.

Note: your input variable has the same name of an entity attribute, "address", wich can cause some confusion when trying to understand query strings using them both. Though not needed, you might want to change that, for easier readable query strings.