mixed) */ private $properties = array(); /** * Constructs a new search session that works on the handler $handler. * * The $manager provides valid search document definitions to the * session. The $handler will be used to perform all search operations. * * @param ezcSearchHandler $handler * @param ezcSearchDefinitionManager $manager */ public function __construct( ezcSearchHandler $handler, ezcSearchDefinitionManager $manager ) { $this->properties['handler'] = $handler; $this->properties['definitionManager'] = $manager; } /** * Returns the result of the search query $query as a list of objects. * * Returns the documents found for document type $type using the submitted * $query. $query should be created using {@link createFindQuery()}. * * Example: * * $q = $session->createFindQuery(); * $allPersons = $session->find( $q ); * * * If you are retrieving large result set, consider using {@link * findIterator()} instead. * * Example: * * $q = $session->createFindQuery(); * $documents = $session->findIterator( $q ); * * foreach ( $documents as $document ) * { * // ... * } * * * @throws ezcSearchDefinitionNotFoundException * if there is no such persistent class. * @throws ezcSearchQueryException * if the find query failed. * * @param ezcSearchQuery $query * @param string $type * * @return array(object($class)) */ public function find( ezcSearchQuery $query ) { return $this->handler->find( $query ); } /** * Returns the result of $query for the $class as an iterator. * * This method is similar to {@link find()} but returns an {@link * ezcSearchFindIterator} instead of an array of documents. This is * useful if you are going to loop over the documents and just need them one * at the time. Because you only instantiate one document it is faster than * {@link find()}. * * @throws ezcSearchDefinitionNotFoundException * if there is no such persistent class. * @throws ezcSearchQueryException * if the find query failed. * * @param ezcSearchQuery $query * @param string $type * * @return ezcSearchFindIterator */ public function findIterator( ezcSearchQuery $query, $type ) { return $this->handler->findIterator( $query, $type ); } /** * Returns a search query for the given document type $type. * * The query is initialized to fetch all properties. * * Example: * * $q = $session->createFindQuery( 'Person' ); * $allPersons = $session->find( $q, 'Person' ); * * * @throws ezcSearchException * if there is no such document type. * * @param string $type * * @return ezcSearchFindQuery */ public function createFindQuery( $type ) { $def = $this->definitionManager->fetchDefinition( $type ); /* We add the ezcsearch_type field to the definition automatically here */ $def->fields['ezcsearch_type'] = new ezcSearchDefinitionDocumentField( 'ezcsearch_type', ezcSearchDocumentDefinition::STRING ); return $this->handler->createFindQuery( $type, $def ); } /** * Starts a transaction for indexing. * * When using a transaction, the amount of processing that the search * backend does decreases, increasing indexing performance. Without this, * the component sends a commit after every document that is indexed. * Transactions can be nested, when commit() is called the same number of * times as beginTransaction(), the component sends a commit. */ public function beginTransaction() { $this->handler->beginTransaction(); } /** * Ends a transaction and calls commit. * * @throws ezcSearchTransactionException if no transaction is active. */ public function commit() { $this->handler->commit(); } /** * Indexes the new document $document to the search index. * * @throws ezcSearchException if $document * is not of a valid document type. * @throws ezcSearchException * if it was not possible to generate a unique identifier for the * new object. * @throws ezcSearchException * if the indexing failed. * * @param object $document */ public function index( $document ) { $class = get_class( $document ); $def = $this->definitionManager->fetchDefinition( $class ); $state = $document->getState(); if ( $state[$def->idProperty] == null ) { $document->setState( array( $def->idProperty => uniqid() ) ); } $this->handler->index( $def, $document->getState() ); } /** * Indexes a new document after removing the old one first. * * @throws ezcSearchDefinitionNotFoundException if $document is not of a valid document type. * @throws ezcSearchDocumentNotAvailableException if $document is not stored in the database already. * @param object $document * @return void */ public function update( $document ) { $this->delete( $document ); return $this->index( $document ); } /** * Deletes the document $document from the index. * * @throws ezcSearchDefinitionNotFoundxception * if the object is not recognized as valid document type. * @throws ezcSearchDocumentNotAvailableException if $document is not stored in the database already * @throws ezcSearchQueryException * if the object could not be deleted. * * @param object $document The document to delete */ public function delete( $document ) { return $this->deleteHandler->delete( $document ); } /** * Deletes documents using the query $query. * * The $query should be created using {@link createDeleteQuery()}. * * @throws ezcSearchQueryException * if the delete query failed. * * @param ezcSearchDeleteQuery $query */ public function deleteFromQuery( ezcSearchDeleteQuery $query ) { return $this->deleteHandler->deleteFromQuery( $query ); } /** * Returns a delete query for the given document type $type. * * Example: * * $q = $session->createDeleteQuery( 'Person' ); * $q->where( $q->gt( 'age', $q->bindValue( 15 ) ) ); * $session->deleteFromQuery( $q ); * * * @throws ezcSearchException * if there is no such document type. * * @param string $type * * @return ezcQueryDelete */ public function createDeleteQuery( $type ) { return $this->deleteHandler->createDeleteQuery( $type ); } /** * Sets the property $name to $value. * * @throws ezcBasePropertyNotFoundException if the property does not exist. * @throws ezcBasePropertyPermissionException if a read-only property is * tried to be modified. * * @param string $name * @param mixed $value * * @ignore */ public function __set( $name, $value ) { switch ( $name ) { case 'definitionManager': case 'handler': throw new ezcBasePropertyPermissionException( $name, ezcBasePropertyPermissionException::READ ); default: throw new ezcBasePropertyNotFoundException( $name ); break; } } /** * Property get access. * * Simply returns a given property. * * @param string $propertyName The name of the property to get. * @return mixed The property value. * * @throws ezcBasePropertyNotFoundException * if the given property does not exist. * @throws ezcBasePropertyPermissionException * if the property to be set is a write-only property. * * @ignore */ public function __get( $propertyName ) { if ( $this->__isset( $propertyName ) === true ) { return $this->properties[$propertyName]; } throw new ezcBasePropertyNotFoundException( $propertyName ); } /** * Returns if a property exists. * * Returns true if the property exists in the {@link $properties} array * (even if it is null) and false otherwise. * * @param string $propertyName Option name to check for. * @return void * @ignore */ public function __isset( $propertyName ) { return array_key_exists( $propertyName, $this->properties ); } } ?>