lucene - Hibernate Search: Define dynamically searchable classes -
the code below works fine, need extend back upwards 2 classes (userent , bookent) 40 classes. improve performance, allow user select classes search, meaning classes in method createfulltextquery should declared dynamically depending on selection. possible? otherwise have declare 40 classes in createfulltextquery.
// lucene search string[] fields = {"firstname", "lastname", "name"}; queryparser parser = new multifieldqueryparser( version.lucene_34, fields, new standardanalyzer(version.lucene_34)); org.apache.lucene.search.query lucenequery = null; seek { lucenequery = parser.parse(s); } grab (parseexception e) { throw new runtimeexception("unable parse query: " + s, e); } // hibernate search wrap fulltextentitymanager ftem = search.getfulltextentitymanager(em); javax.persistence.query query = ftem.createfulltextquery(lucenequery, userent.class, bookent.class); list <?> results = query.getresultlist(); system.out.println("records found:"+results.size());
the method createfulltextquery(..) takes first mandatory parameter, , optional varargs parameter list types want search for.
you omit listing types there, have target known indexed entities.
fulltextentitymanager ftem = search.getfulltextentitymanager(em); javax.persistence.query query = ftem.createfulltextquery(lucenequery);
explicitly listing types form of filtering, roll own custom fulltextfilter restrict results on other criteria, , still target known types not need list them.
hibernate lucene hibernate-search
No comments:
Post a Comment