today I run into an issue with KeywordQuery on SharePoint 2013 - On-Premise. Filter on a Managed Property is not working. I am getting results with different values than given with my QueryText PersNrOWSTEXT="44540".
If I type following into the Search-Box of the default SharePoint-Search-Page, I get proper results (only rows having 44540 in field PersNrOWSTEXT): PersNrOWSTEXT="44540" AND isDocument:true AND path:https://portal/apps/hr/* So, it is clear that the field PersNrOWSTEXT is Searchable.
If I do the same with my JSOM-Code, I get results with different values than 44540:
var context = new SP.ClientContext("https://portal");
var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(context);
var queryText = "PersNrOWSTEXT=\"44540\"";
var sortproperties = keywordQuery.get_sortList();
var properties = keywordQuery.get_selectProperties();
var queryTemplate = "isDocument:true AND path:https://portal/apps/hr/*";
properties.add("Path");
properties.add("ContentType");
properties.add("Filename");
properties.add("Author");
properties.add("Editor");
properties.add("Write");
properties.add("PersNrOWSTEXT");
keywordQuery.set_trimDuplicates(true);
keywordQuery.set_clientType(15); // 15 = ContentSearchRegular
keywordQuery.set_sourceId("8413cd39-2156-4e00-b54d-11efd9abdb89");
keywordQuery.set_enableSorting(true);
sortproperties.add("ModifiedOWSDATE", 1);
keywordQuery.set_queryText(queryText);
keywordQuery.set_queryTemplate(queryTemplate);
keywordQuery.set_rowLimit(15);
keywordQuery.set_startRow(portal.hr.search.currentPagingOffset);
var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(context);
portal.hr.search.results = searchExecutor.executeQuery(keywordQuery);
context.executeQueryAsync(portal.hr.search.onSearchSuccess, portal.hr.search.onSearchFailed);
The next thing is, that the sorting on field ModifiedOWSDATE is not working either.
What am I missing here? Any help is appreciated.
Thx, Ronny