Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I cannot seem to get a custom keyword query to return phonetic results when searching for people.

I have FAST search installed, and if I do a people search (in the FAST search center) for "Jon", I get the expected results containing both "Jon" and "John". However, if I construct a keyword query (as shown below) I only return the results for "Jon".

Any suggestions?

using (SPSite spSite = new SPSite("http://localhost"))
{   
    // get the query and settings service proxy
    SearchQueryAndSiteSettingsServiceProxy settingsProxy = spSite.WebApplication.Farm.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();
    // get the search service application proxy by name
    SearchServiceApplicationProxy proxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>("FAST Query SSA");

    KeywordQuery keywordQuery = new KeywordQuery(proxy);
    keywordQuery.RowLimit = 100;
    keywordQuery.EnablePhonetic = true;
    keywordQuery.EnableNicknames = true;
    keywordQuery.ResultsProvider = SearchProvider.SharepointSearch;

    keywordQuery.ResultTypes = ResultType.RelevantResults;

    keywordQuery.SelectProperties.Add("firstname");
    keywordQuery.SelectProperties.Add("lastname");

    keywordQuery.QueryText = "jon";

    ResultTableCollection fullTextSearchResults = keywordQuery.Execute();

    if (fullTextSearchResults.Exists(ResultType.RelevantResults))
    {               
        ResultTable searchResult = fullTextSearchResults[ResultType.RelevantResults];
        Console.WriteLine("Total Rows: " + searchResult.TotalRows) ;
        Console.WriteLine("Total Row Count: " + searchResult.RowCount);
        Console.WriteLine("Total Rows Including Duplicates: " + searchResult.TotalRowsIncludingDuplicates);
        Console.WriteLine("Is Total Rows Exact: " + searchResult.IsTotalRowsExact);
    }
}   
share|improve this question

3 Answers 3

For anyone trying to do this through a web service the element you'll need is named RelevanceModel instead of RankingModelId

I was stuck trying to get it to work through jQuery and SPServices until I found the Microsoft.Search.Query Schema reference and discovered the element name is RelevanceModel when doing Web Service calls. The reference doesn't mention EnableNicknames or EnablePhonetic, but I found they were also needed to get this to work.

Here's the XML query I ended up with:

<QueryPacket Revision="1000">'
    <Query>
        <Context>
            <QueryText language="en-US" type="STRING">Jon scope:"People" </QueryText>
        </Context>
        <SupportedFormats Format="urn:Microsoft.Search.Response.Document.Document" />
        <ResultProvider>SharepointSearch</ResultProvider>
        <EnableNicknames>true</EnableNicknames>
        <EnablePhonetic>true</EnablePhonetic>
        <RelevanceModel>d9bfb1a1-9036-4627-83b2-bbd9983ac8a1</RelevanceModel>
        <Properties>
            ...
            <Property name="FirstName" />
            <Property name="LastName" />
        </Properties>
    </Query>
</QueryPacket>
share|improve this answer
up vote 5 down vote accepted

I found a blog where someone referenced the fact that you need to set the RankingModelId on the KeywordQuery. This works for the sample code you see above, as well as the custom extended CoreSearchResults web part I've built.

Here is the sample code:

using (SPSite spSite = new SPSite("http://localhost"))
{   
    SearchQueryAndSiteSettingsServiceProxy settingsProxy = spSite.WebApplication.Farm.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();
    SearchServiceApplicationProxy proxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>("FAST Query SSA");

    KeywordQuery keywordQuery = new KeywordQuery(proxy);
    keywordQuery.RowLimit = 100;
    keywordQuery.EnablePhonetic = true;
    keywordQuery.EnableNicknames = true;
    keywordQuery.ResultsProvider = SearchProvider.SharepointSearch;

    keywordQuery.RankingModelId = "D9BFB1A1-9036-4627-83B2-BBD9983AC8A1";       

    keywordQuery.ResultTypes = ResultType.RelevantResults;

    keywordQuery.SelectProperties.Add("firstname");
    keywordQuery.SelectProperties.Add("lastname");

    keywordQuery.QueryText = "jon";

    ResultTableCollection fullTextSearchResults = keywordQuery.Execute();

    if (fullTextSearchResults.Exists(ResultType.RelevantResults))
    {               
        ResultTable searchResult = fullTextSearchResults[ResultType.RelevantResults];
        Console.WriteLine("Total Rows: " + searchResult.TotalRows) ;
        Console.WriteLine("Total Row Count: " + searchResult.RowCount);
        Console.WriteLine("Total Rows Including Duplicates: " + searchResult.TotalRowsIncludingDuplicates);
        Console.WriteLine("Is Total Rows Exact: " + searchResult.IsTotalRowsExact);
    }
}   
share|improve this answer

What about changing the ResultsProvider value to "FASTSearch"?

share|improve this answer
2  
Unfortunately no - Although we are using FAST Search as our Search Service Application, the FAST Query SSA contains an instance of SharePoint Server search that handles People Search. (taken from the link below). If you set the ResultsProvider to FASTSearch, there are no results returned. social.technet.microsoft.com/wiki/contents/articles/… –  Jason Rastovski Feb 25 '11 at 14:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.