lucene - index unrelated entities in same index with hibernate search -
in our domain model using aggregates quite aggressively, ie don't connect classes through jpa-relations rather use services can query related objects. so, lets have 2 example classes, person , workplace related reference rather direct object-relation.
public class person { int id; string name; } public class workplace { int id; string name; list<int> personid; }
now build hibernate search index should index fields both person , workplace. possible though hibernate search or have handroll our own lucene-indexer , take care of maintenance hibernate search performs on index ourself?
are there other solutions should consider?
using hibernate search can make index containing both, or can have 2 indexes 1 each entity query them single index.
@indexed @entity public class person { int id; @field string name; } @indexed @entity public class workplace { int id; @field string name; list<int> personid; }
you can use index find matching persons and/or workplace instances.
org.apache.lucene.search.query q = ...[a standard lucene query] fulltextquery fulltextquery = fulltextsession.createfulltextquery( q, person.class ); list<person> list = fulltextquery.list();
or targetting both types:
fulltextquery fulltextquery = fulltextsession.createfulltextquery( q, person.class, workspace.class ); list list = fulltextquery.list();
or indexed types:
fulltextquery fulltextquery = fulltextsession.createfulltextquery( q ); list list = fulltextquery.list();
Comments
Post a Comment