2

I can't seem to get the very basic FieldBridge implementation to work. It looks as if the indexing process is ignoring @FieldBridge annotation completely.

Here's the implementation:

public class LocalisedInformationBridge implements FieldBridge {

    @Override
    public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {

        luceneOptions.addFieldToDocument(name + ".test", "test", document);

    }   
}

Entity with the @FieldBridge annotation:

@OneToMany(mappedBy = "product")
@MapKey(name = "languageCode")
@IndexedEmbedded
@FieldBridge(impl = LocalisedInformationBridge.class)
private Map<String, LocalisedProductInformation> localisedProductInformation;

Contained entity:

@ManyToOne
@JoinColumn(name="productId")
@ContainedIn
private Product product;

When I try to search on localisedProductInformation.test field, I'm getting exception:

org.hibernate.search.exception.SearchException: Unable to find field localisedProductInformation.test

Here's how I'm indexing data:

FullTextEntityManager fullTextEntityManager =
        Search.getFullTextEntityManager(entityManager);
fullTextEntityManager.createIndexer().startAndWait();

The weird thing is when I put a breakpoint on set method of LocalisedInformationBridge class, debugger doesn't stop the execution of the program. Is there something very obvious that I'm missing here?

tomz
  • 341
  • 3
  • 14
  • Are you sure is in the path and being loaded? Do something silly like a default constructor that prints a message. This way you'd know that is being loaded at least – bichito Jan 19 '17 at 17:37
  • The log says that all entities have been reindexed and when I print a message from constructor, I can see it for all entities... – tomz Jan 19 '17 at 17:51
  • How does the container know that your implementation is for that index? – bichito Jan 19 '17 at 18:23

1 Answers1

0

One thing to know is, when you use @IndexedEmbedded on a container property (array, collection or map), any field bridge defined in a @Field annotation will be applied to elements of this property's value. So in your case, the field bridge will be applied to the map's values, not to the map itself. If your map is empty, the field bridge won't be applied at all. Is this your case?

This behavior is admittedly a bit strange (given that @IndexedEmbedded has a slightly different purpose), but it's been introduced a while ago and fixing it would lead to regressions for users relying on it. So, until a new major version is released, this is likely to stay that way...

yrodiere
  • 9,280
  • 1
  • 13
  • 35
  • Yes, that was the case and when I removed the IndexedEmbedded annotations, this started to work properly. I'm just wondering if IndexedEmbedded annotation is needed for ContainedIn annotation to work on the other side of relationship, or could that be used on its own? – tomz Jan 20 '17 at 12:14
  • @fuudge The `@IndexedEmbedded` annotation isn't required for the `@ContainedIn` annotation to work. You should be alright without it, assuming you use your own field bridge. – yrodiere Jan 23 '17 at 11:09