Permalink
Browse files

General updates, see README.txt.

  • Loading branch information...
1 parent d9e1bf2 commit b585dc5fcb001ca52b35f9e8792d1af80e5823f7 mchampan committed Jul 25, 2006
View
@@ -1,7 +1,23 @@
+2006/07/25
+----------
+Query logic moved into the SearchQuery class in querylib.php. Should be able
+to include this file in any page and run a query against the index (PHP 5
+checks must be added to those pages then, though).
+
+Index info can be retrieved using IndexInfo class in indexlib.php.
+
+Abstracted some stuff away, to reduce rendundancy and decrease the
+likelihood of errors. Improved the stats.php page to include some
+diagnostics for adminstrators.
+
+delete.php skeleton created for removing deleted documents from the
+index. cron.php will contain the logic for running delete.php,
+update.php and eventually add.php.
+
2006/07/11
----------
(Warning: It took me 1900 seconds to index the forum, go make coffee
-whilst you wait.)
+whilst you wait.) [Moodle.org forum data]
Forum search functions changed to use 'get_recordset' instead of
'get_records', for speed reasons. This provides a significant improvement,
@@ -430,7 +430,7 @@ public function getTermInfo($term)
$freqPointer = $prevTermInfo->freqPointer;
$proxPointer = $prevTermInfo->proxPointer;
for ($count = $prevPosition*$indexInterval + 1;
- $count < $termCount &&
+ $count <= $termCount &&
( $this->_getFieldPosition($termFieldNum) < $searchDicField ||
($this->_getFieldPosition($termFieldNum) == $searchDicField &&
strcmp($termValue, $term->text) < 0) );
@@ -64,7 +64,16 @@ public function __construct($inputString)
$currentToken = '';
for ($count = 0; $count < strlen($inputString); $count++) {
- if (ctype_alnum( $inputString{$count} )) {
+ if (ctype_alnum( $inputString{$count} ) ||
+ $inputString{$count} == '_') {
+ $currentToken .= $inputString{$count};
+ } else if ($inputString{$count} == '\\') { // Escaped character
+ $count++;
+
+ if ($count == strlen($inputString)) {
+ throw new Zend_Search_Lucene_Exception('Non finished escape sequence.');
+ }
+
$currentToken .= $inputString{$count};
} else {
// Previous token is finished
@@ -3,7 +3,7 @@
* extend.
* */
- class SearchDocument extends Zend_Search_Lucene_Document {
+ abstract class SearchDocument extends Zend_Search_Lucene_Document {
public function __construct(&$doc, &$data, $document_type, $course_id, $group_id) {
$this->addField(Zend_Search_Lucene_Field::Keyword('id', $doc->id));
$this->addField(Zend_Search_Lucene_Field::Text('title', $doc->title));
@@ -7,12 +7,7 @@
class ForumSearchDocument extends SearchDocument {
public function __construct(&$post, $forum_id, $course_id, $group_id) {
- // generic information
- /*$doc->id = $post->id;
- $doc->title = $post->subject;
- $doc->author = $post->firstname." ".$post->lastname;
- $doc->contents = $post->message;*/
-
+ // generic information
$doc->id = $post['id'];
$doc->title = $post['subject'];
$doc->author = $post['firstname']." ".$post['lastname'];
@@ -24,7 +19,7 @@ public function __construct(&$post, $forum_id, $course_id, $group_id) {
$data->forum = $forum_id;
$data->discussion = $post['discussion'];
- parent::__construct($doc, $data, SEARCH_FORUM_TYPE, $course_id, $group_id);
+ parent::__construct($doc, $data, SEARCH_TYPE_FORUM, $course_id, $group_id);
} //constructor
} //ForumSearchDocument
@@ -34,7 +29,7 @@ function forum_make_link($discussion_id, $post_id) {
} //forum_make_link
function forum_iterator() {
- //no @ = Undefined index: 82 in /home/michael/public_html/moodle/lib/datalib.php on line 2671
+ //no @ = Undefined index: 82 in moodle/lib/datalib.php on line 2671
return @get_all_instances_in_courses("forum", get_courses());
} //forum_iterator
@@ -72,33 +67,6 @@ function forum_get_content_for_index(&$forum) {
return $documents;
} //forum_get_content_for_index
- //old slower version
- function forum_get_content_for_index_old(&$forum) {
- $documents = array();
- if (!$forum) return $documents;
-
- $posts = forum_get_discussions($forum->id);
- if (!$posts) return $documents;
-
- foreach($posts as $post) {
- if (is_object($post)) {
- if (strlen($post->message) > 0 && ($post->deleted != 1)) {
- $documents[] = new ForumSearchDocument($post, $forum->id, $forum->course, $post->groupid);
- } //if
-
- if ($children = forum_get_child_posts($post->id, $forum->id)) {
- foreach ($children as $child) {
- if (strlen($child->message) > 0 && ($child->deleted != 1)) {
- $documents[] = new ForumSearchDocument($child, $forum->id, $forum->course, $post->groupid);
- } //if
- } //foreach
- } //if
- } //if
- } //foreach
-
- return $documents;
- } //forum_get_content_for_index_old
-
//reworked faster version from /mod/forum/lib.php
function forum_get_discussions_fast($forum) {
global $CFG, $USER;
@@ -32,7 +32,7 @@ public function __construct(&$page, $wiki_id, $course_id, $group_id) {
$data->wiki = $wiki_id;
// construct the parent class
- parent::__construct($doc, $data, SEARCH_WIKI_TYPE, $course_id, $group_id);
+ parent::__construct($doc, $data, SEARCH_TYPE_WIKI, $course_id, $group_id);
} //constructor
} //WikiSearchDocument
View
@@ -48,16 +48,19 @@
//php5 found, continue including php5-only files
require_once("$CFG->dirroot/search/Zend/Search/Lucene.php");
-
- if (get_config("search_indexer_busy") == 1) {
- } //if
-
- //turn on busy flag
- set_config("search_indexer_busy", 1);
+
mtrace('<pre>Server Time: '.date('r',time())."\n");
+
+ if ($CFG->search_indexer_busy == '1') {
+ //means indexing was not finished previously
+ mtrace("Warning: Indexing was not successfully completed last time, restarting.\n");
+ } //if
+
+ //turn on busy flag
+ set_config('search_indexer_busy', '1');
//paths
- $index_path = $CFG->dataroot.'/search';
+ $index_path = SEARCH_INDEX_PATH;
$index_db_file = "$CFG->dirroot/search/db/$CFG->dbtype.sql";
//setup directory in data root
@@ -103,6 +106,7 @@
if ($mods = get_records_select('modules' /*'index this module?' where statement*/)) {
foreach ($mods as $mod) {
+ if ($mod->name == 'forum') continue;
$class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
if (file_exists($class_file)) {
@@ -174,6 +178,9 @@
mtrace('</pre>');
//finished, turn busy flag off
- set_config("search_indexer_busy", 0);
+ set_config("search_indexer_busy", "0");
+
+ //mark the time we last updated
+ set_config("search_indexer_run_date", time());
?>
@@ -18,30 +18,18 @@
$phpversion = phpversion();
mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version $phpversion)");
exit(0);
- } //if
-
- $index_path = "$CFG->dataroot/search";
- $index_dir = get_directory_list($index_path, '', false, false);
- $index_filecount = count($index_dir);
-
- //check if the table exists in the db
- $tables = $db->MetaTables();
-
- if (in_array($CFG->prefix.'search_documents', $tables)) {
- $db_count = count_records('search_documents');
- } else {
- $db_count = 0;
- } //else
+ } //if
- //TODO: elaborate on error messages, when db!=0 and index=0 -> corrupt, etc.
- if ($index_filecount != 0 or $db_count != 0) {
- mtrace("<pre>The data directory ($index_path) contains $index_filecount files, and\n"
- ."there are $db_count records in the <em>search_documents</em> table.\n"
+ require_once("$CFG->dirroot/search/indexlib.php");
+ $indexinfo = new IndexInfo();
+
+ if ($indexinfo->valid()) {
+ mtrace("<pre>The data directory ($indexinfo->path) contains $indexinfo->filecount files, and\n"
+ ."there are ".$indexinfo->dbcount." records in the <em>search_documents</em> table.\n"
."\n"
- ."This indicates that you have already succesfully indexed this site, or at least\n"
- ."started and cancelled an indexing session. Follow the link if you are sure that\n"
- ."you want to continue indexing - this will replace any existing index data (no\n"
- ."Moodle data is affected).\n"
+ ."This indicates that you have already succesfully indexed this site. Follow the link\n"
+ ."if you are sure that you want to continue indexing - this will replace any existing\n"
+ ."index data (no Moodle data is affected).\n"
."\n"
."You are encouraged to use the 'Test indexing' script before continuing onto\n"
."indexing - this will check if the modules are set up correctly. Please correct\n"
View
@@ -1,19 +1,32 @@
<?php
- //Move this stuff to lib/searchlib.php?
- // Author: Michael Champanis
-
- //document types that can be searched
- define('SEARCH_NO_TYPE', 'none');
- define('SEARCH_WIKI_TYPE', 'wiki');
- define('SEARCH_FORUM_TYPE', 'forum');
+ /* Move this stuff to lib/searchlib.php?
+ * Author: Michael Champanis
+ *
+ * This file must not contain any PHP 5, because it is used to test for PHP 5
+ * itself, and needs to be able to be executed on PHP 4 installations.
+ * */
+
+ define('SEARCH_INDEX_PATH', "$CFG->dataroot/search");
+
+ //document types that can be searched
+ define('SEARCH_TYPE_NONE', 'none');
+ define('SEARCH_TYPE_WIKI', 'wiki');
+ define('SEARCH_TYPE_FORUM', 'forum');
//returns all the document type constants
- function search_get_document_types() {
- $r = Array(SEARCH_WIKI_TYPE, SEARCH_NO_TYPE, SEARCH_FORUM_TYPE);
- return $r;
+ function search_get_document_types($prefix='SEARCH_TYPE') {
+ $ret = array();
+
+ foreach (get_defined_constants() as $key=>$value) {
+ if (substr($key, 0, strlen($prefix)) == $prefix) {
+ $ret[$key] = $value;
+ } //if
+ } //foreach
+
+ return $ret;
} //search_get_document_types
-
+
//shortens a url so it can fit on the results page
function search_shorten_url($url, $length=30) {
return substr($url, 0, $length)."...";
Oops, something went wrong.

0 comments on commit b585dc5

Please sign in to comment.