-->
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.  [ 6 posts ] 
Author Message
 Post subject: Indexing and Searching with different analyzers
PostPosted: Thu Jul 14, 2011 11:24 am 
Newbie

Joined: Thu Jul 14, 2011 11:14 am
Posts: 3
Hello, I'm new at the forum. I have to questions about this topic:

1.- Is there a simple way to index a list of entities using an specific analyzer with Hibernate Search? (different from the one specified at entity level)
2.- Can I create a QueryBuilder for an specific entity and using a specific analyzer? Using something like
Code:
queryBuilder.withAnalyzer(Analyzer)


Thanks in advance!
Regards,
Mariano.


Top
 Profile  
 
 Post subject: Re: Indexing and Searching with different analyzers
PostPosted: Thu Jul 14, 2011 12:07 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hello, welcome.

Quote:
1.- Is there a simple way to index a list of entities using an specific analyzer with Hibernate Search? (different from the one specified at entity level)

Yes: http://docs.jboss.org/hibernate/stable/ ... e/#d0e3385
Quote:
Can I create a QueryBuilder for an specific entity and using a specific analyzer?

Yes, see the second code example:
http://docs.jboss.org/hibernate/stable/ ... e/#d0e3385

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Indexing and Searching with different analyzers
PostPosted: Thu Jul 14, 2011 4:45 pm 
Newbie

Joined: Thu Jul 14, 2011 11:14 am
Posts: 3
Thank you for your response!

In relation with the second question, I was wondering If there is something like this or similar(using DSL):

Code:
QueryBuilder builder = ftSession.getSearchFactory().buildQueryBuilder()
            .forEntity( Empresa.class ).withAnalyzer(Analyzer).get();


As I read, the only way to override the "deafult" analyzer is using the overridesForField method. Is there something similar to the overridesForField method but at class level?

What I'm trying to do is the following:

I have an Empresa entity which I need to be indexed with a custom analyzer that for example doesn't have the SynonymFilter. But when I'm searching I want to use the other Analyzer (both at Entity level) that has the SynonymFilter. Is there a way to implement it without specifying each of the fields to override and using DSL?


Top
 Profile  
 
 Post subject: Re: Indexing and Searching with different analyzers
PostPosted: Fri Jul 15, 2011 5:36 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
ah, now I understand what you're trying to do. No I don't think there is one: would this be useful? I'm wondering, since when you're defining the query you still need to list the fields.
Can you post a better example to explain the use case?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Indexing and Searching with different analyzers
PostPosted: Fri Jul 15, 2011 7:49 am 
Newbie

Joined: Thu Jul 14, 2011 11:14 am
Posts: 3
Ok, this is part of the code when searching (the variable 'textoBusqueda' is the String that the user searched and 'fields' is an String[] with the indexed fields.):

Code:
         FullTextSession ftSession = getSesionBusqueda();
         Transaction tx = ftSession.beginTransaction();
       
         // creo el constructor de consultas DSL
         final QueryBuilder builder = ftSession.getSearchFactory().buildQueryBuilder()
            .forEntity( Empresa.class ).get();
      
         // creo la consulta de hibernate
         MustJunction query = builder.bool().must(builder.keyword().onField(ConstantesDTO.TABLA_EMPRESA_ESTADO).
                                 matching(EstadoEmpresa.PUBLICADA).createQuery());

                       //buscando el texto ingresado
                    if (StringUtils.isNotBlank(textoBusqueda)) {
                      query.must(builder.keyword().onFields(fields).matching(textoBusqueda).createQuery());
                    }

                         //creo busqueda con hibernate serarch para trar los resultados
                    hibQuery = ftSession.createFullTextQuery(query.createQuery(), Empresa.class);
                    hibQuery.initializeObjectsWith(ObjectLookupMethod.SECOND_LEVEL_CACHE, DatabaseRetrievalMethod.QUERY);

                        resultado.getEmpresas().addAll(hibQuery.list());



I tried to reduce the code in order to show only the query part.


Top
 Profile  
 
 Post subject: Re: Indexing and Searching with different analyzers
PostPosted: Fri Jul 15, 2011 9:17 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
thanks, almost clear now :)

Could you please open a JIRA request for this? https://hibernate.onjira.com/browse/HSEARCH

Also it doesn't seem hard: if you want to contribute it that would be nice.

_________________
Sanne
http://in.relation.to/


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