0

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?

4

1 回答 1

0

尝试以下,我没有测试它。希望它能解决问题。

def finalQuery = "name:${myQuery}* OR surname:${myQuery}* -(active:false)";
def searchResults = Person.search(finalQuery , params)
于 2013-09-11T08:03:26.677 回答