I made some research already about Lucene and its syntax and I'm not sure if my problem is caused by a typo in the syntax. Can you quickly watch at my configurations and tell me if they are correct?
At first 2 entity classes. You can see that the ID of each entity is inherited by VersionableEntity.
VersionableEntity, which is the super class of contact
Code:
@Entity
@Indexed // I tried it with and without this annotation
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class VersionableEntity {
@Id
@DocumentId
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
...
Contact
Code:
import javax.persistence.*;
@Entity
@Indexed
@PrimaryKeyJoinColumn(name = "contactId")
public class Contact extends VersionableEntity {
@Field(index=Index.UN_TOKENIZED)
private String name;
@Field(index=Index.UN_TOKENIZED)
@Column(nullable = false)
private String street;
...
Parts of the properties of my persistence.xml:
Code:
<property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/>
<property name="hibernate.search.default.indexBase" value="/Users/rydl/indexes"/>
<property name="hibernate.ejb.event.post-update" value="org.hibernate.search.event.FullTextIndexEventListener"/>
<property name="hibernate.ejb.event.post-insert" value="org.hibernate.search.event.FullTextIndexEventListener"/>
<property name="hibernate.ejb.event.post-delete" value="org.hibernate.search.event.FullTextIndexEventListener"/>
And my servlet is trying to query like this:
Code:
try {
System.out.println("suche gestartet!");
Session session = ((Session) getEM().getDelegate());
FullTextSession fullTextSession = Search.createFullTextSession(session);
QueryParser parser = new QueryParser("street", new StopAnalyzer()); // also tried it with contact.street as field name
org.apache.lucene.search.Query luceneQuery;
luceneQuery = parser.parse("w*"); // want to see all streets starting with the letter 'w'
org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery);
System.out.println("fulltextquery: " + fullTextQuery.toString());
List result = fullTextQuery.list();
System.out.println("result.size(): " + result.size());
request.setAttribute("resultList", result);
} catch (ParseException e) {
e.printStackTrace();
}
The two outputs are printing:
fulltextquery: FullTextQueryImpl(street:w*)
result.size(): 0
The directory indexes was created and even some subdirectories named like the entities with some files in it were created on my filesystem. I don't know whether there are wrong data indexed or some configuration went wrong or the query is wrong.