java - Why Hibernate Search is slow? Even with few records -
i have project uses jsf 2, spring, jpa 2 , hibernate search 4.5.0. project simple hibernate search giving me trouble.
the part use hibernate search indexing oracle view. view, if run simple select count(*) my_view
gives me 5756 records, not much.
well, first thing did, entity mapping jpa / hibernate search:
@entity @indexed @table(name = "my_view") public class person implements serializable { private static final long serialversionuid = 244555315052436669l; @id @column(name = "id", insertable = false, updatable = false) private long id; @field(store = store.no, index = index.yes, analyze = analyze.yes) @column(name = "name", insertable = false, updatable = false) private string name; @field(store = store.no, index = index.yes, analyze = analyze.yes) @column(name = "email", insertable = false, updatable = false) private string email; @field(store = store.no, index = index.yes, analyze = analyze.yes) @column(name = "user", insertable = false, updatable = false) private string user; @field(store = store.yes, index = index.yes, analyze = analyze.yes) @column(name = "phone", insertable = false, updatable = false) private string phone; //getters , setters ommited }
after mapping entity, build cronjob index entity. take method use index entity.
public void index() throws daoexception { fulltextentitymanager fulltextentitymanager = search.getfulltextentitymanager(this.entitymanager); try { fulltextentitymanager.createindexer(person.class) .purgeallonstart(boolean.true) .optimizeonfinish(boolean.true) .startandwait(); } catch (interruptedexception e) { logger.error("error creating index", e); throw new daoexception(e); } }
and, after indexing entity, can search on many columns 1 keyword. the problem when try search without keyword! application has return records. thought, using hibernate search, search extremely fast. mistake!
the search takes more 40 seconds return! here how search without term:
fulltextentitymanager fulltextem = search.getfulltextentitymanager(this.entitymanager); querybuilder qb = fulltextem.getsearchfactory().buildquerybuilder().forentity(person.class).get(); fulltextquery fulltextquery = fulltextem.createfulltextquery(qb.all().createquery()); sort sortfield = new sort(new sortfield("name", sortfield.string)); fulltextquery.setsort(sortfield); return fulltextquery.getresultlist();
the query execution extremely fast (as searching without keyword efficient), next step of execution load results in memory database , loading 5000+ elements database never going fast, unless caching of entities , queries.
if need load everything, that's not full-text query better performed standard relational query. whatever query type -unless use projections- might want investigate loading strategies model causing. can significant boost adjusting fetch strategies of relation, and/or enabling second level caching.
Comments
Post a Comment