How To: Avoid IE language settings affecting MOSS search results

11 בדצמבר 2007

תגיות: ,
8 תגובות

Here’s another SharePoint search classic that instantly became my favorite: IE Language settings in Search Queries.

Recently, one of our customers implemented an internet facing web site and used a search engine. After a week or so in the air, the Q/A team encountered some nasty and unexplained behaviors regarding the Word Breaker that is used for keywords. We’ve investigated this issue some more and found out some “small words” in the MOSS manual: if you index content using one wordbreaker but your client uses another wordbreaker for searching content – the result will be terrible since non of them will be used. In other words: if you index your content in one language but the user is configured to use another language – you’re screwed!

Now, and this is where this becomes interesting: the client configuration is determind by IE (or any other browser) and not the regional settings of the OS. This configuration is also known as the “ACCEPT-LANGUAGE” header of the browser.  SharePoint Search was developed to intelligently capture the browser accept-language header when processing the query and use it to set the user’s language. By the way, this setting is also used in the “Spell Checker” feature in MOSS – it will appear only when the Spell Checker for the client’s language is installed. This means that different clients will see different results (some with Word Breaker and some without) and the Speller will appear in what looks like total randomness. If we need to summarize this weird story: Microsoft had a good idea (giving different languages – different behaviors) but the implementation was “problematic” at best and most of the time will be categorized as a bug and not a feature. Hardly the first time…

So, can we work around it? Is there a way to execute a MOSS search query without taking the IE language settings into account? Well, the quick answer is of course: NO (Damm). However, we were able to bypass it with a nice little trick.

Basically, when a configuration is taken from the browser – it could easily be manipulated via code. This gives us a very simple solution to the IE Language problem. Here’s what you need to do:

  • Create your own search results page (can be done by copying the default)

  • Configure the search to use your new results page.

  • Now, use the new page and code it to set a hard-coded culture – The code should be executed in the page load event. That’s it. Effectively, this will make a unanimous culture for all of the clients in the system and the speller/results will always the same.

Cool Hua?

Adir Ron.


הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

8 תגובות

  1. Martijn11 בפברואר 2008 ב 18:07

    Hi, can you post a sample Page_Load for the new searchresults page?

  2. Sjoert10 במרץ 2008 ב 19:56

    I've tried to get this to work:

    protected override void OnLoad(EventArgs e)
    Page.Culture = "en-US";

    but to no avail. Im using a Core Search Results wp on the page, and it does pick up my browser language, but not the culture override.

    Did you manage to get this to work in a similar setting?

  3. Kent27 בנובמבר 2008 ב 9:57

    We had this problem also, but we cant modify the Page culture because our sites has language resource files.

    The behaviour was very strange. If the users language is the same as the sites locale, the search result was not as expected. If we changed the language in the browser the result was as it should be.

    In our masterpage we set the uiculture to the current web's locale (from regional settings)
    This is the reason why we cant change the page locale. I did test it though, just to see if it had an impact on the result, but it didnt solve the issue.

    Instead i made another approach, lets change the default language on the browser…. well at least in the request object.

    Here's the code, which i put in the preinit event:

    if (Request.UserLanguages != null && Request.UserLanguages.Length > 0)
    Request.UserLanguages[0] = "en-US";

    Voila… all search request returns the same result.

    Hope this helps someone.


  4. peter5 בפברואר 2009 ב 18:25

    Hi, can this be done with javascript that I can include in a content editor webpart? (changing server side code is harder to deploy)

  5. Guido12 בנובמבר 2009 ב 12:52

    Dear Adir

    You saved me – I was going nuts with this problem!

    Regards from switzerland


  6. Rainer3 בדצמבר 2009 ב 17:51

    Thanks Adir!
    Your article finally solved a problem we've been having for months. IE language settings were producing search result differences we couldn't explain until now.


  7. Gert Petersen4 בדצמבר 2009 ב 9:03

    Hi, can anybody show me where to put it in the code, and what to write. I can't get it working.


  8. ceren22 באפריל 2010 ב 14:52

    Hi Adir,

    We try to implement your solution but I need the chunk of code which you mentioned in step 3.

    "The code should be executed in the page load event. That’s it."

    Could you share the code in the page load event please? We are desperately in need of search to be working

    Thanks in advance!