5

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);
    }
}   

3 Answers 3

6

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);
    }
}   
1
  • In SP2013 we have different verticals. The nickname search works on People vertical. But I would want to show the nickname search results on Everything vertical as well. I have till now created a Result block using query rule it do not return nickname results but normal ones. do you have any idea on how to achieve it.?
    – Asad Refai
    Commented Aug 7, 2015 at 9:25
0

What about changing the ResultsProvider value to "FASTSearch"?

1
  • 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/… Commented Feb 25, 2011 at 14:58
0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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