PHP code example of vulcandigital / silverstripe-search

1. Go to this page and download the library: Download vulcandigital/silverstripe-search 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/ */

    

vulcandigital / silverstripe-search example snippets


class Recipe extends DataObject
{
    // Apply the extension
    private static $extensions = [
        \Vulcan\Search\Extensions\SearchIndexExtension::class
    ];
    
    // the search tank that records from the class are indexed under 
    // this is optional and will default to "Main" if not provided
    private static $search_tank = 'Recipes'
    
    private static $db = [
        'Title' => 'Varchar(255)',
        'Content' => 'HTMLText',
        'SomeRandomFieldWithContent' => 'Text',
        'UselessField' => 'Boolean'
    ];
    
    // Showing the use of Dot Notation in searchableColumns()
    private static $has_one = [
        'User' => Member::class
    ];
    
    // This will conslidate the content from all columns into a single searchable line of text
    public function searchableColumns() 
    {
        return [
            'Title',
            'Content',
            'SomeRandomFieldWithContent',
            'User.FirstName'
        ]
    }
}

private static $search_tank = 'MyCustomTank';