How to get the document id from PropertyBinder?

Hello,

In Hibernate Search 5 inside the FieldBridge custom implementation I had access to Lucene document and was able to access it’s fields. Now, I Hibernate Search 6 I can’t see how to access the document fields from my PropertyBinder custom implementation.

Any tip?

Thanks in advance.

Hi,

You can’t access the fields produced by other bridges/@*Field annotations, and that’s on purpose, to ensure perfect isolation between the bridges; otherwise we’d run into problems internally.

As to the identifier… No, there is no way to retrieve it at the moment, though we could consider adding API for that.

In the meantime, if you apply your binder to a property of the root entity (the one annotated with @Indexed), you could turn your PropertyBinder into a TypeBinder, and apply it to the entity type instead of the property. Then your bridge would get passed the whole entity as a parameter, and you would be able to retrieve the entity identifier.

Maybe I could provide more useful suggestions if you explained a bit more about your use case?

Ok, I will try the TypeBinder option.

My use case is a bit special: this field data is not stored in database but in disk because it can be a huge text and storing in database has performance issues. And the file name is the same as the Entity id.

Thanks!

Ah, in that case yes, it definitely makes sense to use either a PropertyBinder applied to the identifier property, or a TypeBinder applied to the entity type (if you need more than just the entity identifier).