Dec 032010

MOSS 2007 People search influenced by synonym list by user language and setting the rowlimit on a query greater than 50.

This post is an addition to my previous post about SharePoint people search.

While building a custom “CoreResultsWebPart” we noticed that some people were not being returned in our search results by the default search.

 

1) But when we searched it with our custom code it did return results.

2) When a french speaking collegue of mine searched using the same webpart he did get the result, but only when he logged into the machine, not just by signing into my IE Sharepoint.

 

When going to the SharePoint logs I found that the query did the following when I searched for “Leemans”:

 

0x231c0031

Type="Synonym">10x00006c00650065, lee

PID="0x7fff7fff" len="13">0x00006c6d0061006e, leeman

len="19">0x00006c6d0061006e006e0065006e, leemannen

len="15">0x00006c6d0061006e0073, leemans1

Count="3">0x00006d0061006e, man

len="13">0x00006d0061006e006e0065006e, mannen0x00006d0061006e0073,

mans

Type="Unknown0x16777206">... 
So the query automatically (also for out of the box Sharepoint people search!) used synonyms to change my queryterms.

 

After some Reflector work on the “SearchResultHiddenObject” class I found the following:

 

try
                {
                    if (!string.IsNullOrEmpty(this._QueryLanguage))
                    {
                        myRequest.Culture = new CultureInfo(this._QueryLanguage);
                    }
                    else if ((this.thisPage.Request.UserLanguages != null) &&

(this.thisPage.Request.UserLanguages.Length > 0))
                    {
                        myRequest.Culture = new CultureInfo(this.thisPage.Request.UserLanguages[0]);
                    }
                }

 

Which means if the param _QueryLanguage isn’t filled in, it used the users language which explains why my french speaking collegue did get results. The french synonym list wasn’t creating issue’s, nor was the english one, just dutch.

 

By adding the following code to my already custom webpart I could set the parameter and garanty that each user use the same, english synonym list.

+ I added some code so the maximum returned results by a query isn’t limited to 50.

public class xxxwebpart: CoreResultsWebPart

{

....

protected override void SetPropertiesOnHiddenObject()

{

base.SetPropertiesOnHiddenObject();

 

// Get Reflection info

object srho = this.GetType().InvokeMember("srho", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic, null, this, new object[] { });

Type type = srho.GetType();

 

//Set RowLimit

type.InvokeMember("_ResultsRequested", BindingFlags.SetField | BindingFlags.Instance | BindingFlags.NonPublic, null, srho, new object[] { ((short)1000) });

 

//Set Query Culture to en-GB to use this synonym list which causes no problems

type.InvokeMember("QueryLanguage", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.Public, null, srho, new object[] { "en-GB" });

 

// Allow the query to be reissued

type.InvokeMember("ForceRerun", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, srho, new object[] { });

}

 

Seeing as the dutch synonym list was not changed but default, I think we can assume all the out of the box people searches for Dutch users will sometimes give no results because of the synonym use…

 

As a quick fix for users that don’t use a custom CoreSearchResults webpart I’ve created a simple webpart called SearchQueryOptionsWebPart that does 2 things:

 

- Sets the culture for the query so you can determine per page which Culture (read which synonymlist) should be used by all users.

- Sets the rowLimit for the query to return. I’ve noticed that a lot of people are also looking for an easy way to increase this above the hard limit of 50.

 

You can find the sourcecode here.

 

Just install the wsp, activate the site collection feature “MOSS2007 Search Query Options WebPart (SQOW) ” and add the webpart to any search result page where you want to set the options.

The default for the options are “en-GB” and 1000 (rowlimit) but you can change these easily in the webpart properties.

Gr

Tom

Published: 12/3/2010  11:28 AM | 0  Comments | 0  Links to this post

Dec 032010

MOSS 2007 People wildcard search webpart and refine your results.

I’ve been searching for a good way to use wildcard search in combination with people search (SharePoint User Profiles) and have found a few but not 100% what I was looking for.

 

My colleague Steven has found a solution for wildcard search which is pretty much the same as the Codeplex solution and DotNetMaffia solution for this problem.

 

My problem was that these solutions are designed for wildcard content search and not specifically for people search. Normally you’d perform a people search in SharePoint by using the “People Search Core Resuls webpart” which includes some nice people specific features such as:

 

- Refine your search (by example refine by job title)

- Sort by social distance

- …

 

Now all the wildcard search solutions I’ve come across don’t include these features because they all extend the “ CoreResultsWebPart “ instead of the “ PeopleCoreResultsWebpart “ and there is a very good reason for this, being that that class is sealed so you can’t extend it!

 

Now in my case I just need the “refine your search” feature + I only want to search the people scope so I’ve made some adjustments to Steven Van de Craen's original wildcard search solution.

 

By looking at the sealed class from the “ PeopleCoreResultsWebpart “ I found and included the methodes required for the refine feature (CollectRefinementData – SortRefinementDataForColumn – SetSortedRefinementDataOnHiddenObject - GetXPathNavigator). And off course I fixed the scope to only search for people.

So now I have all the functionality I need by simply extending the “CoreResultsWebPart”.

 

You can find an example of the code here as the methods are just too much to post here. Of course you can always Reflector the “PeopleCoreResultsWebPart” if you need any of the other functionality’s, it probably won’t be easy as I haven’t come across someone who reverse engineered the entire webpart.

 

Hope this helps someone out, I’m sure glad I figured it out so I didn’t have to choose between wildcard search or my nice people search functionality's.

 

Gr Tom

Published: 12/3/2010  11:14 AM | 0  Comments | 0  Links to this post