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'
CREATE_TYPE
string
public
mixed
CREATE_TYPE
= 'create'
DELETE_TYPE
string
public
mixed
DELETE_TYPE
= 'delete'
DELETE_TYPE_ALL
Solr update types
public
mixed
DELETE_TYPE_ALL
= 'deleteall'
ID_FIELD
Unique ID in Solr
public
mixed
ID_FIELD
= 'id'
UPDATE_TYPE
string
public
mixed
UPDATE_TYPE
= 'update'
Properties
$admin
protected
Query
$admin
A core admin object
$baseIndexes
protected
array<string|int, mixed>
$baseIndexes
= []
Base indexes that exist
$client
protected
Client
$client
The current client
$debug
Add debugging information
protected
bool
$debug
= false
$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
coreCreate()
Create a new core
public
coreCreate( $core, ConfigStore $configStore) : bool
Parameters
- $core :
-
string - The name of the core
- $configStore : ConfigStore
Tags
Return values
boolcoreReload()
Reload the given core
public
coreReload( $core) : StatusResult|null
Parameters
Return values
StatusResult|nullcoreStatus()
Get the core status
public
coreStatus(string $core) : StatusResult|null
Parameters
- $core : string
Return values
StatusResult|nullcoreUnload()
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
Return values
ResultgetAdmin()
Get the admin query
public
getAdmin() : Query
Return values
QuerygetClient()
Get the client
public
getClient() : Client
Return values
ClientgetSolrVersion()
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
Return values
intgetValidClasses()
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
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
boolisValidClass()
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
Return values
boolsetAdmin()
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
selfsetDebug()
Set the debug mode
public
setDebug(bool $debug) : self
Parameters
- $debug : bool
Return values
selfupdateIndex()
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
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
Return values
bool|ResultcheckReflection()
Check if the class is instantiable
protected
checkReflection( $subindex) : bool
Parameters
Tags
Return values
boolfilterIndexes()
Filter enabled indexes down to valid indexes that can be instantiated or are allowed from config
protected
filterIndexes() : void
Tags
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
Return values
array<string|int, mixed>getFactory()
Get the document factory prepared
protected
getFactory(SS_List $items) : DocumentFactory
Parameters
- $items : SS_List
Return values
DocumentFactorygetUpdate()
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
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>