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. You must honor the reference of that call.

see \global\midcom_services_indexer_document
see \global\midcom_services_indexer_backend
see \global\midcom_services_indexer_filter
todo Batch indexing support
todo Write code examples
todo More elaborate class introduction.
package midcom.services

 Methods

__construct (\midcom_services_indexer_backend $backend)

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

$backend

\midcom_services_indexer_backendAn explicit indexer to initialize with.

delete (array $RIs)

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

Using GUIDs instead of RIs will delete all language versions

Parameters

$RIs

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

Returns

booleanIndicating success.

delete_all ($constraint)

Clear the index completely.

This will drop the current index.

Parameters

$constraint

Returns

booleanIndicating success.

enabled ()

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

Returns

booleanService state.

index (mixed $documents)

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

$documents

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

Returns

booleanIndicating success.

new_document (object $object)

This function tries 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 midcom_services_indexer_document_datamanager2.
  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.

todo Move to a full factory pattern here to save document php file parsings where possible. This means that all document creations will in the future be handled by this method.

Parameters

$object

object&$object The object for which a document instance is required, passed by reference.

Returns

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

query (string $query, \midcom_services_indexer_filter $filter)

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.

todo Refactor into multiple methods

Parameters

$query

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

$filter

\midcom_services_indexer_filterAn optional filter used to restrict the query.

Returns

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

_index_cast_to_document (\midcom_helper_datamanager2_datamanager $object)

Automatic helper which transforms a reference-passed object into an indexable document.

Where necessary (f.x. with the DM instances) automatic indexing of subclasses is done.

Note, that this is conceptually different from the public new_document operation: It might already trigger indexing of dependent objects: A datamanager instance for example will automatically reindex all BLOBs defined in the schema.

Parameters

$object

\midcom_helper_datamanager2_datamanager&$object A reference to the DM2 object

 Properties

 

\midcom_services_indexer_backend $_backend

The backend indexer implementation
 

boolean $_disabled

Flag for disabled indexing, set by the constructor.