Permalink
Browse files

renew of the global search engine

  • Loading branch information...
1 parent 3f7ebaf commit 918fb61f41f170c8d98227c38553b1c58bb2508b diml committed Jul 12, 2007
View
@@ -0,0 +1,15 @@
+This block is a revamping of the Google Summer Of Code Project (2006) on Global Search engine
+for Moodle. New block version is completed and internationalized according to Moodle multilengual support.
+
+This block instanciates a startup database model for the search engine.
+
+## Installing
+
+You need installing the following elements in order the global search to be available :
+
+1. The global search bloc (this block)
+2. update the /search root package from CVS
+3. The antiword libraries
+4. The xpdf libraries
+
+Both last libraries are provided as a patch called "global_search_libraries" in the contrib section.
@@ -14,8 +14,9 @@
class block_search extends block_base {
function init() {
- $this->title = "Global Search"; //get_string()
- $this->version = 2006062500;
+ $this->title = get_string('blockname', 'block_search');
+ $this->cron = 1;
+ $this->version = 2007062900;
} //init
// only one instance of this block is required
@@ -45,8 +46,8 @@ function get_content() {
//lazy check for the moment
if (check_php_version("5.0.0")) {
//fetch values if defined in admin, otherwise use defaults
- $label = (isset($CFG->block_search_text)) ? $CFG->block_search_text : "Search Moodle";
- $button = (isset($CFG->block_search_button)) ? $CFG->block_search_button : "Go";
+ $label = (isset($CFG->block_search_text)) ? $CFG->block_search_text : get_string('searchmoodle', 'block_search');
+ $button = (isset($CFG->block_search_button)) ? $CFG->block_search_button : get_string('go', 'block_search');
//basic search form
$this->content->text =
@@ -68,6 +69,16 @@ function get_content() {
function specialisation() {
//empty!
} //specialisation
+
+ /**
+ * wraps up to search engine cron
+ *
+ */
+ function cron(){
+ global $CFG;
+
+ include($CFG->dirroot.'/search/cron.php');
+ }
} //block_search
@@ -1,19 +1,132 @@
<div style="text-align:center;">
- <label for="block_search_text">Search label</label>
- <input id="block_search_text" type="text" name="block_search_text" value="<?php
- if(isset($CFG->block_search_text)) {
- p($CFG->block_search_text);
- } else {
- p("Search Moodle");
- } ?>"/><br/>
-
- <label for="block_search_button">Button label</label>
- <input id="block_search_button" type="text" name="block_search_button" value="<?php
- if(isset($CFG->block_search_button)) {
- p($CFG->block_search_button);
- } else {
- p("Go");
- } ?>"/><br/><br/>
-
- <input type="submit" value="<?php print_string('savechanges'); ?>" />
+<table cellspacing="5">
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configsearchtext', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_text" type="text" name="block_search_text" value="<?php
+ if(isset($CFG->block_search_text)) {
+ p($CFG->block_search_text);
+ } else {
+ p(get_string('searchmoodle', 'block_search'));
+ } ?>"/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configbuttonlabel', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_button" type="text" name="block_search_button" value="<?php
+ if(isset($CFG->block_search_button)) {
+ p($CFG->block_search_button);
+ } else {
+ p(get_string('go', 'block_search'));
+ } ?>"/><br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configenablefileindexing', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_enable_file_indexing" type="radio" name="block_search_enable_file_indexing" value="1" <?php
+ if(isset($CFG->block_search_enable_file_indexing) && $CFG->block_search_enable_file_indexing) {
+ echo " checked=\"checked\" ";
+ } ?> /> <?php print_string('yes') ?> -
+ <input id="block_search_enable_file_indexing" type="radio" name="block_search_enable_file_indexing" value="0" <?php
+ if(!isset($CFG->block_search_enable_file_indexing) || !$CFG->block_search_enable_file_indexing) {
+ echo " checked=\"checked\" ";
+ } ?> /> <?php print_string('no') ?>
+ <br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configfiletypes', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_filetypes" type="text" name="block_search_filetypes" value="<?php
+ if(isset($CFG->block_search_filetypes)) {
+ p($CFG->block_search_filetypes);
+ } else {
+ p("PDF,TXT,HTML,PPT,XML,DOC,HTM");
+ } ?>"/><br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configpdftotextcmd', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_pdf_to_text_cmd" type="text" size="60" name="block_search_pdf_to_text_cmd" value="<?php
+ if(isset($CFG->block_search_pdf_to_text_cmd)) {
+ p($CFG->block_search_pdf_to_text_cmd);
+ } else {
+ $encoding = ($CFG->unicodedb) ? "-enc UTF-8" : "-enc ISO-8859-1" ;
+ if ($CFG->ostype == 'WINDOWS'){
+ p("lib/xpdf/win32/pdftotext.exe -eol dos $encoding -q");
+ }
+ else{
+ p("lib/xpdf/linux/pdftotext $encoding -eol unix -q");
+ }
+ } ?>"/><br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configwordtotextcmd', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_word_to_text_cmd" type="text" size="60" name="block_search_word_to_text_cmd" value="<?php
+ if(isset($CFG->block_search_word_to_text_cmd)) {
+ p($CFG->block_search_word_to_text_cmd);
+ } else {
+ if ($CFG->ostype == 'WINDOWS'){
+ p("lib/antiword/win32/antiword/antiword.exe ");
+ }
+ else{
+ p("lib/antiword/linux/usr/bin/antiword");
+ }
+ } ?>"/><br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configwordtotextenv', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_word_to_text_env" type="text" size="60" name="block_search_word_to_text_env" value="<?php
+ if(isset($CFG->block_search_word_to_text_env)) {
+ echo stripslashes($CFG->block_search_word_to_text_env);
+ } else {
+ if ($CFG->ostype == 'WINDOWS'){
+ p("HOME={$CFG->dirroot}\\lib\\antiword\\win32");
+ }
+ else{
+ p("ANTIWORDHOME={$CFG->dirroot}/lib/antiword/linux/usr/share/antiword");
+ }
+ } ?>"/><br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configlimitindexbody', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_limit_index_body" type="text" size="8" name="block_search_limit_index_body" value="<?php
+ if(isset($CFG->block_search_limit_index_body)) {
+ p($CFG->block_search_limit_index_body);
+ } else {
+ p('');
+ } ?>"/> <?php print_string('bytes', 'block_search') ?><br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right" colspan="2">
+ <input type="submit" value="<?php print_string('savechanges'); ?>" />
+ </td>
+ </tr>
+</table>
</div>
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<XMLDB PATH="blocks/search/db" VERSION="20080801" COMMENT="XMLDB file for Moodle search engine">
+ <TABLES>
+ <TABLE NAME="search_documents" COMMENT="table to store search index backups">
+ <FIELDS>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="docid"/>
+ <FIELD NAME="docid" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="doctype"/>
+ <FIELD NAME="doctype" TYPE="char" LENGTH="32" NOTNULL="true" DEFAULT="'none'" SEQUENCE="false" ENUM="false" PREVIOUS="docid" NEXT="itemtype"/>
+ <FIELD NAME="itemtype" TYPE="char" LENGTH="32" NOTNULL="true" DEFAULT="'standard'" SEQUENCE="false" ENUM="false" PREVIOUS="doctype" NEXT="title"/>
+ <FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="''" SEQUENCE="false" ENUM="false" PREVIOUS="itemtype" NEXT="url"/>
+ <FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="''" SEQUENCE="false" ENUM="false" PREVIOUS="title" NEXT="docdate"/>
+ <FIELD NAME="docdate" TYPE="datetime" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="url" NEXT="updated"/>
+ <FIELD NAME="updated" TYPE="datetime" NOTNULL="true" DEFAULT="CURRENT_TIMESTAMP" SEQUENCE="false" ENUM="false" PREVIOUS="docdate" NEXT="courseid"/>
+ <FIELD NAME="courseid" TYPE="int" LENGTH="11" NOTNULL="true" DEFAULT="0" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="updated" NEXT="groupid"/>
+ <FIELD NAME="groupid" TYPE="int" LENGTH="11" NOTNULL="true" DEFAULT="0" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="courseid"/>
+ </FIELDS>
+ <KEYS>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for block"/>
+ </KEYS>
+ <INDEXES>
+ <INDEX NAME="mdl_search_docid" UNIQUE="false" FIELDS="docid" NEXT="mdl_search_doctype"/>
+ <INDEX NAME="mdl_search_doctype" UNIQUE="false" FIELDS="doctype" PREVIOUS="mdl_search_docid" NEXT="mdl_search_itemtype"/>
+ <INDEX NAME="mdl_search_itemtype" UNIQUE="false" FIELDS="itemtype" PREVIOUS="mdl_search_doctype"/>
+ </INDEXES>
+ </TABLE>
+ </TABLES>
+</XMLDB>
View
@@ -13,8 +13,14 @@ function search_upgrade($oldversion=0) {
$result = true;
- if ($oldversion < 2006062500 and $result) {
- $result = true; //Nothing to do
+ if ($oldversion < 2007080100 and $result) {
+ modify_database ("", "ALTER TABLE `{$CFG->prefix}search_documents` ADD `item_type` VARCHAR( 32 ) NOT NULL AFTER `doctype` ; ");
+ modify_database ("", "ALTER TABLE `{$CFG->prefix}search_documents` ADD INDEX ( `item_type` ) ; ");
+ modify_database ("", "ALTER TABLE `{$CFG->prefix}search_documents` CHANGE `doctype` `doctype` VARCHAR( 32 ) DEFAULT 'none' ; ");
+ modify_database ("", "ALTER TABLE `{$CFG->prefix}search_documents` CHANGE `title` `title` VARCHAR( 255 ) ; ");
+ modify_database ("", "ALTER TABLE `{$CFG->prefix}search_documents` CHANGE `url` `url` VARCHAR( 255 ) ; ");
+ modify_database ("", "ALTER TABLE `{$CFG->prefix}mdl_search_documents` CHANGE `docid` `docid` VARCHAR( 32 ) ; ");
+ $result = true;
}
////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.
View
@@ -0,0 +1,13 @@
+CREATE TABLE IF NOT EXISTS `prefix_search_documents` (
+ `id` int(11) NOT NULL auto_increment,
+ `docid` varchar(32) NOT NULL,
+ `doctype` varchar(32) NOT NULL default 'none',
+ `itemtype` varchar(32) NOT NULL default 'standard',
+ `title` varchar(255) NOT NULL default '',
+ `url` varchar(255) NOT NULL default '',
+ `docdate` timestamp NOT NULL default 0,
+ `updated` timestamp NOT NULL default CURRENT_TIMESTAMP,
+ `courseid` int(11) NOT NULL default 0,
+ `groupid` int(11) NOT NULL default 0,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=1;
@@ -13,7 +13,7 @@ function search_upgrade($oldversion=0) {
$result = true;
- if ($oldversion < 2006062500 and $result) {
+ if ($oldversion < 2007080100 and $result) {
$result = true; //Nothing to do
}
@@ -0,0 +1,12 @@
+CREATE TABLE prefix_search_documents (
+ id SERIAL8 PRIMARY KEY,
+ docid int4 NOT NULL,
+ doctype varchar(12) NOT NULL default 'none',
+ itemtype varchar(32) NOT NULL default 'standard',
+ title varchar(255) NOT NULL default '',
+ url varchar(255) NOT NULL default '',
+ docdate timestamp NOT NULL,
+ updated timestamp NOT NULL default NOW(),
+ courseid int4,
+ groupid int4
+);

0 comments on commit 918fb61

Please sign in to comment.