SilverStripe solr Search

SolrCoreService
in package
Uses Injectable, Configurable, CoreServiceTrait, CoreAdminTrait

Class SolrCoreService provides the base connection to Solr.

Default service to connect to Solr and handle all base requirements to support Solr. Default constants are available to support any set up.

Table of Contents

Constants

CLASS_ID_FIELD  = 'ObjectID'
SilverStripe ID of the object
CLASSNAME  = 'ClassName'
Name of the field that can be used for queries
CREATE_TYPE  = 'create'
string
DELETE_TYPE  = 'delete'
string
DELETE_TYPE_ALL  = 'deleteall'
Solr update types
ID_FIELD  = 'id'
Unique ID in Solr
UPDATE_TYPE  = 'update'
string

Properties

$admin  : Query
$baseIndexes  : array<string|int, mixed>
$client  : Client
$debug  : bool
Add debugging information
$solr_versions  : array<string|int, mixed>
$validIndexes  : array<string|int, mixed>

Methods

__construct()  : mixed
SolrCoreService constructor.
coreCreate()  : bool
Create a new core
coreReload()  : StatusResult|null
Reload the given core
coreStatus()  : StatusResult|null
Get the core status
coreUnload()  : StatusResult|null
Remove a core from Solr
doManipulate()  : Result
Execute the manipulation of solr documents
getAdmin()  : Query
Get the admin query
getClient()  : Client
Get the client
getSolrVersion()  : int
Check the Solr version to use In version compare, we have the following results: 1 means "result version is higher" 0 means "result version is equal" -1 means "result version is lower" We want to use the version "higher or equal to", because the configs are for version X-and-up.
getValidClasses()  : array<string|int, mixed>
Get all classes from all indexes and return them.
getValidIndexes()  : array<string|int, mixed>
Get valid indexes for the project
isDebug()  : bool
Check if we are in debug mode
isValidClass()  : bool
Is the given class a valid class to index Does not discriminate against the indexes. All indexes are worth the same
setAdmin()  : void
Set a (custom) admin query object
setClient()  : self
Set the client
setDebug()  : self
Set the debug mode
updateIndex()  : void
Create the documents and add to the update
updateItems()  : bool|Result
Update items in the list to Solr
checkReflection()  : bool
Check if the class is instantiable
filterIndexes()  : void
Filter enabled indexes down to valid indexes that can be instantiated or are allowed from config
getClassesInHierarchy()  : array<string|int, mixed>
Get the classes in hierarchy to see if it's valid
getFactory()  : DocumentFactory
Get the document factory prepared
getUpdate()  : mixed
get the update object ready
getSolrAuthentication()  : array<string|int, mixed>|array<string|int, array<string|int, mixed>>
This will add the authentication headers to the request.

Constants

CLASS_ID_FIELD

SilverStripe ID of the object

public mixed CLASS_ID_FIELD = 'ObjectID'

CLASSNAME

Name of the field that can be used for queries

public mixed CLASSNAME = 'ClassName'

DELETE_TYPE_ALL

Solr update types

public mixed DELETE_TYPE_ALL = 'deleteall'

Properties

$baseIndexes

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

Base indexes that exist

$solr_versions

protected static array<string|int, mixed> $solr_versions = ["9.0.0", "7.0.0", "5.0.0", "4.0.0"]

Available config versions

$validIndexes

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

Valid indexes out of the base indexes

Methods

__construct()

SolrCoreService constructor.

public __construct() : mixed
Tags
throws
ReflectionException

coreCreate()

Create a new core

public coreCreate( $core, ConfigStore $configStore) : bool
Parameters
$core :

string - The name of the core

$configStore : ConfigStore
Tags
throws
Exception
throws
HTTPException
Return values
bool

coreReload()

Reload the given core

public coreReload( $core) : StatusResult|null
Parameters
$core :
Return values
StatusResult|null

coreStatus()

Get the core status

public coreStatus(string $core) : StatusResult|null
Parameters
$core : string
Return values
StatusResult|null

coreUnload()

Remove a core from Solr

