Student 1-------* Attendance *---------1 Course
データが
Course.name Attendance.mandatory Student.name
-------------------------------------------------
cooking N Bob
art Y Bob
以下に要約され、以下の構造を有するドメインを照会するためのLuceneを使用しようとしている
"courseName:cooking AND mandatory:Y"
ボブは料理教室に参加しており、ボブも必須コースに参加しているので、ボブを返します。しかし、私は本当には、この場合は誰も返さない "必須の料理コースに参加している学生"です。
これをLuceneクエリとして作成することはできますか?実際にLuceneではなくCompassを直接使用しているので、CompassQueryBuilderまたはLuceneのクエリ言語を使用できます。
完全性のために、ドメインクラスそのものを以下に示します。これらのクラスはGrailsのドメインクラスですが、標準コンパスアノテーションと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
}
おかげで、それは動作しません - 私は "を省略した場合と同じ結果を得ます+記号 –