假設我有以下類。 (僅包括最重要的事情)休眠搜索 - 在給定範圍內搜索
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();
}
現在,我希望能夠搜索文檔,而不是在整個索引的範圍,但只需查找屬於給定客戶的文檔。我唯一想到的是將關聯添加到索引中,並將客戶端ID添加到搜索中的相應字段。但這看起來不正確。必須有另一種選擇,這就是我所要求的。
嗯,我認爲對某些值使用索引是不合適的(例如,對某些布爾數據進行過濾看起來不正確)+給出的示例是簡化的,真實的關聯更加複雜 - 因此我想以其他方式過濾結果。 – 2010-02-26 10:55:57
嗯...我做了一些研究,我認爲你是對的,標準不是最好的方式來做到這一點。我會去索引其他值。謝謝。 – 2010-02-26 13:36:03