1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / GetContent with all site languages problem

GetContent with all site languages problem

7 posts, 0 answered
  1. Nadya
    Nadya avatar
    52 posts
    Registered:
    17 Dec 2008
    12 Jan 2010
    Link to this post
    Hello Telerik Team!

    I am developing a multilingual web site using Sitefinity 3.7 SP2.
    I am making custom index provider for search and I am having problems with making it index all metafields in all languages of my custom module (which inherits from Generic Content).

    I have the following :

    public IIndexerInfo[] GetContentToIndex() 
            { 
                List<IIndexerInfo> list = new List<IIndexerInfo>(); 
     
                list.AddRange( 
                    GetIndexerInfoListForLanguage("da""da-DK")); 
     
                list.AddRange( 
                    GetIndexerInfoListForLanguage("en""en-US")); 
     
                return list.ToArray(); 
            } 
     
            private List<IIndexerInfo> GetIndexerInfoListForLanguage(string cultureUI, string culture) 
            { 
                CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture; 
                CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; 
     
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(cultureUI); 
                Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(culture); 
                 
                List<IIndexerInfo> listResults = new List<IIndexerInfo>(); 
     
                List<IContent> listContentItems = new List<IContent>(); 
     
                ContentManager cmSecretaries = new ContentManager("Secretaries"); 
                IList listSecretaries = cmSecretaries.GetContent(); 
                foreach (IContent item in listSecretaries) 
                { 
                    listContentItems.Add(item); 
                } 
     
                if (listContentItems != null && listContentItems.Count > 0) 
                { 
                    foreach (IContent item in listContentItems) 
                    { 
                        if (item.Status == ContentStatus.Published) 
                        { 
                            Hashtable metaFields = new Hashtable(); 
                            foreach (string key in this.MetaFields) 
                            { 
                                metaFields.Add(key, string.Empty); 
                            } 
     
                            metaFields["Title"] = item.GetMetaDataValue("Title"); 
                            metaFields["FirstName"] = item.GetMetaDataValue("FirstName"); 
                            metaFields["Surname"] = item.GetMetaData("Surname").ToString(); 
                            metaFields["Position"] = item.GetMetaDataValue("Position"); 
                            metaFields["LawyerDescription"] = item.GetMetaDataValue("LawyerDescription"); 
                            metaFields["Specialties"] = item.GetMetaDataValue("Specialties"); 
                            metaFields["Career"] = item.GetMetaDataValue("Career"); 
                            metaFields["Experience"] = item.GetMetaDataValue("Experience"); 
                            metaFields["PhoneNumber"] = item.GetMetaDataValue("PhoneNumber"); 
                            metaFields["MobilePhoneNumber"] = item.GetMetaDataValue("MobilePhoneNumber"); 
                            metaFields["EmailAddress"] = item.GetMetaDataValue("EmailAddress"); 
                            metaFields["SecretaryDescription"] = item.GetMetaDataValue("SecretaryDescription"); 
     
                            string urlDetails = string.Format("~/{0}{1}?EmployeeID={2}"
                                Thread.CurrentThread.CurrentUICulture.ToString(), s_EmployeesPageUrl, item.ID); 
     
                            listResults.Add( 
                                        new CustomIndexerInfo( 
                                            urlDetails, 
                                            metaFields, 
                                            string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11}"
                                                            metaFields["Title"].ToString(), 
                                                            metaFields["FirstName"].ToString(), 
                                                            metaFields["Surname"].ToString(), 
                                                            metaFields["Position"].ToString(), 
                                                            metaFields["LawyerDescription"].ToString(), 
                                                            metaFields["Specialties"].ToString(), 
                                                            metaFields["Career"].ToString(), 
                                                            metaFields["Experience"].ToString(), 
                                                            metaFields["PhoneNumber"].ToString(), 
                                                            metaFields["MobilePhoneNumber"].ToString(), 
                                                            metaFields["EmailAddress"].ToString(), 
                                                            metaFields["SecretaryDescription"].ToString() 
                                                         ) 
                                            ) 
                                    ); 
                        } 
                    } 
                } 
     
                Thread.CurrentThread.CurrentUICulture = currentUICulture; 
                Thread.CurrentThread.CurrentCulture = currentCulture; 
     
                return listResults; 
            } 


    Strange thing is that when I am using manager.GetContent() it is returning correct items considering current culture.When I use GetMetaData () of the items that have two language versions (I can see that in their Languages array there're two items) the result is always the same. No matter what is the current culture. And more - the version of metafield is the version of language that is the value of Language property of the IContent Item. And this is always the first language I change the culture with. I tried changing the Language property but it is returning to this language by it self (I cannon find any good explanation  for this reviewing methods in reflector).
    I tried using manager.GetContentWithLanguage(item.ID). The result IContent Item does have the Language of the current culture (correct), but does not have any meta data.

    I am very confused and I need help ASAP.


    Thank you!
    Cheers, Nadya
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    12 Jan 2010
    Link to this post
    Hi Nadya,

    Can you please check if your metafields have localizable attribute set to True? This should be done in the web.config:

    <add key="Module.Field"
     valueType="ShortText"
     visible="False"
     searchable="False"
     sortable="False"
     defaultValue="True"
     localizable="True"/>

    Default is false (if it is not present). This will force Sitefinity to use one value for all cultures, or to read the default culture's value.

    Best wishes,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Nadya
    Nadya avatar
    52 posts
    Registered:
    17 Dec 2008
    12 Jan 2010
    Link to this post
    Hi Georgi,

    Yes, I have  "localizable = true " for each of my meta fields. 
    I also have :
     
    <localization defaultProvider="Sitefinity" persistenceMode="PathPrefix" autoSetClientLanguage="false" allowSpecificCultures="true" defaultCulture="da" cultures="da, en"
     

    and

    <add name="Secretaries" urlRewriteFormat="[Name].aspx" urlWhitespaceChar="_" visible="False" defaultMetaField="Name" securityProviderName="" allowVersioning="True" allowLocalization="True" applicationName="/Secretaries" versioningProviderName="" commentsModeration="true" connectionStringName="GenericContentConnection" type="Telerik.Cms.Engine.Data.Providers.DefaultProvider, Telerik.Cms.Engine.Data"/> 



    In fact the multiple languages (in my case "en" and "da") are working. And I am getting it correct after first change of current culture. I am doing this because I know that GetContent is getting only the items that have language version same as  current culture's language.

    I did this for other projects but this is the first time I am changing the culture twice in a row and it is just not working.

    Can you, please help?

    Best,
    Nadya
  4. Nadya
    Nadya avatar
    52 posts
    Registered:
    17 Dec 2008
    12 Jan 2010
    Link to this post
    Hi Georgi,

    Sorry I missed,  the GetMetaDataValue() is a extension to get empty string if there's no metadata:

    public static class IContentExtensions 
        { 
            public static string GetMetaDataValue(this IContent content, string key) 
            { 
                return content.GetMetaData(key) != null ? content.GetMetaData(key).ToString() : string.Empty; 
            } 
        } 

    Thanks, 
    Nadya
  5. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    14 Jan 2010
    Link to this post
    Hello Nadya,

    Thank you for getting back to us with the additional information.

    Does your CustomIndexerInfo class inherit from Telerik.Cms.Engine.ContentIndexerInfo if yes in that case can you try to use this constructor when adding new items to the list of items (constructor coming from base class):
    //here culture is of type CultureInfo and sets the desired culture
    listResults.Add(new ContentIndexerInfo(urlDetails, item, metaFields, culture));

    You could also create another constructor for your custom class whish will set the culture property of your class.

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Nadya
    Nadya avatar
    52 posts
    Registered:
    17 Dec 2008
    15 Jan 2010
    Link to this post

    Hi Georgi,
    thanks for your help. It appears that my class does not inherit from Telerik.Cms.Engine.ContentIndexerInfo . It just implements Telerik.Framework.Search.IIndexerInfo .  This is from this example I saw.
    Anyway, the way I managed to fix it was adding:

    CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture;  
                CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;  
     
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(currentUI);  
                Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(culture);  
                  
                List<IIndexerInfo> listResults = new List<IIndexerInfo>();  
     
                List<IContent> listContentItems = new List<IContent>();  
     
                ContentManager cmSecretaries = new ContentManager("Secretaries");  
                IList listSecretaries = cmSecretaries.GetContent();  
                foreach (IContent item in listSecretaries)  
                {  
                    if (cultureUI.Equals("en", StringComparison.OrdinalIgnoreCase))  
                    {  
                        item.Language = "en";  
                    }  
     
                    listContentItems.Add(item);  
                } 

    ...
     So setting explicitly the Language properrty at this place worked.

    But I belive this should be reported as bug. GetContent() method is supposed to take all Content Items with current culture and it is obviously not. If you watch the item in their Languages array there are all languages they have content in. But the Language property is not changing considering current culture - GetContent() should take items and set their Language property to the correct language from current culture.

    It will be great if you have time to fix this.

    Regards, 
    Nadya 
  7. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Jan 2010
    Link to this post
    Hello Nadya,

    Thank you for the follow up.

    We are happy to hear that you have managed to resolve the issue. We will definitely run tests on the GetContent method and observe the results if we find issues with it they will be fixed.

    Just a side note. The IIndexInfo class also has an interface get method Culture which has to be implemented.

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
7 posts, 0 answered