Esempio n. 1
0
 /**
  * Records the search engine 
  * @return type boolean true if the operation is successful
  */
 function search_engine_save()
 {
     $search_db_path = api_get_path(SYS_PATH) . 'searchdb';
     if (is_writable($search_db_path)) {
         $course_id = api_get_course_id();
         require_once api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php';
         require_once api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php';
         $ic_slide = new IndexableChunk();
         $ic_slide->addValue('title', $this->name);
         $ic_slide->addCourseId($course_id);
         $ic_slide->addToolId(TOOL_LEARNPATH);
         $xapian_data = array(SE_COURSE_ID => $course_id, SE_TOOL_ID => TOOL_LEARNPATH, SE_DATA => array('type' => SE_DOCTYPE_LEARNPATH, 'lp_id' => (int) $this->lp_id), SE_USER => (int) api_get_user_id());
         $ic_slide->xapian_data = serialize($xapian_data);
         //get the keyword
         $searchkey = new SearchEngineManager();
         $keyword = $searchkey->getKeyWord(TOOL_LEARNPATH, $this->lp_id);
         $add_extra_terms = $keyword . ' ';
         $file_content = $add_extra_terms;
         $ic_slide->addValue("content", $file_content);
         $di = new DokeosIndexer();
         isset($_POST['language']) ? $lang = Database::escape_string($_POST['language']) : ($lang = 'english');
         $di->connectDb(NULL, NULL, $lang);
         $di->addChunk($ic_slide);
         //index and return search engine  id
         $did = $di->index();
         if ($did) {
             // save it to db
             $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
             $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, search_did)
                                 VALUES (NULL , \'%s\', \'%s\', %s, %s)';
             $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_LEARNPATH, $this->lp_id, $did);
             api_sql_query($sql, __FILE__, __LINE__);
             return true;
         } else {
             return false;
         }
     }
 }