1

So I have two Console Search which I am testing out the usage of SharePoint Search Models via visual studio 2013.

I encountered an issue where EnablePhonetic and EnableNicknames does not really work within the Server Object Model but works perfectly fine for Client Object model.

The following is my Client Object Model:

        static void Main(string[] args)
                {
                    using (ClientContext clientContext = new ClientContext("http://portal.conium.com/sites/TestView/"))
                    {
                        Guid PeopleSearch= new Guid("b09a7990-05ea-4af9-81ef-edfab16c4e31");// this is the default people search source id

                        KeywordQuery keywordQuery = new KeywordQuery(clientContext);
                        keywordQuery.SourceId = PeopleSearch;
                        keywordQuery.EnableNicknames = true;
                        keywordQuery.EnablePhonetic = true; 
                        keywordQuery.RankingModelId = "D9BFB1A1-9036-4627-83B2-BBD9983AC8A1";//Default sharepoint People ranking model
                        keywordQuery.TrimDuplicates = false;
                        keywordQuery.QueryText = "Sps";
        SearchExecutor searchExecutor = new SearchExecutor(clientContext);


                        ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
                        clientContext.ExecuteQuery();

                            foreach (var resultRow in results.Value[0].ResultRows)
                            {Console.WriteLine("Path" + " : {0}", resultRow["Path"].ToString());}

It always returns all Sps users' mysite paths.

(Content,Search,Services,sites,mysite,farm) --> which is all I had made.

However in Server Object Model... it is inconsistent and returns results similarly or returns nothing. This is the code:

static void Main(string[] args)
            {
                Guid PeopleSearch = new Guid("b09a7990-05ea-4af9-81ef-edfab16c4e31");
    using(SPSite site = new SPSite("http://portal.conium.com/sites/testSearch"))
                {
     KeywordQuery keywordQuery = new KeywordQuery(site);
                        keywordQuery.SourceId = PeopleSearch;
                        keywordQuery.EnableNicknames = true;
                        keywordQuery.EnablePhonetic = true;
                        keywordQuery.RankingModelId = "D9BFB1A1-9036-4627-83B2-BBD9983AC8A1";
                        keywordQuery.TrimDuplicates = false;
                        keywordQuery.QueryText = "Sps";
    SearchExecutor searchExecutor = new SearchExecutor();
                        ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);
                        var resultTables = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);
                        var resultTable = resultTables.FirstOrDefault();
    DataTable dataTable = resultTable.Table;
    for (int i = 0; i < rowCount;i++)
                        {
                            Console.WriteLine("Path" + " : {0}",dataTable.Rows[i]["Path"].ToString());
                        }
                 }
           }

However, if I were to explictly search for people with their user name.

Example: keywordQuery.querytext = "Sps Farm";

It always works correctly for both Client and Server models. I have tried other things like IgnoreAllNoiseQuery=false, EnableStemming=true.

I am trying apply the server object model on a Web Part as a test for creating a search web part from scratch. It returns exactly like the console application for server object model.

Is there something wrong with the code?

Thank you for reading.

  • Have you tried just specifying the SourceID and not the RankingModelId? – Matthew McDermott Aug 20 '15 at 19:04
  • Yeap.. It still happens. However I've tried in a webpart and it works after i set the query text to have ContentClass=urn:content-class:SPSPeople. I am not quite sure this is the correct method? Because the result sources has exactly that query attached behind to the searchterms. But temporarily it works. – Conium Aug 21 '15 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.