Hibernate 3.6.0, HSearch 3.3.0. I wonder if anyone could clarify if I am right to solve my problem by using ignoreFieldBridge(), when I actually would benefit from the bridging of the fields in question (using my PadNumberBridge).
I have a CategoryEntity which has indexed 'left' and 'right' properties. Other entities hold attributes of type CategoryEntity and index their fields using @IndexedEmbedded, so I have:
Code:
@Entity
class CategoryEntity {
@Column(name="lft")
@Field(name="left", index=Index.UN_TOKENIZED, store=Store.YES)
@FieldBridge(impl=PadNumberBridge.class,
params = { @Parameter(name="pad", value="4") }
)
private int left;
... same for 'right' ...
}
@Entity
class ItemEntity {
@IndexedEmbedded(depth=1)
private CategoryEntity category;
}
This results in each Lucene document for ItemEntity being represented with a "category.left" and "category.right" field. Luke shows an ItemEntity being indexed with, for example,
Quote:
category.left = 0004
category.right = 0012
Until now I've used Hibernate Search query building, with a @FilterDef on the CategoryEntity class allowing me to enable the filter on the FullTextSession and specify the left and right values easily as 'int' parameters. The conversion from 4 to "0004" was done for me.
Now, I'm trying to change my code to use Hibernate Search query DSL and a QueryBuilder to build the same basic query. I find that I have trouble specifying a search for ItemEntity's with specific category.left and category.right values. If I use some naive code like:
Code:
qb.range().onField("category.left").above(searchCat.getLeft()).createQuery())
I get an exception saying it doesn't know what FieldBridge to use for "category.left". I cannot see how to specify a search on a sub-entity's field.
I ran into ignoreFieldBridge(), and tried it thus:
Code:
qb.range().onField("category.left").ignoreFieldBridge().above(searchCat.getLeft()).createQuery())
This does generate a Lucene query, but does not pad the 'left' integer, so I get e.g. "category.left:[4 TO *]" and the search returns no results.
If I pad the number manually and pass the resulting string "0004" to the above() clause of the QueryBuilder, to make "category.left:[0004 TO *]", then the search executes correctly and returns results, however it feels wrong to do this.
So, is there a better way to specify a search on "category.left" of my ItemEntity's? I feel the documentation (5.1.2. Building a Lucene query with the Hibernate Search query DSL) is lacking guidance in this area.
Thanks!
Nick