-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Unable to access @Factory method
PostPosted: Tue Aug 24, 2010 1:41 pm 
Newbie

Joined: Tue Aug 24, 2010 11:12 am
Posts: 7
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 !!


Top
 Profile  
 
 Post subject: Re: Unable to access @Factory method
PostPosted: Wed Aug 25, 2010 5:20 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I think the factory method gets actually called. What happens is that an InvocationTargetException gets thrown. Unfortunately, the code swallows the actual target exception and does just print out the message you see. Maybe you could debug the code and see what exception is wrapped in the InvocationTargetException.

Out of interest - why do you need the casts in your Filter? The code should work without any casts.

--Hardy


Top
 Profile  
 
 Post subject: Re: Unable to access @Factory method
PostPosted: Fri Aug 27, 2010 10:15 am 
Newbie

Joined: Tue Aug 24, 2010 11:12 am
Posts: 7
Thx a lot. In fact the problem was with the Query in the getFilter(). One was an org.hibernate.Query and the other an org.apache.lucene.search.Query.


Top
 Profile  
 
 Post subject: Re: Unable to access @Factory method
PostPosted: Fri Aug 27, 2010 1:55 pm 
Newbie

Joined: Tue Aug 24, 2010 11:12 am
Posts: 7
Ok, now the filter seem to work but query.list returns nothing.

In the FullTextQueryImpl.getQueryHits(Sercher, Integer) the object queryHits got the right filter and the right preparedQuery but the hits numbers is 0.

Without the filter the query works very well.

Do you have any ideas where the problem can be ?


Top
 Profile  
 
 Post subject: Re: Unable to access @Factory method
PostPosted: Sat Aug 28, 2010 4:12 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Are you sure the filter condition is correct. Have you inspected the index with Luke? If you add your filter condition as additional query parameter (instead of using a filter) do you get a result then?

--Hardy


Top
 Profile  
 
 Post subject: Re: Unable to access @Factory method
PostPosted: Mon Aug 30, 2010 12:05 pm 
Newbie

Joined: Tue Aug 24, 2010 11:12 am
Posts: 7
My index are set and works. I got the result wanted when I add my filter condition to the query. So the problem must be in the filter object.

Like you can see up here, used the exact pattern show in Hibernate Search in Action at the page 258 in the listing 8.4.


Top
 Profile  
 
 Post subject: Re: Unable to access @Factory method
PostPosted: Mon Aug 30, 2010 3:29 pm 
Newbie

Joined: Tue Aug 24, 2010 11:12 am
Posts: 7
Everything works. I fact, if I write "BUZZ" in the setParameter(String name, Object val) for the value nothing is return. But if I write "buzz" I got the good result.

So how can I set hibernate to not be case-sensitive ???


Top
 Profile  
 
 Post subject: Re: Unable to access @Factory method
PostPosted: Tue Aug 31, 2010 5:05 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
This depends, mainly which and how you use analyzers. In case you haven't I recommend you read up on the topic of analyzers within Lucene. Per default the so called StandardAnalyzer is used, which will lowercase all tokens during indexing. Normally when you are using a query parser the same analysis steps will be applied to your query as to your indexed text, meaning your query terms will be lowercased.
In your case you are constructing a TermQuery which is pretty the lowest level. The assumptions on this level is that any required analysis of the search term has already occurred. The term you specify will be searched for in the index as is. If you want analysis applied on your term you have to use a QueryParser. Keeping this in mind you have to decide what the best solution is for your filter. Often you will look for specific term like "buzz" (lowercase)


Top
 Profile  
 
 Post subject: Re: Unable to access @Factory method
PostPosted: Tue Aug 31, 2010 9:48 am 
Newbie

Joined: Tue Aug 24, 2010 11:12 am
Posts: 7
Thx a lot guys ! Now everything working fine. I own you a beer for the time I save because of you !!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.