samedi 1 novembre 2014

Hibernate Search: Define dynamically searchable classes


Vote count:

0




The code below works fine, however I need to extend it to support from two classes (UserEnt and BookEnt) to 40 classes. To improve performance, I will allow the user to select the classes to search, meaning that the classes in the method createFullTextQuery should be declared dynamically depending on the selection. Is this possible? Otherwise I will have to declare the 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;
try {
luceneQuery = parser.parse(s);
}
catch (ParseException e) {
throw new RuntimeException("Unable to 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());


asked 3 mins ago

ps0604

133






Hibernate Search: Define dynamically searchable classes

Aucun commentaire:

Enregistrer un commentaire