Umair Saleem
Umair Saleem

Reputation: 1063

Grails Searchable Plugin(Lucene) - 1 To Many Query

I am using grail's searchable plugin(0.6.4). I need to search the Members on the basis of privacy settings. Following is the db design. Member has MemberProfile, and MemberProfile has PrivacySettings

class Member extends {
        String firstName
        String lastName
    static searchable = {
        analyzer "simple"
        only = ['firstName', 'lastName']
        firstName boost: 5.0
        profile component: true
        profile reference: true
    }
    static hasOne = [profile: MemberProfile]
}
class MemberProfile {
    static searchable = {
        analyzer "simple"
        only = ['currentCity', 'currentCountry']
        privacySettings component: true
    }

        static hasMany = [privacySettings:PrivacySettings]
    String currentCity
    String currentCountry
    List<PrivacySettings> privacySettings
}
//For instance Privacy Settings contains 
//fieldSectionName: firstName , connectionLevel: true , memberLevel: false
// This means firstName will be shown to only members' friends(connection)
class PrivacySettings {

    static searchable = {
        analyzer "simple"
        only = ['fieldSectionName', 'connectionLevel', 'memberLevel']
    }
    String fieldSectionName
    boolean connectionLevel
    boolean memberLevel
}

One member profile has many privacy settings for each field.

What will be the query to search only those members which have display_name in fieldsSectionName and connectionLevel true in the privacy settings table.

I am trying something like this

def query="mydisplayname"
def searchResults = Member.search(query + "*" + "  +(fieldSectionName:${'display_name'} AND connectionLevel:${true})", params)

Upvotes: 0

Views: 272

Answers (2)

Farouk
Farouk

Reputation: 91

I had the same issue in my grails application, to resolve it add org.apache.lucene.search.BooleanQuery.maxClauseCount = 99999 to your config.groovy and restart your application

Upvotes: 0

Omri
Omri

Reputation: 915

I don't know grail but in Lucene the maximum number of clauses in a boolean query is 1024 by default.

You can increase this limit.

There would be performance penalty, though. or you can index the values on the document and search for them (lucene will do an OR operation on different fields with the same name).

You can change the limit using a static property on BooleanQuery class:

 BooleanQuery.MaxClauseCount = 99999;

Omri

Upvotes: 0

Related Questions