Reputation: 1164
I try to simplify my question, I have class A :
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class A {
@Field
private String a;
....
}
and class B which extends class A:
@Entity
@Indexed
public class B extends A {
@Field
private String b;
....
}
another class C which extends A :
@Entity
@Indexed
public class C extends A {
@Field
private String c;
....
}
My problem is, when I do polymorphic queries like :
Query query = queryBuilder.keyword().onField("a").matching(a).createQuery();
It works very fine, no problem, but when the field is b or c like :
Query query = queryBuilder.keyword().onField("b").matching(b).createQuery();
I have an exception : org.hibernate.search.SearchException: Unable to find field b in C Is there any solution to this, or should I do non polymorphic queries ? May be I have a mistake somewhere. Thanks for helping.
Upvotes: 1
Views: 487
Reputation: 1164
For those having the same problem, use lucene TermQuery :
org.apache.lucene.search.TermQuery termQuery = new TermQuery("field", "term"));
luceneBooleanQuery.add(termQuery, BooleanClause.Occur.MUST);
if a field is numeric (int, double, ...) use lucene NumericRangeQuery :
NumericRangeQuery<Double> numericQuery = NumericRangeQuery.newDoubleRange("numericField", minRange, maxRange, true, true);
luceneBooleanQuery.add(numericQuery, BooleanClause.Occur.MUST);
Upvotes: 0
Reputation: 19129
You are basically hitting a limitation of the query DSL. At the moment it only supports the creation of queries for a single indexed type. See also HSEARCH-1851.
As a workaround you can revert to writing native Lucene queries. Polymorphic queries should work.
If you want to use the DSL you need to create a QueryBuilder
instance for the specific subclass you want to target.
Upvotes: 1