1

I'm working on a Communications site, and I can't make content created in special custom editors (like the React Script Editor, or the React TinyMCE editor included in the sample web parts) searchable.

I assume this is because this content needs to be added to one of the big indexed fields - I think CanvasContent1 exists for this purpose, possibly? That's just a guess, and I can't seem to find anything in the documentation about this.

How do I make sure that content from these SPFx web parts, or any SPFx web part, gets properly added to the correct Page property to make it indexed and searchable? Is there a method I need to override or call from within my web part? Do I need to manually update CanvasContent1 somehow?

2

I asked this same question on Github, and the devs pointed me to the correct answer.

The web part .ts file for any part you want to index needs to be modified so that the property that contains the text to be added to the index has one of these value types assigned to it:

isSearchablePlainText, isHtmlString, isImageSource, isLink

If these types are assigned to a web part property on a page that gets crawled, that property gets indexed by the search engine.

A sample of adding the types to properties follows:

import {
  BaseClientSideWebPart,
  IPropertyPaneConfiguration,
  PropertyPaneTextField,
  IWebPartPropertiesMetadata
} from '@microsoft/sp-webpart-base';

// ...

export default class ArticleLinkWebPart extends BaseClientSideWebPart<IArticleLinkWebPartProps> {
  // ...
  protected get propertiesMetadata(): IWebPartPropertiesMetadata {
    return {
      'title': { isSearchablePlainText: true },
      'intro': { isHtmlString: true },
      'image': { isImageSource: true },
      'url': { isLink: true }
    };
  }
  // ...
}

This code needs to be in the <WebPartName>WebPart.ts file (not in the component definition *.tsx file).

Microsoft's documentation with details is located here: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/guidance/integrate-web-part-properties-with-sharepoint

It didn't come up for me in a web search, so hopefully this will help others like me who are looking for this answer.

  • Have you found this to work ok? I tried it with isSearchablePlainText and haven't got expected search results. – Paul Lucas Mar 15 '18 at 4:42
  • @PaulLucas - It works for me using the isHtmlString option, but I haven't tried it with isSearchablePlainText yet. With the isHtmlString option, the content of the web part gets put into the page Description field. You might want to check if your content is getting added to any of the page's properties to see if it actually is getting transferred, although I'm not 100% sure that isSearchablePlainText works in the same way that isHtmlText does. – yogsodoth Mar 16 '18 at 15:34

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.