I am using hibernate search(built on top of Lucene). i have indexes created. now if i make a search, does it gets results only from the indexes created? i mean does it also queries the data from database table?
Thanks!
No, you need to create a Lucene Query to run against Hibernates' Search
class like this:
MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_29, searchFields, new KeywordAnalyzer());
org.apache.lucene.search.Query query = parser.parse("Text from entity to search for"); // Or any other valid query
FullTextSession fullTextSession = Search.getFullTextSession(hibernateSession);
org.hibernate.Query hibernateQuery = fullTextSession.createFullTextQuery(query, YOUR_TARGET_ENTITY_HERE.class);
List result = hibernateQuery.list();
I have no idea why they named the Hibernate result class Query
too..
searchFields
is a String[]
containing the list of fields to search.
EDIT: More explanations.
Hibernate Search is like a powerful helper for projects using Hibernate that needs full-text search capabilities. As such, "Hibernate Search" itself won't do searches in the database. It will search only in the indexes. That's the Lucene integration part. The Hibernate integration part is mostly around listeners, that would index the entities as documents every time you do some operation with the entity (saving, updating, removing, ...).
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.