0

I am using the Searchable plugin's query builder to try and build a query that searches some content and only returns objects that the user is the audience of or the audience is global. The code I would like to have would be similar to:

{
  term("content", content)
  or {
    term('reach', 'global')
    term('audience$user', User)
  }
}

But there is no 'or' for this, how do I say that I want one of my field to have a term AND have one of two other conditions met with the searchable's query builder DSL?

This seems like a dumb question, but I've been searching for quite a while and can't find an answer.

mfollett
  • 1,814
  • 15
  • 27

2 Answers2

2

I would use the grammar of the searchable plugin:

search("+content:${content} +(reach:global OR audience.user.id:${user.id})")

Not sure what you meant with 'audience$user' though.

Look here for details: http://grails.org/Searchable+Plugin+-+Searching+-+String+Queries http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Boolean%20operators

fixitagain
  • 6,543
  • 3
  • 20
  • 24
  • Yeah, I've used that approach before, I was trying the other approach this time but it looks like I might fall back to the string search. – mfollett Sep 24 '11 at 17:14
  • I ended up just going with this in the end, so I'll accept it as the answer. – mfollett Oct 12 '11 at 16:31
0

This is a very late answer, but the correct way with the builder would be

{
   must(term("content", content))
   must {
      term('reach', 'global')
      term('audience$user', User)
   }
}

apart from that I'm also not sure what you mean with audience$user.
See http://grails.1312388.n4.nabble.com/Searchable-plugin-s-query-builder-nested-or-query-td1388307.html

peron
  • 2,939
  • 1
  • 15
  • 6