Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7071497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:41:42+00:00 2026-05-28T05:41:42+00:00

My Grails app is using the searchable plugin, which builds on Compass and Lucene

  • 0

My Grails app is using the searchable plugin, which builds on Compass and Lucene to provide search functionality. I have two searchable classes, say Author and Book. I have mapped these classes to the search index, so that only certain fields can be searched.

To perform a search across both classes I simply call

def results = searchableService.search(query)

One of the nice features of doing the search across both class simultaneously, is that the results object includes metadata about number of results included, number of results available, pagination details etc.

I recently added a boolean approved flag to the Book class and I never want unapproved books to appear in the search results. One option is to replace the call above with:

def bookResults = Book.search(query + " approved:1")
def authorResults = Author.search(query)

However, I now need to figure out how to combine the metadata for both results, which is likely to be tricky (particularly pagination).

Is there a way to search across Book and Author with a single query, but only return approved books?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:41:42+00:00Added an answer on May 28, 2026 at 5:41 am

    I’ve created a test app and came to the following solution. maybe it helps…

    if the property approved only has the states 0 and 1, the following query will work:

    def results = searchableService.search(
        "(${query} AND approved:1) OR (${query} -approved:0 -approved:1)"
    )
    

    I guess this can be reformulated in a better way if you don’t use the QueryParser but the BooleanQueryBuilder.

    BTW: if you add a method like

    String getType() { "Book" }
    

    and

    String getType() { "Author" }
    

    To your domains, you can even configure your search to do it like this

    def results = searchableService.search(
        "(${query} AND approved:1) OR (${query} AND type:Author)"
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're developing an app (using Grails Spring Security (formerly Acegi)) in which we'll have
In my Grails app, I'm using the Searchable plugin for searching/indexing. I want to
I have secured my Grails app using the ACEGI plugin and am using annotations
I have a grails app that is using jsecurity plugin for authentication. How do
I have a Grails 2.0.0 project that was created using grails create-app . In
I am using the joda-time grails plugin in my grails app to deal with
All, I am trying to test my grails app using Hudson. I have in
I am using the spring-security-core plugin in my grails app. I need to know
I have a grails app, and I am using the java-apns 0.1.5 jar! I
I'm writing a web app using grails and spring-security 3.0.3 which requires me to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.