-->
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: Analyzer and i18n
PostPosted: Tue Jun 23, 2009 6:29 pm 
Newbie

Joined: Sat Jan 03, 2009 6:33 pm
Posts: 11
Hi,

1. I'm a complete HSearch/Lucene beginner.
2. I have read both Hibernate in Action (2sd Ed) and Hibernate Search in action, searched the forums, but found (almost) nothing...
3. Versions of Hibernate are the latest (since it's a new project)

I'm in the process of creating a data model with some fields in several languages. For example :

Code:
class Product
{
    @Column(
        name = "description",
        nullable = false
    )
    @JoinTable(joinColumns = @JoinColumn(name = "productId"))
    @org.hibernate.annotations.CollectionOfElements(fetch = FetchType.EAGER)
    @org.hibernate.annotations.ForeignKey(name = "products_key")
    @org.hibernate.annotations.MapKey(
        columns =
            @Column(
                length = 2,
                name = "locale"
            )
    )
    private Map<String, String> descriptions = new Hashtable<String, String>();
}


"descriptions" is a map with the key being the locale and the value the description in that locale, eg {{"en","my product"}, {"fr","mon produit"}}.
So far so good, but now the problem is indexing each description with the right analyzer, ie for the language used for the current row.

1. I found on this forum a thread mentioning "AnalyzerDiscriminator", but it seems it cannot be applied to a Map, does it?
2. I'm thinking to convert Map<Locale,String> to List<I15nData> (I15nData being a simple structure with a locale and a description fields) and applying "AnalyzerDiscriminator" to I15nData.

Please can someone give me some input on this?
Thanks

David


Top
 Profile  
 
 Post subject: Re: Analyzer and i18n
PostPosted: Fri Jun 26, 2009 3:17 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
1. I found on this forum a thread mentioning "AnalyzerDiscriminator", but it seems it cannot be applied to a Map, does it?

You can apply an AnalyzerDiscriminator on every kind of field, but in this case you'll get only one Analyzer for the indexing of the whole Map; of course that's not what you need.

Quote:
2. I'm thinking to convert Map<Locale,String> to List<I15nData> (I15nData being a simple structure with a locale and a description fields) and applying "AnalyzerDiscriminator" to I15nData.

that's not going to work, the Analyzer being used at index time is selected by the field name, using an @IndexedEmbedded collection you're basically appending all information in the same field, but you need to keep the information for each language in separate fields if you want them to use different Analyzers..

You will need a @ClassBridge, so you can define new fields dynamically from the Locale,String value of each entity.

Did you consider how you are going to query this? If it's allowed to search on more than one language in one query you might want to avoid having multiple Analyzers: the user query has to be analyzed with one Analyzer, consistent with the one used for indexing the data you want to match.

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


Top
 Profile  
 
 Post subject: Re: Analyzer and i18n
PostPosted: Fri Jun 26, 2009 3:52 am 
Hibernate Team
Hibernate Team

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

I guess your approach could work depending of course how you design I15nData.
Another approach could be to use a FieldBridge for the description map together with a Lucene PerFieldAnalyzerWrapper. If you for example want to index the description for each language into a separate field, eg description_en, description_de, etc, then you can define the appropriate analyzers for these fields names in the wrapper. Then in your custom FieldBridge indexing the map you just have make sure to create the right field names depending on the locale.

--Hardy


Top
 Profile  
 
 Post subject: Re: Analyzer and i18n
PostPosted: Fri Jun 26, 2009 4:44 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
right I jumped to the @ClassBridge, but the @FieldBridge Hardy is describing should be a better approach.

Still let me know how you are going to write the queries, you will have to consider the different named fields at Query definition.

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


Top
 Profile  
 
 Post subject: Re: Analyzer and i18n
PostPosted: Mon Jun 29, 2009 6:07 pm 
Newbie

Joined: Sat Jan 03, 2009 6:33 pm
Posts: 11
Thanks for our answers !
That's a lot to process for a newbie. I guess I didn't start with the easiest part...

@s.grinovero :
1. each query will be for a single language
2. i don't understand why I have to use @IndexedEmbedded on the map ?

@hardy.ferentschik :
1. well, I was refering to your post :) the only one talkingt about AnalyzerDiscriminator in the forum
https://forum.hibernate.org/viewtopic.php?f=9&t=996099&p=2410221&hilit=AnalyzerDiscriminator#p2410221
2. I'll (re)read the related parts of the doc and the book, and certainly come back to you :)


Top
 Profile  
 
 Post subject: Re: Analyzer and i18n
PostPosted: Tue Jun 30, 2009 10:34 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
2. i don't understand why I have to use @IndexedEmbedded on the map ?

you don't need IndexedEmbedded; it was needed to map the collection as you were trying to do in the first post.
IndexedEmbedded is used to include in the index of this entity the fields from the related objects,
in this case you might annotate fields of the I15nData class so to get those fields included in the index of your root
entity.
This will however generate multiple copies of the same-named field, so you don't need the IndexedEmbedded
but a FieldBridge to be able to customize the field name for each I15nData instance.

_________________
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.