Display Metadata in cross site search

Copper Contributor

Hey guys, 

 

Is it possible to display metadata in the UI during cross-site search in sharepoint hub?

So that we have the same view in the cross-site search as in the library search, with the metadata to the right of the result.

 

Thanks for helping.

 

 

3 Replies

@mh_98

To display metadata in cross-site search results in SharePoint is to use the Search Results web part with a custom result type.

Here's how to do it:

  1. Go to the search results page where you want to display the metadata.

  2. Edit the page and add the "Search Results" web part.

  3. Click on the "Search Results" web part and then click on "Edit Web Part" from the ribbon.

  4. In the web part properties, scroll down to the "Change Query" section and click on "Switch to Advanced Mode".

  5. In the query text box, add the following code:

 

{ 
    "querytext": "*", 
    "sourceid": "your_source_id", 
    "rowlimit": "10", 
    "enablequeryrules": "false", 
    "trimduplicates": "true", 
    "selectproperties": "Title,Path,Description,Write,AuthorOWSUSER,MetadataColumn1,MetadataColumn2", 
    "refinementfilters": "FileType:equals('docx')", 
    "clienttype": "ContentSearchRegular"
}

Replace "your_source_id" with the ID of the search source you want to use for the cross-site search. Replace "MetadataColumn1" and "MetadataColumn2" with the internal names of the metadata columns you want to display.

 

  1. Click "OK" to save the query.

  2. In the web part properties, scroll down to the "Display Templates" section and click on "Switch to custom".

  3. In the "Result Type" section, click on "Add new item" and give it a name.

  4. In the "Mapping" section, add the following mappings:

 

Title -> Title
Description -> Description
Path -> Path
Write -> Write
AuthorOWSUSER -> Author
MetadataColumn1 -> MetadataColumn1
MetadataColumn2 -> MetadataColumn2

Replace "MetadataColumn1" and "MetadataColumn2" with the internal names of the metadata columns you want to display.

 

  1. In the "Display properties" section, add the following HTML:

 

<div class="srch-Item"> 
    <h3 class="srch-ItemTitle"> 
        <a href="_#=ctx.CurrentItem.Path=#_"> 
            _#=ctx.CurrentItem.Title=#_ 
        </a> 
    </h3> 
    <div class="srch-ItemDescription"> 
        _#=ctx.CurrentItem.Description=#_ 
    </div> 
    <div> 
        MetadataColumn1: _#=ctx.CurrentItem.MetadataColumn1=#_ 
    </div> 
    <div> 
        MetadataColumn2: _#=ctx.CurrentItem.MetadataColumn2=#_ 
    </div> 
</div> 

Replace "MetadataColumn1" and "MetadataColumn2" with the internal names of the metadata columns you want to display.

 

  • Save and publish the page. Once you have completed the above steps, the search results will display the metadata columns in the UI during cross-site search in SharePoint hub, using the custom result type you created.

Hey Nikolino,
Thanks for answering me that fast!
I will try it.
Hi Nikolino, I'm having some issues.
I changed the query, but I'm seeing different settings options in the display templates than you described.
I can choose between 'Use result types to display items' where I can choose the Result type for item and Configure result types.
or Use a single template to display items' where I can choose the Item Display Template, confgure it and choose Hit-highlighted properties.

So I'm hanging in 2. In the web part properties, scroll down to the "Display Templates" section and click on "Switch to custom". - of your walk through.

Maybe you have some ideas which can help me.
Thanks a lot,

Max