SilverStripe solr Search

BaseIndexTrait

This is slightly cheating, but it works and also makes things more readable.

This is slightly cheating, but it works and also makes things more readable.

Table of Contents

Properties

$client  : Client
$copyFields  : array<string|int, mixed>
$defaultField  : string
$facetFields  : array<string|int, mixed>
$filterFields  : array<string|int, mixed>
$fulltextFields  : array<string|int, mixed>
$sortFields  : array<string|int, mixed>
$storedFields  : array<string|int, mixed>
$usedAllFields  : bool
usedAllFields is used to determine if the addAllFields method has been called This is to prevent a notice if there is no yml.

Methods

addAllDateFields()  : mixed
Add all date-type fields to the given index
addAllFulltextFields()  : mixed
Add all text-type fields to the given index
addBoostedField()  : mixed
Add an abstract for the add Boosted Field to keep things consistent
addCopyField()  : $this
Add a copy field
addFacetField()  : $this
Add a facet field
addFilterField()  : $this
Add a filterable field
addFulltextField()  : $this
Add a single Fulltext field
addSortField()  : $this
Add a field to sort on
addStoredField()  : BaseIndex
Add a stored/fulltext field
getClasses()  : array<string|int, mixed>
This trait requires classes to be set, so getClasses can be called.
getClient()  : Client
Get the client
getCopyFields()  : array<string|int, mixed>
Return the copy fields
getDefaultField()  : string
Return the default field for this index
getFilterFields()  : array<string|int, mixed>
Get the filter fields
getFulltextFields()  : array<string|int, mixed>
Get the fulltext fields
getSortFields()  : array<string|int, mixed>
Get the sortable fields
getStoredFields()  : array<string|int, mixed>
Get the stored field list
setClient()  : $this
Set/override the client
setCopyFields()  : $this
Set the copy fields
setDefaultField()  : $this
Set the default field for this index
setFilterFields()  : $this
Set the filter fields
setFulltextFields()  : $this
Set the fulltext fields
setSortFields()  : $this
Set/override the sortable fields
setStoredFields()  : BaseIndex
Set/override the stored field list
addAllFieldsByType()  : void
Add all database-backed text fields as fulltext searchable fields.
addFulltextFieldsForClass()  : void
Add all fields of a given type to the index

Properties

$copyFields

protected array<string|int, mixed> $copyFields = ['_text' => ['*']]

Fields to copy to the default fields

$defaultField

protected string $defaultField = '_text'

Default search field

$facetFields

protected array<string|int, mixed> $facetFields = []

Facet fields

$filterFields

protected array<string|int, mixed> $filterFields = []

Filterable fields

$fulltextFields

protected array<string|int, mixed> $fulltextFields = []

Fulltext fields

$sortFields

protected array<string|int, mixed> $sortFields = []

Sortable fields

$storedFields

protected array<string|int, mixed> $storedFields = []

Stored fields

$usedAllFields

usedAllFields is used to determine if the addAllFields method has been called This is to prevent a notice if there is no yml.

protected bool $usedAllFields = false

Methods

addAllDateFields()

Add all date-type fields to the given index

public addAllDateFields() : mixed
Tags
throws
ReflectionException

addAllFulltextFields()

Add all text-type fields to the given index

public addAllFulltextFields() : mixed
Tags
throws
ReflectionException

addBoostedField()

Add an abstract for the add Boosted Field to keep things consistent

public abstract addBoostedField(string $field[, array<string|int, mixed>|int $options = [] ][, null|int $boost = null ]) : mixed
Parameters
$field : string
$options : array<string|int, mixed>|int = []
$boost : null|int = null

addCopyField()

Add a copy field

public addCopyField(string $field, array<string|int, mixed> $options) : $this
Parameters
$field : string

Name of the copyfield

$options : array<string|int, mixed>

Array of all fields that should be copied to this copyfield

Return values
$this

addFacetField()

Add a facet field

