3

I'm trying to find the way to get access to a few additional fields inside my custom search result template. This template is attached to a content type that is derived from a common Folder if it makes a difference.

So far result looks like the following: enter image description here

Notice that ListID and WebId are not displayed.

I have included ListID and WebId in mso:ManagedPropertyMapping tag, but it still does not work.

<mso:ManagedPropertyMapping msdt:dt="string">'Title':'Title','Path':'Path','Description':'Description','EditorOWSUSER':'EditorOWSUSER','LastModifiedTime':'LastModifiedTime','CollapsingStatus':'CollapsingStatus','DocId':'DocId','HitHighlightedSummary':'HitHighlightedSummary','HitHighlightedProperties':'HitHighlightedProperties','FileExtension':'FileExtension','ViewsLifeTime':'ViewsLifeTime','ParentLink':'ParentLink','FileType':'FileType','IsContainer':'IsContainer','SecondaryFileExtension':'SecondaryFileExtension','DisplayAuthor':'DisplayAuthor','ListItemID':'ListItemID','BarCodeOWSNMBR':'BarCodeOWSNMBR','BarCode','ItemID':'ItemID','ListID':'ListID','SPSiteURL':'SPSiteURL','WebId':'WebId'</mso:ManagedPropertyMapping>

enter image description here

The main HTML part of my template(I don't include the whole one because it's too big):

        <div id="_#= $htmlEncode(itemId) =#_" name="Item" data-displaytemplate="DefaultItem" class="ms-srch-item" onmouseover="_#= ctx.currentItem_ShowHoverPanelCallback =#_" onmouseout="_#= ctx.currentItem_HideHoverPanelCallback =#_">
            <!--_#=ctx.RenderBody(ctx)=#_   -->
            <div>_#= titleHtml2 =#_</div>
            <div id="_#= $htmlEncode(hoverId) =#_" class="ms-srch-hover-outerContainer"></div>
            <div>ctx.CurrentItem.IsContainer _#= ctx.CurrentItem.IsContainer =#_</div>
            <div>ctx.CurrentItem.Title= _#= ctx.CurrentItem.Title =#_</div>
            <div>ctx.CurrentItem.Path= _#= ctx.CurrentItem.Path =#_</div>
            <div>ctx.CurrentItem.OriginalPath= _#= ctx.CurrentItem.OriginalPath =#_</div>
            <div>ctx.CurrentItem.BarCodeOWSNMBR= _#= ctx.CurrentItem.BarCodeOWSNMBR =#_</div>
            <div>ctx.CurrentItem.BarCode = _#=ctx.CurrentItem.BarCode =#_ </div>
            <div>ctx.CurrentItem.ListItemID = _#=ctx.CurrentItem.ListItemID =#_ </div>
            <div>ctx.CurrentItem.ItemID = _#=ctx.CurrentItem.ItemID =#_ </div>
            <div>ctx.CurrentItem.SPSiteURL = _#=ctx.CurrentItem.SPSiteURL =#_ </div>
            <div>ctx.CurrentItem.ListID = _#=ctx.CurrentItem.ListID =#_ </div>
            <div>ctx.CurrentItem.WebId = _#=ctx.CurrentItem.WebId =#_ </div>
            <div>ctx.CurrentItem.ows_ListID = _#=ctx.CurrentItem.ows_ListID =#_ </div>
        </div>

Can someone, please, help me to force my template get access to the WebId and ListID properties? I don't know what I am doing wrong. Could it be because this is a CT derived from a folder?

Additional info:

I've also written a basic WinForms app that gets search results from SharePoint search service with KeyWordQuery for testing purposes and it shows me ListID and WebId with no problems. It just proves that those are retrievable managed properties.

enter image description here

              using (KeywordQuery keywordQuery = new KeywordQuery(proxy))
              {
                keywordQuery.ResultsProvider = SearchProvider.Default;
                keywordQuery.StartRow = 0;
                keywordQuery.RowLimit = 500;
                keywordQuery.EnableStemming = true;
                keywordQuery.TrimDuplicates = true;
                keywordQuery.AuthenticationType = QueryAuthenticationType.PluggableAuthenticatedQuery;
                keywordQuery.Culture = CultureInfo.CurrentCulture;
                keywordQuery.KeywordInclusion = KeywordInclusion.AllKeywords;

                List<RoleSetup> roleSetups = PermissionsHelper.GetRoleSetup(site.RootWeb.CurrentUser);

                keywordQuery.SelectProperties.Add("path");
                keywordQuery.SelectProperties.Add("ListItemID");
                keywordQuery.SelectProperties.Add("BarCodeOWSNMBR");
                keywordQuery.SelectProperties.Add("ows_BarCode");
                keywordQuery.SelectProperties.Add("BarCode");
                keywordQuery.SelectProperties.Add("Description");
                keywordQuery.SelectProperties.Add("ListID");
                keywordQuery.SelectProperties.Add("ItemID");
                keywordQuery.SelectProperties.Add("SPSiteURL");
                keywordQuery.SelectProperties.Add("ListID");
                keywordQuery.SelectProperties.Add("WebId");

                keywordQuery.SelectProperties.Add("title");
                keywordQuery.SelectProperties.Add("RP");
                keywordQuery.SelectProperties.Add("LP");
                keywordQuery.SelectProperties.Add("SE");
                keywordQuery.SelectProperties.Add("path");
                keywordQuery.SelectProperties.Add("ContentType");
                keywordQuery.SelectProperties.Add("ContentTypeId");
                keywordQuery.SelectProperties.Add("contentclass");
                SearchExecutor executor = new SearchExecutor();
                ResultTableCollection resultTableCollection = executor.ExecuteQuery(keywordQuery);
                var resultTables = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);
                ResultTable resultTable = resultTables.FirstOrDefault();
               }

So, to recap: I just need to know how to get access to ListItemID (and other custom fields) inside my search results template. Any help will be greatly appreciated.

Update: At first, I could not get ListItemID property, but then I found the following text on a blog:

Save the template file and navigate to the site collection Search Result Types settings page. A warning "Property Sync" should be visible - click on the suggested "Update" link to sync the newly added managed properties. You have to do this everytime you add a new mapped property, otherwise the property value will be null in the result set.

It did help me to show ListItemID property. But now I can't get very important WebId and ListID properties.

2

I am very embarrassed, but it looks like that search development just needs a lot of patience and carefulness.

It looks like two things might have worked here for me:

The first one

Save the template file and navigate to the site collection Search Result Types settings page. A warning "Property Sync" should be visible - click on the suggested "Update" link to sync the newly added managed properties. You have to do this everytime you add a new mapped property, otherwise the property value will be null in the result set.

Secondly

I did a full crawl. After it finished it took about 5-10 minutes for missing properties to appear on the results template

enter image description here

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.