Reputation: 11870
I have a Hibernate Search entity class that looks something like this:
@Entity
@Indexed
@FullTextFilterDefs({
@FullTextFilterDef(name="myFilter", impl=MyFilterFactory.class)
})
public class Parent {
...
@Column
@Field
private String name;
@ManyToMany
@IndexedEmbedded
private Set<Child> children;
...
}
The associated enity is likewise straightforward:
@Entity
@Indexed
public class Child {
...
@Column
@Field
private String name;
@ManyToMany(mappedBy="children")
@ContainedIn
private Set<Parent> parents;
...
}
If the MyFilterFactory.getFilter()
method is working with a simple field of Parent
like this (hardcoded for easier illustration):
...
Term term = new Term("name", "daddy");
Query query = new TermQuery(term);
return new CachingWrapperFilter( new QueryWrapperFilter(query) );
...
... then FullTextQuery
's with this filter enabled work as expected.
However, if I change the filter to use a field of an embedded field:
...
Term term = new Term("children.name", "Junior");
Query query = new TermQuery(term);
return new CachingWrapperFilter( new QueryWrapperFilter(query) );
...
... then I get 0 hits every time, despite the fact that the search expression children.name:parent=junior
works just fine in Luke.
Is there something I am missing here? Obviously the information is there since I can search it in Luke. Is there something special you have to do with Hibernate Search to implement a FullTextFilter
against an embedded field like this, rather than a simple field?
Upvotes: 0
Views: 990
Reputation: 11870
While putting together a simple unit test with which to submit a bug ticket, I discovered the real issue. The problem is not a matter of simple fields vs. complex fields. The problem was a frustratingly-silly misunderstanding about capitalization.
Normally when Hibernate Search builds a Lucene index, the standard analyzer converts all the field values to lower-case. When you mostly use the Hibernate Search DSL for queries, you get accustomed to case-insensitivity. However, when you query using the Lucene API directly, you are responsible for making your search terms lower-case to match the index.
The behavior that I originally saw was due to the case of my search terms. When I filtered on a simple field, I happened to be using an all-lowercase string. When I filtered on a complex field, I happened to be using a string with a capital letter.
After making sure that the filter parameter is converted to lower-case, the problem was resolved.
Upvotes: 1