public addFacetField( $field, array<string|int, mixed> $options) : $this
Parameters
$field :
$options : array<string|int, mixed>
Return values
$this

addFilterField()

Add a filterable field

public addFilterField( $filterField) : $this
Parameters
$filterField :
Return values
$this

addFulltextField()

Add a single Fulltext field

public addFulltextField(string $fulltextField[, null|string $forceType = null ][, array<string|int, mixed> $options = [] ]) : $this
Parameters
$fulltextField : string
$forceType : null|string = null
$options : array<string|int, mixed> = []
Return values
$this

addSortField()

Add a field to sort on

public addSortField( $sortField) : $this
Parameters
$sortField :
Return values
$this

addStoredField()

Add a stored/fulltext field

public addStoredField(string $field[, null|string $forceType = null ][, array<string|int, mixed> $extraOptions = [] ]) : BaseIndex
Parameters
$field : string
$forceType : null|string = null
$extraOptions : array<string|int, mixed> = []
Return values
BaseIndex

getClasses()

This trait requires classes to be set, so getClasses can be called.

public abstract getClasses() : array<string|int, mixed>
Return values
array<string|int, mixed>

getClient()

Get the client

public getClient() : Client
Return values
Client

getCopyFields()

Return the copy fields

public getCopyFields() : array<string|int, mixed>
Return values
array<string|int, mixed>

getDefaultField()

Return the default field for this index

public getDefaultField() : string
Return values
string

getFilterFields()

Get the filter fields

public getFilterFields() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFulltextFields()

Get the fulltext fields

public getFulltextFields() : array<string|int, mixed>
Return values
array<string|int, mixed>

getSortFields()

Get the sortable fields

public getSortFields() : array<string|int, mixed>
Return values
array<string|int, mixed>

getStoredFields()

Get the stored field list

public getStoredFields() : array<string|int, mixed>
Return values
array<string|int, mixed>

setClient()

Set/override the client

public setClient(Client $client) : $this
Parameters
$client : Client
Return values
$this

setCopyFields()

Set the copy fields

public setCopyFields(array<string|int, mixed> $copyField) : $this
Parameters
$copyField : array<string|int, mixed>
Return values
$this

setDefaultField()

Set the default field for this index

public setDefaultField(string $defaultField) : $this
Parameters
$defaultField : string
Return values
$this

setFilterFields()

Set the filter fields

public setFilterFields(array<string|int, mixed> $filterFields) : $this
Parameters
$filterFields : array<string|int, mixed>
Return values
$this

setFulltextFields()

Set the fulltext fields

public setFulltextFields(array<string|int, mixed> $fulltextFields) : $this
Parameters
$fulltextFields : array<string|int, mixed>
Return values
$this

setSortFields()

Set/override the sortable fields

public setSortFields(array<string|int, mixed> $sortFields) : $this
Parameters
$sortFields : array<string|int, mixed>
Return values
$this

setStoredFields()

Set/override the stored field list

public setStoredFields(array<string|int, mixed> $storedFields) : BaseIndex
Parameters
$storedFields : array<string|int, mixed>
Return values
BaseIndex

addAllFieldsByType()

Add all database-backed text fields as fulltext searchable fields.

protected addAllFieldsByType([string $dbType = DBString::class ]) : void

For every class included in the index, examines those classes and all parent looking for "DBText" database fields (Varchar, Text, HTMLText, etc) and adds them all as fulltext searchable fields.

Note, there is no check on boosting etc. That needs to be done manually.

Parameters
$dbType : string = DBString::class
Tags
throws
ReflectionException

addFulltextFieldsForClass()

Add all fields of a given type to the index

protected addFulltextFieldsForClass(array<string|int, mixed> $fields[, string $dbType = DBString::class ]) : void
Parameters
$fields : array<string|int, mixed>

The fields on the DataObject

$dbType : string = DBString::class

Class type the reflection should extend

Tags
throws
ReflectionException

        
On this page

Search results