1

I did what this page teaches:
http://code.msdn.microsoft.com/SharePoint-2013-Querying-a629b53b

It works, but the thing is that I used the same KQL query in a content search webpart and I have something missing. I changed a bit the code to get me all site collections. I have 5 sites, two are projects web templates. The content search web part gives me all my sites, but the project ones are missing from my code!

Here's my query:

"contentclass:STS_Site -Path:http://mysite.server.com -Path:http://portal.server.com"

The query gives me all sites from my others webapps, like intranet.server.com, etc.

Comments are appreciated!


Just a few more info:

enter image description here

enter image description here

enter image description here

My Code:

var ctx;
var web;
var results;

function test() {
    var queryStr = "contentclass:STS_Site -Path:http://mysite.ubi.com -Path:http://portal.ubi.com"
    ctx = new SP.ClientContext.get_current();
    var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(ctx);
    keywordQuery.set_queryText(queryStr);
    var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(ctx);
    results = searchExecutor.executeQuery(keywordQuery);
    ctx.executeQueryAsync(onQuerySuccess, onQueryFail);
 }

 function onQuerySuccess() {
    $("#searchResults").append('<table>');

    $.each(results.m_value.ResultTables[0].ResultRows, function () {
       $("#searchResults").append('<tr>');
       $("#searchResults").append('<td>' + this.Title + '</td>');
       $("#searchResults").append('<td>' + this.Author + '</td>');
       $("#searchResults").append('<td>' + this.Write + '</td>');
       $("#searchResults").append('<td>' + this.Path + '</td>');
       $("#searchResults").append('</tr>');
    });

    $("#searchResults").append('</table>');
}

function onQueryFail(sender, args) {
    alert('Query failed. Error:' + args.get_message());
}

$(document).ready(function () {

    $("#btn").click(function (e) {
       e.preventDefault();
       test();
    });

});

PS.: I did a full crawl and nothing changed. Well, it worked for the document center, but not for the project sites (PROJECTSITE#0) PS2.: I also checked if fiddler to make sure it wasn't the code, but the response is really different in each of the cases.

8
  • So, the CSWP gives you all 5 sites with this query, but JSOM gives you 3 sites with the same KQL query ? Apr 26 '14 at 0:50
  • Is your code running as the same user as your CSWP? Apr 26 '14 at 12:19
  • @PhilippeLavoie, Yes, I'll try to put some prints of the code and the results here.
    – Ubi
    Apr 26 '14 at 14:47
  • @MatthewMcDermott, I'm not sure. My code and the CSWP are running in the same session, but I know that it doesn't mean they're running in the same account. That happens with services for exemple, but JSOM... Can you give me some tips on how to know this for sure? Thanks!
    – Ubi
    Apr 26 '14 at 14:53
  • @Ubi Did you set your Search permissions to QueryAsUserIgnoreAppPrincipal as specified in your reference article? If so, the search query should be as the current user
    – Louis
    Apr 28 '14 at 5:25
3

Ah, you know what, my top head scratcher when I am missing results in SharePoint search is that darn "trim duplicates" option (which I think is ON by default)

SharePoint may very well be considering your pj and pj1 results too similar to another one in the list.

Try adding:

// Set Trim Duplicates to False
keywordQuery.set_trimDuplicates(false);

Also see this link for lots of good info on Search CSOM: https://blogs.perficient.com/microsoft/2014/01/sharepoint-2013-search-javascript-csom-primer/

1
  • It works! Thank you Louis! Thanks for the link as well! Tons of good info there!
    – Ubi
    Apr 28 '14 at 16:11

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.