コード例 #1
0
 public static function addInformationObjectIndex(QubitInformationObject $informationObject, $language, $options = array())
 {
     // Only ROOT node should have no parent, don't index
     if (null === $informationObject->parent) {
         return;
     }
     $doc = new Zend_Search_Lucene_Document();
     // Reference elements
     $doc->addField(Zend_Search_Lucene_Field::Keyword('id', $informationObject->id));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('slug', $informationObject->slug));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('culture', $language));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('className', 'QubitInformationObject'));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('parentId', $informationObject->parentId));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('parent', $informationObject->parent->slug));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('collectionRootId', $informationObject->getCollectionRoot()->id));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('collectionRootSlug', $informationObject->getCollectionRoot()->slug));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('collectionRootTitle', $informationObject->getCollectionRoot()->getTitle()));
     // Digital object information
     if ($digitalObject = $informationObject->getDigitalObject()) {
         $doc->addField(Zend_Search_Lucene_Field::Keyword('hasDigitalObject', 'true'));
         $doc->addField(Zend_Search_Lucene_Field::Keyword('do_mediaTypeId', $digitalObject->mediaTypeId));
         if (null !== $digitalObject->thumbnail) {
             $doc->addField(Zend_Search_Lucene_Field::UnIndexed('do_thumbnail_FullPath', $digitalObject->thumbnail->getFullPath()));
         }
         // $doc->addField(Zend_Search_Lucene_Field::Unstored('mediatype', $digitalObject->getMediaType()->getName(array('culture' => $language))));
         // $doc->addField(Zend_Search_Lucene_Field::Unstored('filename', $digitalObject->getName()));
         // $doc->addField(Zend_Search_Lucene_Field::Unstored('mimetype', $digitalObject->mimeType));
     } else {
         $doc->addField(Zend_Search_Lucene_Field::Keyword('hasDigitalObject', 'false'));
     }
     // Title
     // include an i18n fallback for proper search result display in case the title field was not translated
     if (0 < strlen($informationObject->getTitle(array('culture' => $language)))) {
         $titleField = Zend_Search_Lucene_Field::Text('title', $informationObject->getTitle(array('culture' => $language)));
     } else {
         $titleField = Zend_Search_Lucene_Field::Text('title', $informationObject->getTitle(array('sourceCulture' => true)));
     }
     // Boost the hit relevance for the title field
     $titleField->boost = 10;
     $doc->addField($titleField);
     // Publication status
     $doc->addField(Zend_Search_Lucene_Field::Text('publicationStatusId', $informationObject->getPublicationStatus()->status->id));
     $doc->addField(Zend_Search_Lucene_Field::Text('scopeAndContent', $informationObject->getScopeAndContent(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Text('referenceCode', $informationObject->referenceCode));
     // Store dates as serialized array
     $dates = array();
     foreach ($informationObject->getDates() as $date) {
         $save_date['id'] = $date->id;
         $save_date['rendered'] = Qubit::renderDateStartEnd($date->getDate(array('cultureFallback' => true)), $date->startDate, $date->endDate);
         $save_date['type'] = $date->getType(array('cultureFallback' => true))->__toString();
         if (isset($date->actor)) {
             $save_date['actor'] = $date->actor->__toString();
         }
         $dates[] = $save_date;
     }
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('dates', serialize($dates)));
     // CREATOR
     $creatorField = Zend_Search_Lucene_Field::Unstored('creator', $informationObject->getCreatorsNameString(array('culture' => $language)));
     // Boost the hit relevance for the creator field
     $creatorField->boost = 8;
     $doc->addField($creatorField);
     $doc->addField(Zend_Search_Lucene_Field::Unstored('creatorhistory', $informationObject->getCreatorsHistoryString(array('culture' => $language))));
     // Level of Description
     if (null !== $informationObject->getLevelOfDescription()) {
         $doc->addField(Zend_Search_Lucene_Field::Text('levelOfDescription', $informationObject->getLevelOfDescription()->getName(array('culture' => $language))));
     } else {
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('levelOfDescription', null));
     }
     // Repository
     $repository = $informationObject->getRepository(array('inherit' => true));
     if (null !== $repository) {
         $doc->addField(Zend_Search_Lucene_Field::Keyword('repositoryId', $repository->id));
         $doc->addField(Zend_Search_Lucene_Field::Keyword('repositorySlug', $repository->slug));
         $doc->addField(Zend_Search_Lucene_Field::Text('repositoryName', $repository->getAuthorizedFormOfName(array('culture' => $language))));
     } else {
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('repositoryId', null));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('repositorySlug', null));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('repositoryName', null));
     }
     // Identifier
     $identifierField = Zend_Search_Lucene_Field::Text('identifier', $informationObject->getIdentifier());
     $identifierField->boost = 5;
     $doc->addField($identifierField);
     // I18n fields
     $doc->addField(Zend_Search_Lucene_Field::Unstored('alternatetitle', $informationObject->getAlternateTitle(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('edition', $informationObject->getEdition(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('extentandmedium', $informationObject->getExtentAndMedium(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('archivalhistory', $informationObject->getArchivalHistory(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('acquisition', $informationObject->getAcquisition(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('appraisal', $informationObject->getAppraisal(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('accruals', $informationObject->getAccruals(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('arrangement', $informationObject->getArrangement(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('accessconditions', $informationObject->getAccessConditions(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('reproductionconditions', $informationObject->getReproductionConditions(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('physicalcharacteristics', $informationObject->getPhysicalCharacteristics(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('findingaids', $informationObject->getFindingAids(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('locationoforiginals', $informationObject->getLocationOfOriginals(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('locationofcopies', $informationObject->getLocationOfCopies(array('culture' => $language))));
     $doc->addField(Zend_Search_Lucene_Field::Unstored('relatedunitsofdescription', $informationObject->getRelatedUnitsOfDescription(array('culture' => $language))));
     // Subjects
     $subjectField = Zend_Search_Lucene_Field::Unstored('subject', $informationObject->getAccessPointsString(QubitTaxonomy::SUBJECT_ID, array('culture' => $language)));
     // Boost the hit relevance for the subject field
     $subjectField->boost = 5;
     $doc->addField($subjectField);
     // Place
     $placeField = Zend_Search_Lucene_Field::Unstored('place', $informationObject->getAccessPointsString(QubitTaxonomy::PLACE_ID, array('culture' => $language)));
     // Boost the hit relevance for the place field
     $placeField->boost = 3;
     $doc->addField($placeField);
     // Names
     $nameField = Zend_Search_Lucene_Field::Unstored('name', $informationObject->getNameAccessPointsString(array('culture' => $language)));
     // Boost the hit relevance for the place field
     $nameField->boost = 3;
     $doc->addField($nameField);
     $cultureInfo = sfCultureInfo::getInstance($language);
     $languages = $cultureInfo->getLanguages();
     $scripts = $cultureInfo->getScripts();
     // Languages
     if (0 < count($properties = $informationObject->getProperties($name = 'language'))) {
         $languageCodes = unserialize($properties->offsetGet(0)->getValue(array('sourceCulture' => true)));
         if (0 < count($languageCodes)) {
             $languageString = '';
             foreach ($languageCodes as $languageCode) {
                 $languageString .= $languages[$languageCode] . ' ';
             }
             $doc->addField(Zend_Search_Lucene_Field::Unstored('language', rtrim($languageString)));
         }
     }
     // Scripts
     if (0 < count($properties = $informationObject->getProperties($name = 'script'))) {
         $scriptCodes = unserialize($properties->offsetGet(0)->getValue(array('sourceCulture' => true)));
         if (0 < count($scriptCodes)) {
             $scriptString = '';
             foreach ($scriptCodes as $scriptCode) {
                 $scriptString .= $scripts[$scriptCode] . ' ';
             }
             $doc->addField(Zend_Search_Lucene_Field::Unstored('script', rtrim($scriptString)));
         }
     }
     // Notes
     if (0 < count($notes = $informationObject->getNotes())) {
         $noteString = '';
         foreach ($notes as $note) {
             $noteString .= $note->getContent(array('culture' => $language)) . ' ';
         }
         $doc->addField(Zend_Search_Lucene_Field::Unstored('notes', $noteString));
     }
     // Exclude control area fields for now, maybe add a seperate index for administrative data?
     // (institution_responsible_identifier, rules, sources, revision_history)
     // To come:
     // Add all dynamic metadata fields to index
     self::getInstance()->getEngine()->getIndex()->addDocument($doc);
 }