-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate Search 3.2 - Error with @AnalyzerDef / @Analyzer
PostPosted: Mon Feb 07, 2011 2:46 pm 
Newbie

Joined: Mon Feb 07, 2011 2:29 pm
Posts: 3
Hi

I´m having problems with the definition and use of a custom analizer in a entity.
When I set a Analizer in the class definition, then the querys return nothing. And most confusing, it does not display query in debug mode.

I´m using hibernate core 3.3 whith lucene 2.9.

Definition of the class and analyzer
Code:
@Indexed
@AnalyzerDef(name = "anuncioSearchAnalizer",
           tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
                    filters = {
                         @TokenFilterDef(factory = LowerCaseFilterFactory.class),
                         @TokenFilterDef(factory = StopFilterFactory.class, params = {
                                 @Parameter(name="words",      value="resources/stopWords.properties" ),
                                 @Parameter(name="ignoreCase", value="true")
                             })
                     }
         )   

@Analyzer(definition="anuncioSearchAnalizer")
public class AnuncioSearch {
...
}



Querying:
Code:
FullTextSession fullTextSession = Search.getFullTextSession(getSession());
Analyzer analizador =  fullTextSession.getSearchFactory().getAnalyzer(AnuncioSearch.class);
BooleanQuery query = new BooleanQuery();

QueryParser parser = new QueryParser(Version.LUCENE_29, "idioma", analizador);
Query fechaQuery = parser.parse("es");
query.add(fechaQuery, BooleanClause.Occur.MUST);

// wrap Lucene query in a org.hibernate.Query   
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, AnuncioSearch.class);

hibQuery.setMaxResults(201);

return hibQuery.list();



In debug, I check that "analizador" is an org.hibernate.search.util.ScopedAnalyzer with the Filters defined in the class.

If I comment @Analyzer(definition="anuncioSearchAnalizer") then the query works, but it does not aply Filters beacuse it´s using StandarAnalyzer...

Any help would be very apreciate
Thanks


Top
 Profile  
 
 Post subject: Re: Hibernate Search 3.2 - Error with @AnalyzerDef / @Analyzer
PostPosted: Tue Feb 08, 2011 6:32 am 
Hibernate Team
Hibernate Team

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

you need to get the named analyzer and not the analyzer for a given class. Adding an @AnalyzerDef to AnunciaSearch does not mean that it is bound to this class. @AnalyzerDef definitions are global and can be used by any class. You have to do something like this:

Code:
Analyzer analyzer = fullTextSession.getSearchFactory().getAnalyzer("customanalyzer");


Top
 Profile  
 
 Post subject: Re: Hibernate Search 3.2 - Error with @AnalyzerDef / @Analyzer
PostPosted: Tue Feb 08, 2011 7:27 am 
Newbie

Joined: Mon Feb 07, 2011 2:29 pm
Posts: 3
Hi

Thanks for your reply.

I tried this, but it did not work. The stament hibQuery.list() seems do nothing, nor debug logs.

my hibernate.cfg.xml is this:
Code:
<property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property>
<property name="hibernate.search.default.indexBase">d:\Lucene\Indices</property>   

<event type="post-update">
      <listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
   </event>
   
   <event type="post-insert">
      <listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
   </event>
   <event type="post-delete">
      <listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
   </event>



I also tried to create my own analyzer (removing @AnalyzerDef and @Analyzer from the class) and set the property hibernate.search.analyzer but the result is the same. When you recover the Analyzer, it bellow to the proper class, but the query is not executed....

Using StandardAnalyzer does works, but I would like to optimize the search time by using filters and other analyzers.

Every time I change my analyzer, I reindex the table (well, the first 1000 records) in order to ensure the analyzer used during indexation is the same than the used in query.

Code:
                FullTextSession fullTextSession = Search.getFullTextSession(getSession());
      
      //Primero se borran todos los �ndices
      fullTextSession.purgeAll(AnuncioSearch.class);
      fullTextSession.flushToIndexes();
      
      fullTextSession.setFlushMode(FlushMode.MANUAL);
      fullTextSession.setCacheMode(CacheMode.IGNORE);      
      //Scrollable results will avoid loading too many objects in memory
      ScrollableResults anuncios = fullTextSession.createCriteria( AnuncioSearch.class )
               .setFetchSize(BATCH_SIZE)
               .scroll( ScrollMode.FORWARD_ONLY );
      
      int index = 0;
      while(anuncios.next()) {         
          index++;
          fullTextSession.index(anuncios.get(0)) ; //index each element
          if (index % BATCH_SIZE == 0) {
              fullTextSession.flushToIndexes(); //apply changes to indexes
              fullTextSession.clear(); //free memory since the queue is processed
          }
         
          if (index>1000)
          break;
      }
      
      if (anuncios != null)
      anuncios.close();


Thanks again
Regards


Top
 Profile  
 
 Post subject: Re: Hibernate Search 3.2 - Error with @AnalyzerDef / @Analyzer
PostPosted: Tue Feb 08, 2011 8:23 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
If you are talking about the Hibernate query you are looking at in debug mode, then it is not so surprising that there is none. If the Lucene query does not match anything there is no Hibernate query to run. I don't think we are logging the Lucene query at the moment.

Maybe it would help if you post the code for the whole entity, annotations and all. What's in your stop word list? You wouldn't by any chance have 'es' in your stop words?


Top
 Profile  
 
 Post subject: Re: Hibernate Search 3.2 - Error with @AnalyzerDef / @Analyzer
PostPosted: Tue Feb 08, 2011 8:47 am 
Newbie

Joined: Mon Feb 07, 2011 2:29 pm
Posts: 3
Wow, Thank you very much!!!

That was the problem, in my stopFile there was "es", so the query didn´t make sense for lucene.

Again, thanks for your help


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