silverstripe-fulltextsearch/docs/en/03_configuration/30_creating_an_index.md

959 B

Creating an index

An index can essentially be considered a database that contains all of your searchable content. By default, it will store everything in a field called Content, which is queried to find your search results. To create an index that you can query, you can define it like so:

use Page;
use SilverStripe\FullTextSearch\Solr\SolrIndex;

class MyIndex extends SolrIndex
{
    public function init()
    {
        $this->addClass(Page::class);
        $this->addFulltextField('Title');
    }
}

This will create a new SolrIndex called MyIndex, and it will store the Title field on all Pages for searching.

You can also skip listing all searchable fields, and have the index figure it out automatically via addAllFulltextFields(). This will add any database fields that are instanceof DBString to the index.

Once you've added this file, make sure you run a Solr configure to set up your new index.