PHP code example of dnadesign / silverstripe-elemental-textcontentforsearch

1. Go to this page and download the library: Download dnadesign/silverstripe-elemental-textcontentforsearch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dnadesign / silverstripe-elemental-textcontentforsearch example snippets


class ElementalSolrIndex extends SolrIndex
{
    public function init()
    {
        $this->addClass(Page::class);
        $this->addAllFulltextFields();
        /** @see ElementalPageTextContentSearchExtension::getTextContentForSearch */
        $this->addFulltextField('TextContentForSearch');
    }
}

class MyCustomElement extends BaseElement
{
    private static $exclude_fields_from_search = [
        'Title'
    ];
}

class MyCustomElement extends BaseElement
{
    private static $

class MyCustomElement extends BaseElement
{
    private static $has_many = [
        'AccordionItems' => AccordionItem::class
    ];

    public function addTextContentForSearch()
    {
        $titles = [];
        foreach($this->AccordionItems() as $item) {
            $titles[] = $item->Title;
        }
        return implode(' ', $titles);
    }
}

class MyCustomElement extends BaseElement
{
    public function updateTextContentForSearch($string)
    {
        // Remove any occurrence of forbiddenWord in the final string
        return = str_replace('forbiddenWord', '', $string);
    }
}

class MyCustomElement extends BaseElement
{
    private static $exclude_content_from_search = true;
}