\midcom_services_indexer

This class is the main access point into the MidCOM Indexer subsystem.

It allows you to maintain and query the document index.

Do not instantiate this class directly. Instead use the get_service method on midcom_application using the service name 'indexer' to obtain a running instance.

Summary

Methods
Properties
Constants
__construct()
getSubscribedEvents()
handle_delete()
enabled()
index()
delete()
delete_all()
query()
new_document()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$_backend
$_disabled
N/A

Properties

$_disabled

$_disabled : boolean

Flag for disabled indexing, set by the constructor.

Type

boolean

Methods

__construct()

__construct(\midcom_services_indexer_backend  $backend = null) 

Initialization

The constructor will initialize the indexer backend using the MidCOM configuration by default. If you need a different indexer backend, you can always explicitly instantiate a backend and pass it to the constructor. In that case you have to load the corresponding PHP file manually.

Parameters

\midcom_services_indexer_backend $backend

An explicit indexer to initialize with.

getSubscribedEvents()

getSubscribedEvents() 

enabled()

enabled() : boolean

Simple helper, returns true if the indexer service is online, false if it is disabled.

Returns

boolean —

Service state.

index()

index(mixed  $documents) : boolean

Adds a document to the index.

A finished document object must be passed to this object. If the index already contains a record with the same Resource Identifier, the record is replaced.

Support of batch-indexing using an Array of documents instead of a single document is possible (and strongly advised for performance reasons).

Parameters

mixed $documents

One or more documents to be indexed, so this is either a midcom_services_indexer_document or an Array of these objects.

Returns

boolean —

Indicating success.

delete()

delete(array  $RIs) : boolean

Removes the document(s) with the given resource identifier(s) from the index.

Using GUIDs instead of RIs will delete all language versions

Parameters

array $RIs

The resource identifier(s) of the document(s) that should be deleted.

Returns

boolean —

Indicating success.

delete_all()

delete_all(  $constraint = '') : boolean

Clear the index completely.

This will drop the current index.

Parameters

$constraint

Returns

boolean —

Indicating success.

query()

query(string  $query, \midcom_services_indexer_filter  $filter = null, array  $options = array()) : array<mixed,\midcom_services_indexer_document>

Query the index and, if set, restrict the query by a given filter.

The filter argument is optional and may be a subclass of indexer_filter. The backend determines what filters are supported and how they are treated.

The query syntax is also dependent on the backend. Refer to its documentation how queries should be built.

Parameters

string $query

The query, which must suit the backends query syntax. It is assumed to be in the site charset.

\midcom_services_indexer_filter $filter

An optional filter used to restrict the query.

array $options

Options that are passed straight to the backend

Returns

array<mixed,\midcom_services_indexer_document> —

An array of documents matching the query, or false on a failure.

new_document()

new_document(object  $object) : \midcom_services_indexer_document

Try to instantiate the most specific document class for the object given in the parameter.

This class will not return empty document base class instances if nothing specific can be found. If you are in this situation, you need to instantiate an appropriate document manually and populate it.

The checking sequence is like this right now:

  1. If a datamanager instance is passed, it is transformed into a datamanager document.
  2. If a Metadata object is passed, it is transformed into a midcom_services_indexer_document_midcom.
  3. Next, the method tries to retrieve a MidCOM Metadata object using the parameter directly. If successful, again, a midcom_services_indexer_document_midcom is returned.

This factory method will work even if the indexer is disabled. You can check this with the enabled() method of this class.

Parameters

object $object

The object for which a document instance is required

Returns

\midcom_services_indexer_document

A valid document class as specific as possible. Returns false on error or if no specific class match could be found.