public coreUnload(string $core) : StatusResult|null
Parameters
$core : string

core name

Return values
StatusResult|null

A result is successful

doManipulate()

Execute the manipulation of solr documents

public doManipulate(SS_List $items,  $type, BaseIndex $index) : Result
Parameters
$items : SS_List
$type :
$index : BaseIndex
Tags
throws
Exception
Return values
Result

getAdmin()

Get the admin query

public getAdmin() : Query
Return values
Query

getClient()

Get the client

public getClient() : Client
Return values
Client

getSolrVersion()

Check the Solr version to use In version compare, we have the following results: 1 means "result version is higher" 0 means "result version is equal" -1 means "result version is lower" We want to use the version "higher or equal to", because the configs are for version X-and-up.

public getSolrVersion([HandlerStack|null $handler = null ]) : int

We loop through the versions available from high to low therefore, if the version is lower, we want to check the next config version

If no valid version is found, throw an error

Parameters
$handler : HandlerStack|null = null

Used for testing the solr version

Tags
throws
LogicException
Return values
int

getValidClasses()

Get all classes from all indexes and return them.

public getValidClasses() : array<string|int, mixed>

Used to get all classes that are to be indexed on change Note, only base classes are in this object. A publish recursive is required when any change from a relation is published.

Tags
throws
ReflectionException
throws
InvalidArgumentException
Return values
array<string|int, mixed>

getValidIndexes()

Get valid indexes for the project

public getValidIndexes([null|string $index = null ]) : array<string|int, mixed>
Parameters
$index : null|string = null
Return values
array<string|int, mixed>

isDebug()

Check if we are in debug mode

public isDebug() : bool
Return values
bool

isValidClass()

Is the given class a valid class to index Does not discriminate against the indexes. All indexes are worth the same

public isValidClass(string $class) : bool
Parameters
$class : string
Tags
throws
ReflectionException
throws
InvalidArgumentException
Return values
bool

setAdmin()

Set a (custom) admin query object

public setAdmin(Query $admin) : void
Parameters
$admin : Query

setClient()

Set the client

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

setDebug()

Set the debug mode

public setDebug(bool $debug) : self
Parameters
$debug : bool
Return values
self

updateIndex()

Create the documents and add to the update

public updateIndex(BaseIndex $index, SS_List $items, Query $update) : void
Parameters
$index : BaseIndex
$items : SS_List
$update : Query
Tags
throws
Exception

updateItems()

Update items in the list to Solr

public updateItems(SS_List|DataObject $items, string $type[, null|string $index = null ]) : bool|Result
Parameters
$items : SS_List|DataObject
$type : string
$index : null|string = null
Tags
throws
ReflectionException
throws
Exception
Return values
bool|Result

checkReflection()

Check if the class is instantiable

protected checkReflection( $subindex) : bool
Parameters
$subindex :
Tags
throws
ReflectionException
Return values
bool

filterIndexes()

Filter enabled indexes down to valid indexes that can be instantiated or are allowed from config

protected filterIndexes() : void
Tags
throws
ReflectionException

getClassesInHierarchy()

Get the classes in hierarchy to see if it's valid

protected getClassesInHierarchy(string $index, array<string|int, mixed> $classes) : array<string|int, mixed>
Parameters
$index : string

Index to check classes for

$classes : array<string|int, mixed>

Classes to get hierarchy for

Tags
throws
ReflectionException
Return values
array<string|int, mixed>

getUpdate()

get the update object ready

protected getUpdate(SS_List $items, string $type, BaseIndex $index, Client $client) : mixed
Parameters
$items : SS_List
$type : string
$index : BaseIndex
$client : Client
Tags
throws
Exception

getSolrAuthentication()

This will add the authentication headers to the request.

private getSolrAuthentication(array<string|int, mixed> $firstEndpoint) : array<string|int, mixed>|array<string|int, array<string|int, mixed>>

It's intended to become a helper in the end.

Parameters
$firstEndpoint : array<string|int, mixed>
Return values
array<string|int, mixed>|array<string|int, array<string|int, mixed>>

        
On this page

Search results