I am having a problem with the code below. It is not returning all the rows/items which are found in different lists. The total number of items is 28, but the code below is returning 19. I have set the rowlimit to different values and the funny thing is that when I set it to 10, it returns me 23 results back. But when I set it to 50, for example, I get 19. What is going on?

On the same page I am using content search web part, and that returns 28 results. The content type that I am using is the same as in Content Search web part. You might ask why don't I use Content Search web part, and the answer is that I cannot use it because the customer has got SharePoint standard edition.

var queryText = "ContentTypeId:0x010066FA3DE3E334C841B418C82CC475A227*";
var clientContext = new SP.ClientContext("http://dev");
var contextSite = clientContext.get_site();
var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(clientContext); 

var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(clientContext);  
var results = searchExecutor.executeQuery(keywordQuery); 
clientContext.executeQueryAsync(onQuerySuccess, onQueryError);

function onQuerySuccess()
    var message = $("#message");
    message.text("Search results fro \"" + queryText + "\"");
    message.append("<br />");
    var rows = results.m_value.ResultTables[0].ResultRows;
    $.each(rows, function(index, value)
        message.append(value.Title + ": " + value.Path);
        message.append("<br />");
  • 5
    Have you tried: keywordQuery.set_trimDuplicates(false)?
    – Bunzab
    Aug 26, 2015 at 7:25

3 Answers 3


Have you tried to set keywordQuery.set_trimDuplicates(false); (MSDN) because maybe some rows / items are incorrectly treated as duplicates by search?

  • Thanks man! You made my day. It worked. It returned all 28 results.
    – Imir Hoxha
    Aug 26, 2015 at 7:33

Actually that was a great question and good that you added your code as well. In my case I was trying to get all the site collection inside Content Search display template I was not getting all the result but by adding "keywordQuery.set_rowLimit(500);"

I started to get all the results. Below is the code that worked for me. By the way deffered approach doesnt make it synchronous and I dont own this code either.

function RetrieveWebSiteUsingSearch(siteUrl,groupElm)

                var d = $.Deferred();
                SP.SOD.executeFunc("SP.js", "SP.ClientContext", function () 
                    SP.SOD.executeFunc("SP.Search.js", "Microsoft.SharePoint.Client.Search.Query.KeywordQuery", function () 
                        var sContext = SP.ClientContext.get_current();
                        var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(sContext);
                        var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(sContext);
                        results = searchExecutor.executeQuery(keywordQuery);
                            function () 
                                var sitePath = '';
                                var siteTitle = '';
                                for (var i= 0; i < results.m_value.ResultTables[0].ResultRows.length; i++) 
                                    sitePath = results.m_value.ResultTables[0].ResultRows[i].Path;
                                    siteTitle = results.m_value.ResultTables[0].ResultRows[i].Title;
                                    dictUrlTitlePairs["'"+sitePath+"'"] = siteTitle;

                            function (err) 

                return d.promise();


Below are the code for searching in specific library with all result

 using (clientContext = new ClientContext(siteName))
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                clientContext.Credentials = GetSharePointNetworkCredential();
                KeywordQuery keywordQuery = new KeywordQuery(clientContext);

                 clientContext.Web.Lists.GetByTitle(libraryName.Replace("%20", " "));
                keywordQuery.TrimDuplicates = false;
                keywordQuery.QueryText = String.Format("{0} AND Path:\"{1}\"", "*searchkeyword*", "SiteName");
                SearchExecutor searchExecutor = new SearchExecutor(clientContext);

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

                foreach (var resultRow in results.Value[0].ResultRows)
                    Console.WriteLine("{0}: {1} ({2})", resultRow["Title"], resultRow["Path"], resultRow["Write"]);

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.