7

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); 
keywordQuery.set_queryText(queryText); 
keywordQuery.set_rowLimit(500);

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 '15 at 7:25
9

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 '15 at 7:33
0

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);
                        keywordQuery.set_trimDuplicates(false);
                        keywordQuery.set_queryText("contentclass:sts_site");
                        keywordQuery.set_rowLimit(500);
                        var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(sContext);
                        results = searchExecutor.executeQuery(keywordQuery);
                        sContext.executeQueryAsync(
                            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;
                                    //alert(results.m_value.ResultTables[0].ResultRows[i].ContentType) 
                                }   
                                search.Grouping.show(groupElm);
                                d.resolve(results);

                            },
                            function (err) 
                            {
                                d.reject(null);
                            }
                            );
                    });
                });

                return d.promise();

            }

Your Answer

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

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