protected function setUp()
 {
     $objObject = $this->createObject("class_module_system_aspect", "");
     self::$arrObjectIds[] = $objObject->getSystemid();
     $objSearchIndexWriter = new class_module_search_indexwriter();
     $objSearchIndexWriter->clearIndex();
     $objSearchDocument_1 = new class_module_search_document();
     $objSearchDocument_1->setStrSystemId($objObject->getSystemid());
     $objSearchDocument_1->setDocumentId(generateSystemid());
     $objSearchDocument_1->addContent("title", "hallo");
     $objSearchDocument_1->addContent("text", "welt");
     $objSearchDocument_1->addContent("subtitle", "blub");
     $objSearchDocument_1->addContent("text2", "blub");
     $objObject = $this->createObject("class_module_search_search", "");
     self::$arrObjectIds[] = $objObject->getSystemid();
     $objSearchDocument_2 = new class_module_search_document();
     $objSearchDocument_2->setStrSystemId($objObject->getSystemid());
     $objSearchDocument_2->setDocumentId(generateSystemid());
     $objSearchDocument_2->addContent("title", "hallo");
     $objSearchDocument_2->addContent("text", "welt");
     $objObject = $this->createObject("class_module_system_aspect", "");
     self::$arrObjectIds[] = $objObject->getSystemid();
     $objSearchDocument_3 = new class_module_search_document();
     $objSearchDocument_3->setStrSystemId($objObject->getSystemid());
     $objSearchDocument_3->setDocumentId(generateSystemid());
     $objSearchDocument_3->addContent("title", "lorem ipsum dolor ipsum");
     $objSearchDocument_3->addContent("text", "dolor ipsum sit amet, consetetur.");
     $objSearchIndexWriter->updateSearchDocumentToDb($objSearchDocument_1);
     $objSearchIndexWriter->updateSearchDocumentToDb($objSearchDocument_2);
     $objSearchIndexWriter->updateSearchDocumentToDb($objSearchDocument_3);
     parent::setUp();
 }
Exemplo n.º 2
0
 public function testIndexCreate()
 {
     $objSearchDocument = new class_module_search_document();
     $objSearchDocument->setDocumentId(1);
     $objSearchContent = new class_module_search_content();
     $objSearchContent->setFieldName('title');
     $objSearchContent->setContent('bla');
     $objSearchContent->setDocumentId(1);
     $objSearchDocument->addContentObj($objSearchContent);
     $objSearchContent = new class_module_search_content();
     $objSearchContent->setFieldName('title');
     $objSearchContent->setContent('blub');
     $objSearchContent->setDocumentId(1);
     $objSearchDocument->addContentObj($objSearchContent);
     $this->assertEquals(count($objSearchDocument->getContent()), 2, "manual added test");
     // test tokenizer
     $objSearchDocument->addContent("title", "hAha DUdub");
     $this->assertEquals(count($objSearchDocument->getContent()), 4);
     // test lowerize
     $this->assertEquals($objSearchDocument->getContent()[2]->getContent(), 'haha');
     $this->assertEquals($objSearchDocument->getContent()[3]->getContent(), 'dudub');
     // test id management
     $this->assertEquals($objSearchDocument->getContent()[2]->getDocumentId(), $objSearchDocument->getDocumentId(), "id management test");
     // test short entry ignoring
     $objSearchDocument->addContent("title", "in hIulk, It, fs fslong or.");
     $arrContent = $objSearchDocument->getContent();
     $this->assertEquals(count($arrContent), 6);
     $this->assertEquals($arrContent[4]->getContent(), 'hiulk');
     $this->assertEquals($arrContent[5]->getContent(), 'fslong');
     //test blacklisting
     $objSearchDocument2 = new class_module_search_document();
     $objSearchDocument2->setDocumentId(2);
     $objSearchDocument2->addContent("title", " this is allowed and this is not ");
     $arrContent = $objSearchDocument2->getContent();
     $this->assertEquals(count($arrContent), 3);
     $this->assertEquals($arrContent[0]->getContent(), 'this');
     $this->assertEquals($arrContent[0]->getScore(), 2);
     $this->assertEquals($arrContent[1]->getContent(), 'allowed');
     $this->assertEquals($arrContent[2]->getContent(), 'not');
 }
 /**
  * Triggers the indexing of a single object.
  *
  * @param class_model $objInstance
  *
  * @return void
  */
 public function indexObject(class_model $objInstance = null)
 {
     if (!self::isIndexAvailable()) {
         return;
     }
     if ($objInstance != null && $objInstance instanceof class_module_pages_pageelement) {
         $objInstance = $objInstance->getConcreteAdminInstance();
         if ($objInstance != null) {
             $objInstance->loadElementData();
         }
     }
     if ($objInstance == null) {
         return;
     }
     $objSearchDocument = new class_module_search_document();
     $objSearchDocument->setDocumentId(generateSystemid());
     $objSearchDocument->setStrSystemId($objInstance->getSystemid());
     if ($objInstance instanceof interface_search_portalobject) {
         $objSearchDocument->setBitPortalObject(true);
         $objSearchDocument->setStrContentLanguage($objInstance->getContentLang());
     }
     $objReflection = new class_reflection($objInstance);
     $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_ANNOTATION_ADDSEARCHINDEX);
     foreach ($arrProperties as $strPropertyName => $strAnnotationValue) {
         $getter = $objReflection->getGetter($strPropertyName);
         $strContent = $objInstance->{$getter}();
         $objSearchDocument->addContent($strPropertyName, $strContent);
     }
     //trigger event-listeners
     class_core_eventdispatcher::getInstance()->notifyGenericListeners(class_search_eventidentifier::EVENT_SEARCH_OBJECTINDEXED, array($objInstance, $objSearchDocument));
     $this->updateSearchDocumentToDb($objSearchDocument);
 }