I am trying to use Lucene to query a domain that has the following structure
Student 1-------* Attendance *---------1 Course
The data in the area are given below.
Course.name Attendance.mandatory Student.name ------------------------------------------------- cooking N Bob art Y Bob
If I execute the "courseName:cooking AND mandatory:Y" , it returns Bob because Bob is on a cooking course and Bob is also attending a required course. However, what I really want to request is βstudents participating in a compulsory culinary course,β which in this case will not return to anyone.
Can this be formulated as a Lucene query? I actually use Compass, not Lucene directly, so I can use CompassQueryBuilder or the Lucene query language.
For completeness, the domain classes themselves are shown below. These classes are Grails class classes, but I use standard Compass annotations and Lucene query syntax.
@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 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 }
source share