Hi there,
I'm a little bit lost in building the proper query/ resp. index for the following use case:
Code:
@Entity
@Indexed
public class A {
@ManyToOne
@JoinColumn(name = "bb", nullable = false)
@IndexedEmbedded
private B bb;
@Field(index = Index.TOKENIZED)
private String content = "";
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "aa", nullable = false)
@IndexColumn(name = "ccPosition", base = 0)
@BatchSize(size = 100)
@OrderBy
@ContainedIn
private List<C> ccs = new ArrayList<c>();
}
@Entity
@Indexed
public class B {
@Field(index = Index.UN_TOKENIZED)
private int id;
@OneToMany(mappedBy = "bb", cascade = {CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH })
@IndexColumn(name = "aasPosition", base = 0)
@OrderBy
@ContainedIn
private List<A> aas = new ArrayList<A>();
}
@Entity
@Indexed
public class C {
@Field(index = Index.UN_TOKENIZED)
private int id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "aa", insertable = false, updatable = false, nullable = false)
@IndexedEmbedded
private A aa;
}
where I want to search within the field "content" of A and get all matching As but only get the subset of Docs that meet ID's of B and have a C with a given ID. The part where I don't get any further is limiting the search to retrieving only As who have a C with the given ID param2.
So basically something like:
Code:
MultiFieldQueryParser parser = createMultiFieldQueryParser(caseSensitive);
String query = "content:" + searchString + " bb.id:" + param1 + " ccs.id:" + param2;
Query ftq = parser.parse(query.toString());
List<A> aas = entityManager.createFullTextQuery(ftq, A.class).getResultList();
Param1 and param2 are coming from user input dynamically.
Maybe this isn't the proper approach and can be done using another concept like filters and someone can point me out how to search in both directions of relations simultaniously. In the exact use case the accosiations go much deeper and dont stop after ony ManyToOne and one OneToMany relation so I have to travers a lot more like "bb.dd.ee.ff.gg.id" and "ccs.hhs.id".
Thanks in advance.
Alexander