OK, so I've been trying to implement a hibernate search, and am having a lot of trouble. Here's some code snippets:
From the persistence.xml:
Code:
<property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/>
<property name="hibernate.search.default.indexBase" value="/var/lucene/indexes"/>
From my services class, for indexing in Lucene:
Code:
public void indexQuestions()
{
EntityManager em = entityManagerFactory.createEntityManager();
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
List<Questions> questions = em.createQuery("SELECT question FROM Questions AS question").getResultList();
for (Questions question : questions)
{
fullTextEntityManager.index(question);
}
em.getTransaction().commit();
em.close();
}
For the actual search:
Code:
public List<Questions> getQuestions(Questions toBeMatched)
{
EntityManager em = entityManagerFactory.createEntityManager();
FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
em.getTransaction().begin();
String[] fields = new String[]{"questionText"};
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
try{
org.apache.lucene.search.Query query = parser.parse(toBeMatched.getQuestiontext());
javax.persistence.Query persistenceQuery = fullTextEntityManager.createFullTextQuery(query, Questions.class);
List<Questions> result = persistenceQuery.getResultList();
em.getTransaction().commit();
em.close();
return result;
}
catch(ParseException p){}
return null;
}
When I try to start up my application, I get a ParseException from Lucene. What's really bizarre is that it happens before I call any methods that have anything to do with Lucene. I'm thinking maybe my annotations in the entity POJO aren't right, but I'm not sure...Thoughts?? Thanks.
Sol