<commit_before>﻿# Add block content to the index.

By <NAME>

## About

This week I needed to add Blocks used on a page to EPiServer Search Index as content of the page they were used on.
This is supported in Find, but as we are not using Find in this project, I needed a different solution.

First I added an extra property to my base class to hold the content of my Blocks. 
Note the ScaffoldColumn(false) attribute, which hides it in edit mode.

        [CultureSpecific]
        [ScaffoldColumn(false)]
        [Searchable]
        [AdditionalSearchContent]
        public virtual string SearchText { get; set; }

Next I created an InitializableModule to attach some functionality to the publishing event.

When publishing the page, I loop through all Blocks in the ContentAreas defined on the page.

I get all values from string properties marked ```Searchable``` in the Blocks and add them to the SearchText property on my PageType. 
Note: If for some reason you don't want a property on a Block indexed, just add ```[Seachable(false)]``` to it.
The aggregated content from the blocks is added to the property marked with ```[AdditionalSearchContent]```.

The content of the property marked with ```[AdditionalSearchContent]`` is added to the index and you get results also if the term you are looking for is only used in a Block on the page.

## Requirements

* EPiServer >= 7.7.1<commit_msg>Added AppVeyor status to readme<commit_after>﻿# Add block content to the index.

By <NAME>

![AppVeyor status](https://ci.appveyor.com/api/projects/status/github/jstemerdink/EPi.Libraries.BlockSearch?branch=master&svg=true)

## About

This week I needed to add Blocks used on a page to EPiServer Search Index as content of the page they were used on.
This is supported in Find, but as we are not using Find in this project, I needed a different solution.

First I added an extra property to my base class to hold the content of my Blocks. 
Note the ScaffoldColumn(false) attribute, which hides it in edit mode.

        [CultureSpecific]
        [ScaffoldColumn(false)]
        [Searchable]
        [AdditionalSearchContent]
        public virtual string SearchText { get; set; }

Next I created an InitializableModule to attach some functionality to the publishing event.

When publishing the page, I loop through all Blocks in the ContentAreas defined on the page.

I get all values from string properties marked ```Searchable``` in the Blocks and add them to the SearchText property on my PageType. 
Note: If for some reason you don't want a property on a Block indexed, just add ```[Seachable(false)]``` to it.
The aggregated content from the blocks is added to the property marked with ```[AdditionalSearchContent]```.

The content of the property marked with ```[AdditionalSearchContent]`` is added to the index and you get results also if the term you are looking for is only used in a Block on the page.

## Requirements

* EPiServer >= 7.7.1
{'fraction_non_alphanumeric': 0.06239403187521193, 'fraction_numerical': 0.002034587995930824, 'mean_word_length': 4.034129692832765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4679730', 'n_tokens_mistral': 787, 'n_tokens_neox': 767, 'n_words': 429}