Hi, I getting this error message and I don't really understand why. I'm new with Hibernate and Hibernate search so I'm kind of lost.
I wanna add a filter to my FullTextQuery but I got this error message :
Quote:
Exception in thread "main" org.hibernate.search.SearchException: Unable to access @Factory method: ca.qc.finances.dib.buzz.dao.hibernate.IssueProjectFilterFactory.getFilter
at org.hibernate.search.query.FullTextQueryImpl.createFilter(FullTextQueryImpl.java:520)
at org.hibernate.search.query.FullTextQueryImpl.buildLuceneFilter(FullTextQueryImpl.java:493)
at org.hibernate.search.query.FullTextQueryImpl.buildFilters(FullTextQueryImpl.java:440)
at org.hibernate.search.query.FullTextQueryImpl.getQueryHits(FullTextQueryImpl.java:402)
at org.hibernate.search.query.FullTextQueryImpl.list(FullTextQueryImpl.java:326)
at ca.qc.finances.dib.buzz.dao.hibernate.IssueDaoHibernate.main(IssueDaoHibernate.java:1075)
Here my filter IssueProjectFilterFactory :
Code:
public class IssueProjectFilterFactory {
private String projectAliasSet;
public void setProjectAliasSet(String projectAliasSet){
this.projectAliasSet = projectAliasSet;
}
@Factory
public Filter getFilter(){
Term term = new Term("project.key", projectAliasSet);
Query query = (Query) new TermQuery(term);
return new CachingWrapperFilter(new QueryWrapperFilter((org.apache.lucene.search.Query) query));
}
@Key
public FilterKey getKey()
{
StandardFilterKey key = new StandardFilterKey();
key.addParameter(projectAliasSet);
return key;
}
}
My Issue class :
Code:
@Entity
@Indexed
@Table(name = "DEMANDE", uniqueConstraints = { @UniqueConstraint(columnNames = { "PRJ_PRJ_ID", "DEM_NUM" }) })
@FullTextFilterDef(name="project", impl=IssueProjectFilterFactory.class)
public class Issue implements Cloneable, Serializable {
@Id
@Column(name = "DEM_ID", nullable = false)
@GeneratedValue(generator = "IssueSeq", strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name = "IssueSeq", sequenceName = "IBOWNER.DEM_SEQ", allocationSize = 1)
private int id;
@IndexedEmbedded
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "PRJ_PRJ_ID", nullable = false)
@NotFound(action = NotFoundAction.IGNORE)
private Project project;
@Field
@Column(name = "DEM_TITRE", length = 255, nullable = false)
private String title;
@Field
@Column(name = "DEM_DESC", length = 4000, nullable = true)
private String description;
...
}
My project class :
Code:
@Entity
@Indexed
@Table(name = "PROJET")
public class Project implements Serializable {
@Id
@Column(name = "PRJ_ID", nullable = false)
@GeneratedValue(generator = "ProjectSeq", strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name = "ProjectSeq", sequenceName = "IBOWNER.PRJ_SEQ", allocationSize = 1)
private int id;
@Field
@Column(name = "PRJ_ALIAS", length = 9, nullable = false, unique = true)
private String key;
...
}
And finally my query code :
Code:
Session session = HibernateUtils.getSession(sid, account);
FullTextSession ftSession = Search.getFullTextSession(session);
ftSession.getTransaction().begin();
List<Issue> issues = session.createQuery("select i from Issue i").list();
for(Issue issue : issues){
ftSession.index(issue);
}
ftSession.getTransaction().commit();
String searchQuery = "title:Ajout OR description:test OR comments.description:test";
org.apache.lucene.search.Query luceneQuery;
QueryParser parser = new QueryParser(org.apache.lucene.util.Version.LUCENE_29,"title",new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_29));
try {
luceneQuery = parser.parse(searchQuery);
}
catch (ParseException e) {
throw new RuntimeException("Unable to parse query: " + searchQuery, e);
}
org.hibernate.search.FullTextQuery query = ftSession.createFullTextQuery(luceneQuery, Issue.class);
query.enableFullTextFilter("project").setParameter("projectAliasSet", "BUZZ");
//Hibernate Core Query APIs
List<Issue> list = query.list();
// Show results
if (list != null) {
for (Issue issue : list) {
log.debug(issue.toString());
}
}
The error is show when this line is execute : List<Issue> list = query.list();
I want to use a filter on the results of the FullTextQuery to keep only the Issue with the project.key = "BUZZ"
Thx for your help !!