Try our conversational search powered by Generative AI!

Searching in blocks



we are trying to implement a search with EPiServer Find, On the site we are only able to find documentation on searching in pagedata, we need to search blocks aswell, and since we have a lot of shared blocks we need to find all pages where the block is added.

Anyone worked on a similar problem ?

Jan 18, 2013 12:11


You need to add the IndexInContentAreas attribute to the blocks that you want to be indexed when located on pages.

Jan 18, 2013 15:31


To elaborate a little on what Marcus wrote:

Shared blocks are indexed just as pages and you can search for shared blocks the same way as you do with pages. As for ContentAreas only references to the contents in them are indexed. For pages a method named SearchText is automatically indexed. This method returns the values of all properties marked as searchable AND all properties marked as searchable on content in ContentArea properties given that the content type is annotated with IndexInContentAreas.

In other words, if you have block types which are used for editorial content and you want pages with such blocks in content areas to be found when you search for a keyword in one of the blocks you should annotate the block with IndexInContentAreas. However, without knowing more about the site you're building, I'd advise you to think about wether that's what you actually want. If the blocks just hold "related" content which also exist on individual pages you may be better off not having the block content indexed on the pages.

Jan 18, 2013 23:24

Is it possible to search the contents of block when using the basic EPiServer Search (used in for example Alloy tech demo site)? I did examine segments.gen (under "EPiServer/VPP/SiteName/Index/Main") with Luke (Lucene Index Toolbox) and it shows that the contents of Xhtml string in block is indexed but searchpage doesn't find it. Any ideas? Or would it be better to just use EPiServer Find? :)

Feb 22, 2013 13:42

I would also like to know the answer to the previous question?

Aug 27, 2013 14:11

Vesa and Anssi i find in episerver blog an item with apparently a bad news

(…)”Global search on all types of content, such as video, images etc. Not only pages and files. (There is one exception: you will not get hits on content in blocks that are added in a Content Area. This is usually not a problem though, since content in a block is often promoting content in a page, and that page will be found when performing the search. Searching in blocks is supported in EPiServer Find.)”(…)

If you find a solution, please help me,I have the same issue. i have use a lot of blocks for dynamized my pages and i have needed to return my blocks linked pages.

Sep 10, 2013 8:13

Joel, what is the logic in collecting text from blocks in contentarea when "IndexInContentArea" is set? I tried adding custom "SearchText" to my block but that text is not added to the indexed content of the page to which this block is added to. How can I change that default behaviour?

Oct 01, 2013 9:42

Hi Janne,

Properties that are searchable on the block will be included in the parent's (the page that contains the content area) SearchText().

Oct 01, 2013 9:50

Yes, but my challenge is that I would like to have custom logic in block to return the SearchText for single block AND have that searchtext included to the parents indexed content? Do you see any way of achieving that? My block has custom logic of retrieving its content and this content is now not included to parents indexed content.

Oct 01, 2013 9:56

Or should I do it so that I include my block also to the list of searched types and when matching block found get pages that use this block and then include those pages to the final results?

Oct 01, 2013 10:00

Ah, what you have to do then is provide a custom implementation of the SearchText field on the parent object. A simple implementation may look something like this:

public class MyPage : PageData
  public virtual ContentArea MyStuff { get; set; }

  public string SearchText 
      var text = this.SearchText();
      foreach(var content in MyStuff.Contents)
        var myBlock = content as MyBlock;
        if(myBlock != null)
          text += " " + myBlock.SearchText;
      return text;

You can of course make it more dynamic by iterating over all content area properties, but I hope the above code shows the essence of the solution?    

Oct 01, 2013 10:02

Ok, this is what I originally had but I wanted to make it more general and place the custom SearchText to block instead so that it would get applied in all places where my block is added. But this is probably not duable this way? 

Oct 01, 2013 10:06

Well, yes and no :) You could override SearchText for all your page types, either in a base class or by removing the default implementation and adding your own through the SearchClient.Convetions property. In your own implementation you could call the default implementation and then iterate over each of the page's properties and look for blocks in content areas.

One could definitely argue that the SearchText field should be used for blocks in content areas. However, if that was the case I think there may be a risk of circular references during indexing.

Oct 01, 2013 10:12

I think I'll go with single page type implementation as a "quick" solution and look into the more general solution of having SearchText in base class later. Thanks a lot for the help and information!

Oct 01, 2013 10:17

Hmm one more question: What is the way to call the default implementation for SearchText of a page?

Oct 01, 2013 10:34

The default implementation is an extension method so given that you are in a PageData class: this.SearchText().

Oct 01, 2013 10:41

Hey Joel, 'IndexInContentAreas' discussed above, is this still valid for EPiServer basic full text search? The results from shared blocks have no URL making it difficult for the visitors to judge the content source.

We also have problems with local blocks on pages not being indexed even properties in those blocks are marked as 'Searchable'. Annoyingly, a local block cannot be marked as searchable in code but in the admin mode you can enable a local block to be searchable but seems of no use as none of the properties in local blocks are indexed.

Dec 12, 2013 3:25
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.