Hi,
I am using Hibernate Search + Hibernate 3 with JPA and I have a strange problem.
When I do indexing, I can see index files being created but they are blank. The luke also shows nothing in these files. Hence the search is also not working. Can anyone please help me regarding this.
My persistence.xml file:
Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="defaultManager"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.driver_class"
value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url"
value="jdbc:mysql://localhost:3306/hibernatetest" ></property>
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password"
value="root" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.search.default.directory_provider"
value="org.hibernate.search.store.FSDirectoryProvider" />
<property name="hibernate.search.indexing_strategy" value="manual" />
<property name="hibernate.search.default.indexBase" value="e:\indexes" />
</properties>
</persistence-unit>
</persistence>
The EO calss is simpple
Code:
@Indexed
@Entity
@Table(name="book")
/*@AnalyzerDef(name = "customanalyzer",
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = SnowballPorterFilterFactory.class,
params = {
@Parameter(name = "language", value = "English")
})
})*/
public class BookEO {
@DocumentId
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Field(index=Index.TOKENIZED)
//@Analyzer(definition = "customanalyzer")
private String title;
@Field(index=Index.TOKENIZED)
//@Analyzer(definition = "customanalyzer")
private String subtitle;
@IndexedEmbedded
@ManyToMany
private Set<AuthorEO> authors = new HashSet<AuthorEO>();
@Field(index = Index.UN_TOKENIZED)
@DateBridge(resolution = Resolution.DAY)
private Date publicationDate;
//getter and setters
And the code doing search is follows:
Code:
EntityManager em = HibernateEntitymanagerHelper.getEntityManagerFactory().createEntityManager();
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
fullTextEntityManager.getTransaction().begin();
List<BookEO> books = em.createQuery("select book from BookEO as book").getResultList();
for (BookEO book : books) {
fullTextEntityManager.index(book);
}
// fullTextEntityManager.getSearchFactory().optimize(BookEO.class);
//System.out.println("Done optimise123!!!!!!!!!");
//fullTextEntityManager.getTransaction().commit();
//fullTextEntityManager.getTransaction().begin();
/*
String[] fields = new String[]{"title", "subtitle"};
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
// parser.setDefaultOperator(QueryParser.AND_OPERATOR);
org.apache.lucene.search.Query query = parser.parse( "hibernate" );
// wrap Lucene query in a javax.persistence.Query
javax.persistence.Query persistenceQuery = fullTextEntityManager.createFullTextQuery(query, BookEO.class);
// execute search
List<BookEO> result = persistenceQuery.getResultList();
System.out.println("result ::"+result);
for (BookEO book : result) {
System.out.println("Book ::"+book.getTitle());
}
fullTextEntityManager.getTransaction().commit();
em.close();
HibernateEntitymanagerHelper.shutdown();