최대 절전 모드 검색 필터로 부울 로직을 구현하는 데 문제가 있습니다. 그룹에 속할 수있는 사람이 있습니다. 모든 그룹에는 상태 카탈로그의 상태가 있습니다.컬렉션에서 Hibernate Search (Lucene) 필터
그룹 1이고 상태 2 인 모든 사용자를 필터링해야합니다. 두 개의 절에 대해 Occur.MUST와 함께 부울 쿼리를 사용하고 있지만 필터링 된 결과에는 목록이있는 사람이 포함됩니다 grops 그 중 하나가 1이고, 그룹의 상태 중 하나는, 예를 들면 2 :
person | group | status
105 (1) 3
105 2 3
105 3 (2)
188 (1) 3
188 7 (2)
197 (1) 4
197 8 5
197 9 (2)
사용자 (105), (188) 및 (197)는 필터링 된 결과에 포함하지 않았다. 그것을 이루기위한 올바른 방법은 무엇입니까?
필터 :
BooleanQuery bq = new BooleanQuery();
TermQuery tqGroup = new TermQuery(new Term("groupPersons.id.groupId", "1"));
TermQuery tqStatus = new TermQuery(new Term("groupPersons.status.id", "2"));
bq.add(tqGroup, BooleanClause.Occur.MUST);
bq.add(tqStatus, BooleanClause.Occur.MUST);
filter = new QueryWrapperFilter(bq);
사람 개체 :
...
private List<GroupPerson> groupPersons = new ArrayList<GroupPerson>(0);
@IndexedEmbedded
@OneToMany(fetch = FetchType.LAZY, mappedBy = "person")
public List<GroupPerson> getGroupPersons() {
return this.groupPersons;
}
GroupPerson 엔티티 :
...
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "groupId", column = @Column(name = "group_id", nullable = false)),
@AttributeOverride(name = "personId", column = @Column(name = "person_id", nullable = false)) })
@NotNull
@DocumentId
@FieldBridge(impl = GroupPersonIdBridge.class)
public GroupPersonId getId() {
return this.id;
}
...
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "status_id",nullable = false)
@IndexedEmbedded
@NotNull
public Status getStatus() {
return this.Status;
}
OrganizationPersonIdBridge :
public Object get(String name, Document document) {
GroupPersonId id = new GroupPersonId();
Field field = document.getField(name + ".groupId");
id.setGroupId(Long.parseLong(field.stringValue()));
field = document.getField(name + ".personId");
id.setPersonId(Long.parseLong(field.stringValue()));
return id;
}
public String objectToString(Object object) {
GroupPersonId id = (GroupPersonId) object;
StringBuilder sb = new StringBuilder();
sb.append(id.getGroupId())
.append(" ")
.append(id.getPersonId());
return sb.toString();
}
public void set(String name,Object value,Document document,LuceneOptions luceneOptions) {
GroupPersonId id = (GroupPersonId)value;
Store store = luceneOptions.getStore();
Index index = luceneOptions.getIndex();
TermVector termVector = luceneOptions.getTermVector();
Float boost = luceneOptions.getBoost();
//store each property in a unique field
Field field = new Field(name + ".groupId", id.getGroupId() + "", store, index, termVector);
field.setBoost(boost);
document.add(field);
field = new Field(name + ".personId", id.getPersonId() + "", store, index, termVector);
field.setBoost(boost);
document.add(field);
//store the unique string representation in the named field
field = new Field(name,
objectToString(id),
store, index, termVector);
field.setBoost(boost);
document.add(field);
}
최대 절전 모드 검색 버전은 4.5.1입니다. 최종
왜 그런 특정 행동이 필요한지 더 자세히 읽은 후 하디처럼 같은 결론에 도달했습니다. 필자는 다른 솔루션을 사용하여 목록을 매개 변수로 필터에 전달했습니다. 그러나 나는 당신이 제안하고있는 해결책을 더 좋아합니다. 감사! – Tvori