Checking active flag in grails searchable query

112 views Asked by At

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 (e.g. 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?

1

There are 1 answers

0
Umair Saleem On

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)