-->
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.  [ 7 posts ] 
Author Message
 Post subject: ClassBridge and FieldBridge/StringBridge
PostPosted: Wed Jul 04, 2012 10:35 am 
Regular
Regular

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

I would like to use @ClassBridge to index just some fields of an entity. This is an example similar to what i am trying to do:

Code:
@ClassBridge(name="branchnetwork",
             index=Index.TOKENIZED,
             store=Store.YES,
             impl = CatFieldsClassBridge.class,
             analyzer=@Analizer(....)
             params = @Parameter( name="sepChar", value=" " ) )


CatFieldsClassBridge index some string data. My problem is that the data indexed by the bridge is not analyzed by my analyzer and i can see accents in the field with luke app. I have been reading some posts that confirms that this is not working on my hibernate search version (3.4).

http://stackoverflow.com/questions/10118212/using-an-analyzer-within-a-custom-fieldbridge

Is there any way to use an analyzer on a string/FieldBridge? I have been trying to get it from the session but i just couldnt. I also tried passing parameters as the stackoverflow link says....but it didnt work....parameterized only takes strings as params, not objects like analyzer.

I think that this problem is fixed on version 4 of hibernate search. I am using jboss 6.0 and i dont know if this new version works on this version of the server...

thanks in advance!


Top
 Profile  
 
 Post subject: Re: ClassBridge and FieldBridge/StringBridge
PostPosted: Thu Jul 05, 2012 10:25 am 
Hibernate Team
Hibernate Team

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

what is the name of the field you are adding? branchnetwork? The analyzer you are specifying only applies to the field with this name. Hibernate Search cannot (at the moment) determine which fields are getting added document. If you class bridge adds other field names than branchnetwork the default analyzer gets applied.

The problem is that analyzers are getting applied per field name. There is a related discussion on the forum - viewtopic.php?f=9&t=1008943&start=0 There the problem centered around the query DSL, but the underlying problem is the same.

There are a couple of "workarounds" you can apply. Basically you cannot select the right analyzer in the class bridge implementation, but you can do it somewhere else. Unfortunately, this probably violates the DRY principle, but at least it should solve your problem.

  • Write your own custom scoped analyzer and set it as the default analyzer in the configuration. For the fields you are adding in the class bridge you can specify the right analyzers and for the other you can delegate to the default analyzer
  • The alternative is to use @AnalyzerDiscriminator. All you implementation would need to do is to map field names from the bridge to analyzer names (see @AnalyzerDef)

Hope this helps.

--Hardy


Top
 Profile  
 
 Post subject: Re: ClassBridge and FieldBridge/StringBridge
PostPosted: Fri Jul 06, 2012 2:28 am 
Regular
Regular

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

thanks for the response!

I created a custom Analyzer like this one (just in case anyone has the same problem):

Code:
public class CustomAnalyzer extends Analyzer
{
      @Override
      public TokenStream tokenStream(String fieldName, Reader reader) {
         TokenStream result = new StandardTokenizer(Version.LUCENE_31, reader);
          result = new StandardFilter(result);
          result = new LowerCaseFilter(result);
          //result = new StopFilter(result, yourSetOfStopWords);
          result = new ASCIIFoldingFilter(result);
          return result;
      }
}



and i use this analyzer in my bridge as is shown here:

Code:
public class AutoridadComoMateriaBridge implements FieldBridge{

   @Override
   public void set(String name, Object value, Document document, LuceneOptions luceneOptions)
   {
......
Field field = new Field(name, texto, luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector());
            try
            {
      field.setTokenStream(new CustomAnalyzer().reusableTokenStream(name, new StringReader(texto)));
      document.add(field);
   }
}


thanks in advance,


Top
 Profile  
 
 Post subject: Re: ClassBridge and FieldBridge/StringBridge
PostPosted: Sun Apr 14, 2013 11:33 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
So, what I'm doing is using an external set of files containing translation values.
In the ClassBirdge I read these values through a Spring MessageSource, so, e.g.

Key: tag.doctor becomes
en: Docter
pt: Médico
nl: Arts

I write these values as separate fields to the index:
tag_en
tag_pt
tag_nl

So, I actually need to be able to select the analyzer in the bridge so I can apply the correct word stemming etc

Any solution for this? What I'm doing now is basically using an asciifoldingfilter to eliminate all the special characters which delivers an ok result but I need word stemming to allow users to search for Gynaecologist to find Gynaecology. Perhaps there is a way for me to set a predefined analyzer to each field (tag_en, tag_pt etc). Of course, these fields don't exist (I could fake them as Transient fields provided the classbridge executes after the @Field notations execute?). This is not really elegant of course. The cool thing would be to be able to trigger the analyzerdiscriminator somehow within the ClassBridge

Kind regards,
Marc


Top
 Profile  
 
 Post subject: Re: ClassBridge and FieldBridge/StringBridge
PostPosted: Tue Apr 16, 2013 8:56 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Another idea would be to offer something like a SearchFactoryAwareClassBridge. If you had access to the SearchFactory you could access all globally defined analyzers via SeachFactory#getAnalyzer(String). WDYT?

--Hardy


Top
 Profile  
 
 Post subject: Re: ClassBridge and FieldBridge/StringBridge
PostPosted: Wed Apr 17, 2013 9:55 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Sounds good to me. I followed the approach of creating my analyzer in the searchbridge but that's not a very elegant approach and it leaves me wondering if this leads to a performance wise non-optimal result.


Top
 Profile  
 
 Post subject: Re: ClassBridge and FieldBridge/StringBridge
PostPosted: Thu Apr 18, 2013 8:32 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
https://hibernate.atlassian.net/browse/HSEARCH-1306


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