-->
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.  [ 3 posts ] 
Author Message
 Post subject: How can i apply an analyzer to a query?
PostPosted: Thu Sep 15, 2011 9:00 am 
Regular
Regular

Joined: Thu Jun 16, 2011 12:03 pm
Posts: 94
I have the next method:

Code:
public List<ExampleEntity> searchTerm(String q, String field) {
   TermQuery tQuery = new TermQuery(new Term(field, q));
   return Search.getFullTextSession(session)
      .createFullTextQuery(tQuery, ExampleEntity.class)
      .list();
}



I would like to use an analyzer that i have defined before...

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: How can i apply an analyzer to a query?
PostPosted: Fri Sep 16, 2011 8:02 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

a term query does not apply an analyzer. If you use a term query the specified terms are searched as you specify them. If you want to use term queries and you want to apply an analyzer yourself you have to do multiple things. First you have to get hold of an analyzer via SearchFactory#getAnaLyzer and then you need some sort of utility class similar to org.hibernate.search.test.util.AnalyzerUtils.
Or why do you not just use a QueryParser or the Hibernate Search DSL which will also apply the analyzer.

--Hardy


Top
 Profile  
 
 Post subject: Re: How can i apply an analyzer to a query?
PostPosted: Mon Sep 19, 2011 5:38 am 
Regular
Regular

Joined: Thu Jun 16, 2011 12:03 pm
Posts: 94
Hi,

Thank you for your response...

I was just trying to understand how to use QueryParser and it was easier than i thought at the first moment :)

Code:
        fields = new String[2];
        fields[0] = "title.title_filter";
        fields[1] = "autority.autority_filter";

            MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_31,
                                                                     fields,
                                                                     Search.getFullTextSession(session).getSearchFactory().getAnalyzer("myAnalizer"));
           
            //parser.setDefaultOperator(Operator.OR);
           
            org.apache.lucene.search.Query query = parser.parse(q);

            System.out.println("Multifield query:" + query.toString());
           
            return Search.getFullTextSession(session)
            .createFullTextQuery(query, MyEntity.class)
            .list();



Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.