Pnpjs: How do I get Associated Site Logos and Descriptions?

Created on 25 Jan 2021  路  2Comments  路  Source: pnp/pnpjs

@patrick-rodgers @tavikukko

Category

  • [ ] Enhancement
  • [ ] Bug
  • [x] Question
  • [ ] Documentation gap/issue

Version

Latest

Expected / Desired Behavior / Question

I have a webpart that builds tiles for the Hub's associated sites. I am trying to get both the SiteLogoUrl and Site description in the search results (single call if possible).

Unfortunately I can't seem to do it without first getting the list of associated sites, then iterating through the list of URLs and getting Description/SiteLogoUrl.

I'm wondering if it's a limitation of this library or Search in general?

I did notice with the OOTB Sites webpart, it seems to get at least the SiteLogoUrl because the Sites webpart does show icons so I'm just wondering if there is a better way to approach this so I don't need multiple calls.

image

Here's a snippet of my current search query. I added "*","SiteLogoUrl","Description" to the SelectProperties but I don't see them in the return.

Thanks!


    sp.search(<ISearchQuery>{
        Querytext: `contentclass:STS_Site AND departmentId:{${departmentId}}`,
          SelectProperties: ["*","Title", "SPSiteUrl", "WebTemplate","departmentId","SiteLogoUrl","Description"],
          RefinementFilters:[`departmentid:string("{*",linguistics=off)`],
          RowLimit: 500,
//          SortList: [ {Property: 'Title',Direction: sortDirection }],
          TrimDuplicates: false})
          .then((r: SearchResults) => {

            console.log(r.RowCount);
            console.log(r.PrimarySearchResults);
            entireResponse.hubs = r.PrimarySearchResults;

            entireResponse.hubs.map( h => {
                h.sourceType = hubsCategory;
            });


            callback( entireResponse, custCategories, newData );

    });

non-library question

Most helpful comment

Just do normal search, no RefinementFilters needed, and use SiteLogo and Description as SelectedProperties
``typescript sp.search({ "Querytext":contentclass:STS_Site AND departmentId:{${departmentId}}`,
"RowLimit": 10,
"StartRow": 0,
"ClientType": "ContentSearchRegular",
"SelectProperties": [
"Title",
"SPSiteUrl",
"WebTemplate",
"departmentId",
"SiteLogo",
"Description",
]
}).then(res => {
console.log(res)
})
````
image

and here is the Managed Property settings that @juliemturner mentioned, here you can check Properties that you can use in search:
image

All 2 comments

Without looking into it further I can't specifically answer your question, but the short answer is that only thing that are configured to be queryable can be retrieved in search results... So where you really want to focus your research is if the SiteLogoUrl and/or Site Description are crawled/managed properties in SharePoint search and if they are queryable ...

In SharePoint Admin look at the Search Admin settings: https://-admin.sharepoint.com/_layouts/15/searchadmin

Just do normal search, no RefinementFilters needed, and use SiteLogo and Description as SelectedProperties
``typescript sp.search({ "Querytext":contentclass:STS_Site AND departmentId:{${departmentId}}`,
"RowLimit": 10,
"StartRow": 0,
"ClientType": "ContentSearchRegular",
"SelectProperties": [
"Title",
"SPSiteUrl",
"WebTemplate",
"departmentId",
"SiteLogo",
"Description",
]
}).then(res => {
console.log(res)
})
````
image

and here is the Managed Property settings that @juliemturner mentioned, here you can check Properties that you can use in search:
image

Was this page helpful?
0 / 5 - 0 ratings