Full text search in sleep mode

I just created a full text search in sleep mode using hibernate-search-4.1.1.Final.jar and all the execution dependencies. There are no errors in this application. But my Lucene query, not querying the DSL query, does not return any results. I mean, does not return any of the rows in the table. can someone help me.

Main search program This Java code is used to perform full-text search in sleep mode.

public class MainSearch { public static void main(String args[]) { Iterator iterator; Session session = HibernateUtil.getSession(); // FullTextSession fullTextSession = Search.getFullTextSession(session); FullTextSession fullTextSession = Search.getFullTextSession(session); org.hibernate.Transaction tx = fullTextSession.beginTransaction(); // create native Lucene query unsing the query DSL // alternatively you can write the Lucene query using the Lucene query // parser // or the Lucene programmatic API. The Hibernate Search DSL is // recommended though QueryBuilder qb = fullTextSession.getSearchFactory() .buildQueryBuilder().forEntity(Book.class).get(); org.apache.lucene.search.Query query = qb.keyword() .onFields("title", "subtitle", "authors.name").matching("cpp") .createQuery(); // wrap Lucene query in a org.hibernate.Query org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery( query, Book.class); // execute search List result = hibQuery.list(); iterator = result.iterator(); while (iterator.hasNext()) { System.out.print(iterator.next() + " "); } System.out.println(); // Check list empty or not if (result.isEmpty()) { System.out.println("Linked list is empty"); } tx.commit(); session.close(); } } 
+1
source share
1 answer

You have not added anything to the database (in your code). If you did outside of your code, you need to index the database before you can trace it. To do this, do the following:

 FullTextSession fullTextSession = Search.getFullTextSession(session); fullTextSession.createIndexer().startAndWait(); 

And you do not need an open transaction to search for material, so you can delete this line org.hibernate.Transaction tx = fullTextSession.beginTransaction(); (and replace it with startAndWait() above)

Link: http://hibernate.org/search/documentation/getting-started/#indexing (since Lucene does not know about your DBMS and vice versa, Hibernate Search is the relationship between them and indexing your data is what makes it searchable Lucene)

+2
source

Source: https://habr.com/ru/post/1410766/


All Articles