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'); }
/** * @param class_module_search_document $objSearchDoc * @return void */ public function updateSearchDocumentToDb(class_module_search_document $objSearchDoc) { if (!self::isIndexAvailable()) { return; } // Delete existing entries if (!$this->bitSkipDeletes) { $this->removeRecordFromIndex($objSearchDoc->getStrSystemId()); } if (count($objSearchDoc->getContent()) == 0) { return; } //insert search document $strQuery = "INSERT INTO " . _dbprefix_ . "search_ix_document\r\n (search_ix_document_id, search_ix_system_id, search_ix_content_lang, search_ix_portal_object) VALUES\r\n (?, ?, ?, ?)"; $this->objDB->_pQuery($strQuery, array($objSearchDoc->getDocumentId(), $objSearchDoc->getStrSystemId(), $objSearchDoc->getStrContentLanguage(), $objSearchDoc->getBitPortalObject() ? 1 : 0)); $this->updateSearchContentsToDb($objSearchDoc->getContent()); }