none
KeywordQuery - Not returning Phonetic results RRS feed

  • Question

  • Hello,

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

    • Moved by Wayne Fan Thursday, February 24, 2011 3:38 AM It's FAST Search issue, thanks. (From:SharePoint 2010 - Using Visual Studio with SharePoint and other programming)
    Tuesday, February 22, 2011 4:48 PM

Answers

  • Well - I left it for a week, had some time to come back to it today, and I found a solution!  I found a blog where someone referenced the fact that you need to set the RandingModelId on the KeywordQuery.  This works for the sample code you see above, as well as the custom extended CoreSearchResults webpart I've built.

    Here is the link to the blog that helped me:

    http://blogs.msdn.com/b/jorman/archive/2010/10/06/custom-search-web-parts-in-2010.aspx

    Here is the sample code:

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

    Tuesday, March 1, 2011 4:58 PM

All replies

  • The FAST Query SSA does not do People search. You must pass in the name of the SharePoint Service Application. See if that brings back the same results.
    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    Tuesday, February 22, 2011 6:30 PM
  • Hi Steve,

    Thanks for the response - I believe you are correct -> However, I am not actually querying against the Fast Query SSA. (I'm simply using it to instantiate a SearchServiceApplicationProxy object, but that's because it's my only Search Service application on the server)

    After I created my KeywordQuery object, I set the ResultsProvider to SharePointSearch.  (Instead of FASTSearch)  I've tested both ways, and the only way to get results is to set the ResultsProvider to SharePointSearch.  It's my understanding that FAST will still index the People profiles, however it "hands over" the indexed results to SharePoint, and that's what we query against. Is this understanding incorrect?

    Jason

     

    Tuesday, February 22, 2011 6:50 PM
  • Well - I left it for a week, had some time to come back to it today, and I found a solution!  I found a blog where someone referenced the fact that you need to set the RandingModelId on the KeywordQuery.  This works for the sample code you see above, as well as the custom extended CoreSearchResults webpart I've built.

    Here is the link to the blog that helped me:

    http://blogs.msdn.com/b/jorman/archive/2010/10/06/custom-search-web-parts-in-2010.aspx

    Here is the sample code:

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

    Tuesday, March 1, 2011 4:58 PM
  • Hi Jason,

    I believe your understanding on the people search is correct.

    People search is served from Sharepoint & all the content is indexed under Sharepoint indexes & not FAST.

    So the result provider needs to be SharepointSearch.

    Thanks,

    Ashwani

    Monday, May 16, 2011 11:21 AM