Hi,
Let's say I have following classes. (only most important things included)
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 */
}
My basic document search is like this:
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();
}
Now, I want to be able to search for documents, but not in the scope of the whole index, but just find documents that belong to given Client. The only thing that comes to my mind is adding the association to the index and add client id to the appropriate field in search. But that does not seem right. There must be another option and that's what I am asking for.