简体   繁体   中英

How does Hibernate Search flatten entites for Lucene

I want to put millions of entities into Solr for querying by their fields (like range-searches, sorting, grouping etc).

However, the entities I have are not flat. They have relationships like Employee has Company, Person has Address, Cart has List etc. (Note all these are entities or Data-Objects and cannot be put into Solr directly).

I came across Hibernate Search which builds a Lucene index from non-flat entities. If someone can point me to the code where it does that, it would be great.

I know this is doable since Elasticsearch is also doing this. But since moving away from Solr might be expensive bet for me, I want to try flattening the entities, either by myself or using HibernateSearch APIs

Hibernate Search adds the entity associations as part of the root entity. Say there is a Person with an association to Address via an address property. Address has a street and city property. The Lucene Document for a Person instance will then also contain a field address.street and address.city . To enable this embedded indexing you will need to annotate the address property with @IndexedEmbedded . See also the online docs of Search - http://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#search-mapping-associated

Technically Hibernate Search keeps the required meta information of the indexed properties (including the associations) for an entity and on an entity change event (or a change of the association) rebuilds the document/index.

Is this what you were after?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM