I would like to build search query for Grails Searchable Plugin, which will return me only active objects. (Will not return objects with 'activate' flag set false). This is my situation.
I have one Abstract class, and some classes, which extend abstract class (eg Person):
class AbstractObject{
boolean active;
DateTime createDate
}
class Person extends AbstractObject{
String name;
String surname;
static searchable=[only:['name','surname','active']]
}
And when I delete object i set 'active' flag to false.
Before I was using
searchableService.search(myQuery, defaultOperator:"or", max: 10)
but it returns object which are inactive, so I decided to try with Query Builder:
def result=searchableService.search({
must(queryString(myQuery))
must(term('active',false))
}, defaultOperator:"or", max: 10)
Unforunately it returns nothing. Do you have any idea what am I doing wrong? How my code should look like?
Try following, I didn't test it. Hope it will resolve the issue.
def finalQuery = "name:${myQuery}* OR surname:${myQuery}* -(active:false)";
def searchResults = Person.search(finalQuery , params)
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.