Hi everybody,
My problem is quite simple but I have no idea where it comes from.
I am running Hibernate Search within Seam.
here is the code I am running:
Code:
Session session = ((FullTextHibernateSessionProxy)entityManager.getDelegate()).getSessionFactory().getCurrentSession();
Criteria searchFilter = session.createCriteria(Request.class);
LuceneBuilder builder = new LuceneBuilder(searchFilter,Request.class,
"title","shortDescription","addendum");
Query q = builder.getQuery(entityManager,query);
if(from > 0) q.setFirstResult(from);
if(max > 0) q.setMaxResults(max);
return q.getResultList();
Where LuceneBuilder does this:
Code:
public Query getQuery(FullTextEntityManager em,String searchText) throws ParseException{
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields.toArray(new String[0]),new StandardAnalyzer());
org.apache.lucene.search.Query q = parser.parse(searchText);
FullTextQuery query = em.createFullTextQuery(q, cls);
if(criteria != null) query.setCriteriaQuery(criteria);
return query;
}
When I try it, it doesn't work.
If I make my criteria null (and then it doesn't set a criteria for the query) it does return a result.
What I don't understand is that the criteria doesn't use any criterion at all, so it shouldn't do a thing. But it doesn't ....
Does someone have any idea why?
Thank you very much in advance.
Here is the Request Class if it can help:
Code:
package com.marroon.webapp.request.model;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.hibernate.search.annotations.Store;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.NotNull;
import com.marroon.webapp.admin.model.User;
import com.marroon.webapp.common.model.Category;
import com.marroon.webapp.common.model.Location;
@Entity
@Indexed
@Analyzer
public class Request implements Serializable{
/**
*
*/
private static final long serialVersionUID = 3195217010000585539L;
private Long id;
private User client;
private Set<Discussion> discussions;
private Category category;
private String title;
private String shortDescription;
private String addendum;
private Double budget;
private Date creationDate;
private Date lastModificationDate;
private Date deadline;
private Location location;
private String answer;
private boolean closed;
private boolean archived;
@Field(store=Store.NO,index=Index.NO)
public boolean isClosed() {
return closed;
}
public void setClosed(boolean closed) {
this.closed = closed;
}
public boolean isArchived() {
return archived;
}
public void setArchived(boolean archived) {
this.archived = archived;
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@DocumentId
public Long getId() {
return id;
}
public Double getBudget(){
return this.budget;
}
@ManyToOne(targetEntity=User.class)
public User getClient() {
return client;
}
@ManyToOne(targetEntity=Category.class)
public Category getCategory() {
return category;
}
@NotNull @NotEmpty
@Field(index=Index.TOKENIZED,store=Store.NO)
public String getTitle() {
return title;
}
@NotNull @NotEmpty
@Length(max=2000)
@Field(index=Index.TOKENIZED,store=Store.NO)
public String getShortDescription() {
return shortDescription;
}
@ManyToOne(targetEntity=Location.class)
public Location getLocation(){
return location;
}
@Field(index=Index.TOKENIZED,store=Store.NO)
public String getAddendum() {
return addendum;
}
public Date getCreationDate() {
return creationDate;
}
public Date getLastModificationDate() {
return lastModificationDate;
}
@OneToMany(mappedBy="request",fetch=FetchType.EAGER,cascade=CascadeType.ALL)
public Set<Discussion> getDiscussions() {
return discussions;
}
public Date getDeadline(){
return deadline;
}
/* SET METHODS */
public void setId(Long id) {
this.id = id;
}
public void setClient(User client) {
this.client = client;
}
public void setCategory(Category category) {
this.category = category;
}
public void setTitle(String title) {
this.title = title;
}
public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}
public void setAddendum(String addendum) {
this.addendum = addendum;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public void setLastModificationDate(Date lastModificationDate) {
this.lastModificationDate = lastModificationDate;
}
public void setDiscussions(Set<Discussion> discussions) {
this.discussions = discussions;
}
public void setLocation(Location location){
this.location = location;
}
public void setBudget(Double budget){
this.budget = budget;
}
public void setDeadline(Date deadline){
this.deadline = deadline;
}
public Request(){}
public Request(User client, Category category,String title, String shortDescription,Double budget,Date deadline, String addendum){
this.client = client;
this.category = category;
this.title = title;
this.shortDescription = shortDescription;
this.addendum = addendum;
this.creationDate = new Date();
this.lastModificationDate = new Date();
this.budget = budget;
this.deadline = deadline;
this.closed = false;
this.archived = false;
}
@Transient
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
@Override
public String toString() {
return getTitle();
}
}