简体   繁体   中英

Grails searcheble don't use field during fulltext search

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM