lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Donal Murtagh <domur...@yahoo.co.uk>
Subject Re: Querying across object relationships
Date Thu, 30 Jul 2009 14:10:34 GMT
Hi Phil,

I don't really have any query parsing/generation code to send you, because I'm not using Lucene
directly. I'm using the Grails Searchable Plugin,
which builds on both Lucene and Compass. The only relevant information
I can give you is my Grails domain classes which show how I've mapped
my classes to the Lucene search index.

@Searchable
class Student {

    @SearchableProperty(accessor = 'property')
    String name
    
    static hasMany = [attendances: Attendance]

    @SearchableId(accessor = 'property')
    Long id

    @SearchableComponent
    Set<Attendance> getAttendances() {
        return attendances
    }
}

@Searchable(root = false)
class Attendance {

    static searchable = true
    static belongsTo = [student: Student, course: Course]

    @SearchableProperty(accessor = 'property')
    String mandatory = "Y"

    @SearchableId(accessor = 'property')
    Long id

    @SearchableComponent
    Course getCourse() {
        return course
    }
} 

@Searchable(root = false)
class Course {

    @SearchableProperty(accessor = 'property', name = "courseName")
    String name  

    @SearchableId(accessor = 'property')
    Long id
}

In order to execute a search I simply provide a Lucene query string such as "+courseName:cooking
AND +mandatory:Y"

Cheers,
Don


      
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message