我試圖使用Lucene來查詢具有以下結構Lucene的查詢語法
Student 1-------* Attendance *---------1 Course
域中的數據總結如下
Course.name Attendance.mandatory Student.name
-------------------------------------------------
cooking N Bob
art Y Bob
域如果我執行查詢"courseName:cooking AND mandatory:Y"
它會返回鮑勃,因爲鮑勃正在參加烹飪課程,鮑勃也參加了強制課程。然而,我想要查詢的是「參加強制性烹飪課程的學生」,在這種情況下,這些人將不會返回任何人。
是否有可能將此作爲一個Lucene查詢?我實際上是直接使用Compass而不是Lucene,所以我可以使用CompassQueryBuilder或Lucene的查詢語言。
爲了完整起見,域類本身如下所示。這些類是Grails域類,但我使用標準的Compass註釋和Lucene查詢語法。
@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
}
感謝您的建議,但它不工作 - 我得到了相同的結果時,我省略了「 +「的標誌 – 2009-07-29 19:50:12