VuFind API Documentation

Connector
in package
implements LoggerAwareInterface Uses LoggerAwareTrait, ConnectorCacheTrait

SOLR connector.

Tags
category

VuFind

author

Andrew S. Nagy vufind-tech@lists.sourceforge.net

author

David Maus maus@hab.de

author

Demian Katz demian.katz@villanova.edu

license

http://opensource.org/licenses/gpl-2.0.php GNU General Public License

link
https://vufind.org

Interfaces, Classes, Traits and Enums

LoggerAwareInterface

Table of Contents

MAX_GET_URL_LENGTH  = 2048
Maximum length of a GET url.
$cache  : StorageInterface
Request cache
$clientFactory  : callable
HTTP client factory
$lastUrl  : Http|null
Url of the last request
$map  : HandlerMap
Handler map.
$uniqueKey  : string
Solr field used to store unique identifier
$url  : string|array<string|int, mixed>
URL or an array of alternative URLs of the SOLR core.
__construct()  : mixed
Constructor
callWithHttpOptions()  : mixed
Call a method with provided options for the HTTP client
getCachedData()  : mixed
Get a request from cache if available
getCacheKey()  : string
Create a cache key from client's request state
getCore()  : string
Extract the Solr core from the connector's URL.
getLastUrl()  : Http|null
Get the last request url.
getMap()  : HandlerMap
Return handler map.
getUniqueKey()  : string
Get unique key.
getUrl()  : string
Get the Solr URL.
query()  : string
Send query to SOLR and return response body.
resetLastUrl()  : void
Clears the last url
retrieve()  : string
Return document specified by id.
search()  : string
Execute a search.
setCache()  : void
Set the cache storage
similar()  : string
Return records similar to a given record specified by id.
terms()  : string
Extract terms from a SOLR index.
write()  : string
Write to the SOLR index.
debug()  : void
Log a debug message.
forceToBackendException()  : Exception
If an unexpected exception type was received, wrap it in a generic BackendException to standardize upstream handling.
isRethrowableSolrException()  : bool
Check if an exception from a Solr request should be thrown rather than retried
log()  : void
Send a message to the logger.
logCacheDebug()  : void
Log a debug message
logCacheWarning()  : void
Log a warning message
logError()  : void
Log an error message.
logWarning()  : void
Log a warning message.
putCachedData()  : void
Cache response data.
send()  : string
Send request the SOLR and return the response.
trySolrUrls()  : string
Try all Solr URLs until we find one that works (or throw an exception).

Constants

MAX_GET_URL_LENGTH

Maximum length of a GET url.

public int MAX_GET_URL_LENGTH = 2048

Switches to POST if the SOLR target URL exceeds this length.

Tags
see
Connector::query()

Properties

$clientFactory

HTTP client factory

protected callable $clientFactory

$lastUrl

Url of the last request

protected Http|null $lastUrl = null

$uniqueKey

Solr field used to store unique identifier

protected string $uniqueKey

$url

URL or an array of alternative URLs of the SOLR core.

protected string|array<string|int, mixed> $url

Methods

__construct()

Constructor

public __construct(string|array<string|int, mixed> $url, HandlerMap $map, callable|Client $cf[, string $uniqueKey = 'id' ]) : mixed
Parameters
$url : string|array<string|int, mixed>

SOLR core URL or an array of alternative URLs

$map : HandlerMap

Handler map

$cf : callable|Client

HTTP client factory or a client to clone

$uniqueKey : string = 'id'

Solr field used to store unique identifier

Return values
mixed

callWithHttpOptions()

Call a method with provided options for the HTTP client

public callWithHttpOptions(array<string|int, mixed> $options, string $method, array<string|int, mixed> ...$args) : mixed
Parameters
$options : array<string|int, mixed>

HTTP client options

$method : string

Method to call

$args : array<string|int, mixed>

Method parameters

Return values
mixed

getCachedData()

Get a request from cache if available

public getCachedData(string $key) : mixed
Parameters
$key : string

Cache key

Return values
mixed

getCacheKey()

Create a cache key from client's request state

public getCacheKey(Client $client) : string
Parameters
$client : Client

HTTP Client

Return values
string

getCore()

Extract the Solr core from the connector's URL.

public getCore() : string
Return values
string

getLastUrl()

Get the last request url.

public getLastUrl() : Http|null
Return values
Http|null

getUniqueKey()

Get unique key.

public getUniqueKey() : string
Return values
string

getUrl()

Get the Solr URL.

