Question

I'm doing a SharePoint search and I need specifically select Title field, but, some times the result is the title of the document and not the Title field of the library or list

I'm using PnP-Js-Core

My code

return new Promise((resolve, reject) => {
  let listName = encodeURIComponent(this.listName);
  let query: string = `contentclass:STS_ListItem OR IsDocument:True path:${this.siteUrl}/${listName}/ ${text}`;
  pnp.sp.search(<SearchQuery>{
    Querytext: query,
    SelectProperties: ['Title'],
  })
    .then((r: SearchResults) => {
      resolve(r.PrimarySearchResults);
    })
    .catch((err) => {
      console.log(err);
      reject(null);
    });
});

Thanks.

Was it helpful?

Solution

The Title managed property is mapped, by default, to more than just the Title column in SharePoint and SharePoint Online. So, in your query for "Title", in addition to ows_Title, you are also getting values from Basic:displaytitle, TermTitle, MetadataExtractorTitle, and Title. If you want only your List or Library Item Title field you may want to configure your own queryable Managed Property and map it to ows_Title.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top