假设我有以下课程。(只包括最重要的东西)
public class Client {
/* Some Properties */
}
public class ClientDocumentAssociation {
@ManyToOne
private Client client;
/* Some Properties */
}
@Indexed
public class Document {
@OneToOne
private ClientDocumentAssociation clientAssociation;
@Field(name = "text")
private String text;
/* Some Properties */
}
我的基本文档搜索是这样的:
public List<AbstractDocument> searchDocuments(String text) {
if (text == null) {
return newArrayList();
}
FullTextEntityManager ftem = Search.getFullTextEntityManager(entityManagerProvider.get());
MultiFieldQueryParser parser = new MultiFieldQueryParser(DOCUMENT_FIELDS, new StandardAnalyzer());
parser.setDefaultOperator(Operator.AND);
FullTextQuery ftq;
try {
Query q = parser.parse(text + "*");
ftq = ftem.createFullTextQuery(q, Document.class);
ftq.setMaxResults(20);
List<AbstractDocument> results = ftq.getResultList();
return results;
} catch (ParseException e) {
e.printStackTrace();
}
return newArrayList();
}
现在,我希望能够搜索文档,但不是在整个索引的范围内,而只是找到属于给定 Client 的文档。我唯一想到的是将关联添加到索引并将客户端 ID 添加到搜索中的相应字段。但这似乎不对。必须有另一种选择,这就是我所要求的。