public getUrl() : string
Return values
string

query()

Send query to SOLR and return response body.

public query(string $handler, ParamBag $params[, bool $cacheable = false ]) : string
Parameters
$handler : string

SOLR request handler to use

$params : ParamBag

Request parameters

$cacheable : bool = false

Whether the query is cacheable

Return values
string

Response body

resetLastUrl()

Clears the last url

public resetLastUrl() : void
Return values
void

retrieve()

Return document specified by id.

public retrieve(string $id[, ParamBag $params = null ]) : string
Parameters
$id : string

The document to retrieve from Solr

$params : ParamBag = null

Parameters

Return values
string

Execute a search.

public search(ParamBag $params) : string
Parameters
$params : ParamBag

Parameters

Return values
string

setCache()

Set the cache storage

public setCache(StorageInterface $cache) : void
Parameters
$cache : StorageInterface

Cache

Return values
void

similar()

Return records similar to a given record specified by id.

public similar(string $id, ParamBag $params) : string

Uses MoreLikeThis Request Component or MoreLikeThis Handler

Parameters
$id : string

ID of given record (not currently used, but retained for backward compatibility / extensibility).

$params : ParamBag

Parameters

Tags
SuppressWarnings

(PHPMD.UnusedFormalParameter)

Return values
string

terms()

Extract terms from a SOLR index.

public terms(ParamBag $params) : string
Parameters
$params : ParamBag

Parameters

Return values
string

write()

Write to the SOLR index.

public write(DocumentInterface $document[, string $handler = 'update' ][, ParamBag $params = null ]) : string
Parameters
$document : DocumentInterface

Document to write

$handler : string = 'update'

Update handler

$params : ParamBag = null

Update handler parameters

Return values
string

Response body

debug()

Log a debug message.

protected debug(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
$msg : string

Log message

$context : array<string|int, mixed> = []

Log context

$prependClass : bool = true

Prepend class name to message?

Return values
void

forceToBackendException()

If an unexpected exception type was received, wrap it in a generic BackendException to standardize upstream handling.

protected forceToBackendException(Exception $ex) : Exception
Parameters
$ex : Exception

Exception

Return values
Exception

isRethrowableSolrException()

Check if an exception from a Solr request should be thrown rather than retried

protected isRethrowableSolrException(Exception $ex) : bool
Parameters
$ex : Exception

Exception

Return values
bool

log()

Send a message to the logger.

protected log(string $level, string $message[, array<string|int, mixed> $context = [] ][, bool $prependClass = false ]) : void
Parameters
$level : string

Log level

$message : string

Log message

$context : array<string|int, mixed> = []

Log context

$prependClass : bool = false

Prepend class name to message?

Return values
void

logCacheDebug()

Log a debug message

protected logCacheDebug(string $msg) : void
Parameters
$msg : string

Message

Return values
void

logCacheWarning()

Log a warning message

protected logCacheWarning(string $msg) : void
Parameters
$msg : string

Message

Return values
void

logError()

Log an error message.

protected logError(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
$msg : string

Log message

$context : array<string|int, mixed> = []

Log context

$prependClass : bool = true

Prepend class name to message?

Return values
void

logWarning()

Log a warning message.

protected logWarning(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
$msg : string

Log message

$context : array<string|int, mixed> = []

Log context

$prependClass : bool = true

Prepend class name to message?

Return values
void

putCachedData()

Cache response data.

protected putCachedData(string $key, mixed $response) : void
Parameters
$key : string

Cache entry key

$response : mixed

Response to be cached

Return values
void

send()

Send request the SOLR and return the response.

protected send(Client $client) : string
Parameters
$client : Client

Prepared HTTP client

Tags
throws
RemoteErrorException

SOLR signaled a server error (HTTP 5xx)

throws
RequestErrorException

SOLR signaled a client error (HTTP 4xx)

Return values
string

Response body

trySolrUrls()

Try all Solr URLs until we find one that works (or throw an exception).

protected trySolrUrls(string $method, string $urlSuffix[, callable $callback = null ][, bool $cacheable = false ]) : string
Parameters
$method : string

HTTP method to use

$urlSuffix : string

Suffix to append to all URLs tried

$callback : callable = null

Callback to configure client (null for none)

$cacheable : bool = false

Whether the request is cacheable

Tags
throws
RemoteErrorException

SOLR signaled a server error (HTTP 5xx)

throws
RequestErrorException

SOLR signaled a client error (HTTP 4xx)

Return values
string

Response body

Search results