Index: add.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/add.php,v
retrieving revision 1.5.2.3
diff -r1.5.2.3 add.php
2,22c2,28
< /**
< * Global Search Engine for Moodle
< *
< * @package search
< * @category core
< * @subpackage search_engine
< * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
< * @date 2008/03/31
< * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
< *
< * Asynchronous adder for new indexable contents
< *
< * Major chages in this review is passing the xxxx_db_names return to
< * multiple arity to handle multiple document types modules
< */
<
< /**
< * includes and requires
< */
< require_once('../config.php');
< require_once("$CFG->dirroot/search/lib.php");
---
> /**
> * Global Search Engine for Moodle
> *
> * @package search
> * @category core
> * @subpackage search_engine
> * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
> * @date 2008/03/31
> * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
> *
> * Asynchronous adder for new indexable contents
> *
> * Major chages in this review is passing the xxxx_db_names return to
> * multiple arity to handle multiple document types modules
> */
>
> /**
> * includes and requires
> */
> require_once('../config.php');
>
> /// makes inclusions of the Zend Engine more reliable
> $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
> ini_set('include_path', $CFG->dirroot.'/search'.$separator.ini_get('include_path'));
>
> require_once("$CFG->dirroot/search/lib.php");
> require_once("$CFG->dirroot/search/indexlib.php");
32c38
< if (!isadmin()) {
---
> if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
38,46c44,49
< if (!search_check_php5()) {
< $phpversion = phpversion();
< mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version ".phpversion().")");
< exit(0);
< }
<
< require_once("$CFG->dirroot/search/indexlib.php");
<
< $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
---
> try {
> $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
> } catch(LuceneException $e) {
> mtrace("Could not construct a valid index. Maybe the first indexation was never made, or files might be corrupted. Run complete indexation again.");
> return;
> }
91c94
< doctype = '{$mod->name}'
---
> doctype = ?
94c97
< $docIds = get_records_sql_menu($query);
---
> $docIds = $DB->get_records_sql_menu($query, array($mod->name));
158c161
< ?>
---
> ?>
\ No newline at end of file
Index: cron.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/cron.php,v
retrieving revision 1.10.2.2
diff -r1.10.2.2 cron.php
21,25c21
< if (!search_check_php5()) {
< $phpversion = phpversion();
< mtrace("Sorry, cannot cron global search as it requires PHP 5.0.0 or later (currently using version $phpversion)");
< }
< else if (empty($CFG->enableglobalsearch)) {
---
> if (empty($CFG->enableglobalsearch)) {
Index: delete.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/delete.php,v
retrieving revision 1.6.2.3
diff -r1.6.2.3 delete.php
2,22c2,25
< /**
< * Global Search Engine for Moodle
< *
< * @package search
< * @category core
< * @subpackage search_engine
< * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
< * @date 2008/03/31
< * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
< *
< * Asynchronous index cleaner
< *
< * Major chages in this review is passing the xxxx_db_names return to
< * multiple arity to handle multiple document types modules
< */
<
< /**
< * includes and requires
< */
< require_once('../config.php');
< require_once("$CFG->dirroot/search/lib.php");
---
> /**
> * Global Search Engine for Moodle
> *
> * @package search
> * @category core
> * @subpackage search_engine
> * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
> * @date 2008/03/31
> * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
> *
> * Asynchronous index cleaner
> *
> * Major chages in this review is passing the xxxx_db_names return to
> * multiple arity to handle multiple document types modules
> */
>
> /**
> * includes and requires
> */
> require_once('../config.php');
>
> /// makes inclusions of the Zend Engine more reliable
> $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
> ini_set('include_path', $CFG->dirroot.'/search'.$separator.ini_get('include_path'));
23a27,31
> require_once("$CFG->dirroot/search/lib.php");
> require_once("$CFG->dirroot/search/indexlib.php");
>
>
> /// checks global search activation
26c34
<
---
>
31c39
< if (!isadmin()) {
---
> if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
35,39c43,47
< //check for php5 (lib.php)
< if (!search_check_php5()) {
< $phpversion = phpversion();
< mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version ".phpversion().")");
< exit(0);
---
> try {
> $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
> } catch(LuceneException $e) {
> mtrace("Could not construct a valid index. Maybe the first indexation was never made, or files might be corrupted. Run complete indexation again.");
> return;
41,44d48
<
< require_once("$CFG->dirroot/search/indexlib.php");
<
< $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
51a56
> /// check all modules
142c147
< ?>
---
> ?>
\ No newline at end of file
Index: indexer.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/indexer.php,v
retrieving revision 1.13.2.4
diff -r1.13.2.4 indexer.php
37a38,41
> //require_once("debugging.php");
>
> $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
> ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path'));
47c51
< if (!isadmin()) {
---
> if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
64,69d67
< if (!search_check_php5()) {
< $phpversion = phpversion();
< mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version ".phpversion().")");
< exit(0);
< }
<
97c95,96
< } else {
---
> }
> else {
100c99,100
< } else {
---
> }
> else {
103a104
> Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
127,129d127
< $searchables = array();
<
< /// collects modules
131,146c129,131
< if ($mods = get_records('modules', '', '', '', 'id,name')) {
< $searchables = array_merge($searchables, $mods);
< }
< mtrace(count($searchables).' modules found.');
<
< // collects blocks as indexable information may be found in blocks either
< if ($blocks = get_records('block', '', '', '', 'id,name')) {
< // prepend the "block_" prefix to discriminate document type plugins
< foreach(array_keys($blocks) as $aBlockId){
< $blocks[$aBlockId]->name = 'block_'.$blocks[$aBlockId]->name;
< }
< $searchables = array_merge($searchables, $blocks);
< mtrace(count($blocks).' blocks found.');
< }
<
< /// add virtual modules onto the back of the array
---
> $searchables = search_collect_searchables();
>
> /// start indexation
148d132
< $searchables = array_merge($searchables, search_get_additional_modules());
151c135,158
< $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
---
>
> $key = 'search_in_'.$mod->name;
> if (isset($CFG->$key) && !$CFG->$key) {
> mtrace("module $key has been administratively disabled. Skipping...\n");
> continue;
> }
>
> if ($mod->location == 'internal'){
> $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
> } else {
> $class_file = $CFG->dirroot.'/'.$mod->location.'/'.$mod->name.'/search_document.php';
> }
>
> /*
> if (!file_exists($class_file)){
> if (defined("PATH_FOR_SEARCH_TYPE_{$mod->name}")){
> eval("\$pluginpath = PATH_FOR_SEARCH_TYPE_{$mod->name}");
> $class_file = "{$CFG->dirroot}/{$pluginpath}/searchlib.php";
> } else {
> mtrace ("No search document found for plugin {$mod->name}. Ignoring.");
> continue;
> }
> }
> */
197a205,206
> } else {
> mtrace ("No search document found for plugin {$mod->name}. Ignoring.");
Index: indexersplash.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/indexersplash.php,v
retrieving revision 1.9.2.4
diff -r1.9.2.4 indexersplash.php
21c21,25
< require_once("$CFG->dirroot/search/lib.php");
---
> require_once("{$CFG->dirroot}/search/lib.php");
>
> /// makes inclusions of the Zend Engine more reliable
> $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
> ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path'));
31c35
< if (!isadmin()) {
---
> if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
35,42d38
< /// check for php5 (lib.php)
<
< if (!search_check_php5()) {
< $phpversion = phpversion();
< mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version ".phpversion().")");
< exit(0);
< }
<
Index: indexlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/indexlib.php,v
retrieving revision 1.7.2.3
diff -r1.7.2.3 indexlib.php
81c81,82
< $types = search_get_document_types();
---
> // $types = search_get_document_types();
> $types = search_collect_searchables(true, false);
Index: lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/lib.php,v
retrieving revision 1.13.2.2
diff -r1.13.2.2 lib.php
20a21
> function search_collect_searchables($namelist=false, $verbose=true){
21a23
> function search_get_document_types($prefix = 'X_SEARCH_TYPE_') {
25d26
< function search_check_php5($feedback = false) {
33,50c34,35
< //document types that can be searched
< //define('SEARCH_TYPE_NONE', 'none');
< define('SEARCH_TYPE_WIKI', 'wiki');
< define('PATH_FOR_SEARCH_TYPE_WIKI', 'mod/wiki');
< define('SEARCH_TYPE_FORUM', 'forum');
< define('PATH_FOR_SEARCH_TYPE_FORUM', 'mod/forum');
< define('SEARCH_TYPE_GLOSSARY', 'glossary');
< define('PATH_FOR_SEARCH_TYPE_GLOSSARY', 'mod/glossary');
< define('SEARCH_TYPE_RESOURCE', 'resource');
< define('PATH_FOR_SEARCH_TYPE_RESOURCE', 'mod/resource');
< define('SEARCH_TYPE_TECHPROJECT', 'techproject');
< define('PATH_FOR_SEARCH_TYPE_TECHPROJECT', 'mod/techproject');
< define('SEARCH_TYPE_DATA', 'data');
< define('PATH_FOR_SEARCH_TYPE_DATA', 'mod/data');
< define('SEARCH_TYPE_CHAT', 'chat');
< define('PATH_FOR_SEARCH_TYPE_CHAT', 'mod/chat');
< define('SEARCH_TYPE_LESSON', 'lesson');
< define('PATH_FOR_SEARCH_TYPE_LESSON', 'mod/lesson');
---
> // get document types
> include "{$CFG->dirroot}/search/searchtypes.php";
53c38,109
< * returns all the document type constants
---
> * collects all searchable items identities
> * @param boolean $namelist if true, only returns list of names of searchable items
> * @param boolean $verbose if true, prints a discovering status
> * @return an array of names or an array of type descriptors
> */
> function search_collect_searchables($namelist=false, $verbose=true){
> global $CFG;
>
> $searchables = array();
> $searchables_names = array();
>
> /// get all installed modules
> if ($mods = get_records('modules', '', '', 'name', 'id,name')){
>
> $searchabletypes = array_values(search_get_document_types());
>
> foreach($mods as $mod){
> if (in_array($mod->name, $searchabletypes)){
> $mod->location = 'internal';
> $searchables[$mod->name] = $mod;
> $searchables_names[] = $mod->name;
> } else {
> $documentfile = $CFG->dirroot."/mod/{$mod->name}/search_document.php";
> $mod->location = 'mod';
> if (file_exists($documentfile)){
> $searchables[$mod->name] = $mod;
> $searchables_names[] = $mod->name;
> }
> }
> }
> if ($verbose) mtrace(count($searchables).' modules to search in / '.count($mods).' modules found.');
> }
>
> /// collects blocks as indexable information may be found in blocks either
> if ($blocks = get_records('block', '', '', 'name', 'id,name')) {
> $blocks_searchables = array();
> // prepend the "block_" prefix to discriminate document type plugins
> foreach($blocks as $block){
> $block->dirname = $block->name;
> $block->name = 'block_'.$block->name;
> if (in_array('SEARCH_TYPE_'.strtoupper($block->name), $searchabletypes)){
> $mod->location = 'internal';
> $blocks_searchables[] = $block;
> $searchables_names[] = $block->name;
> } else {
> $documentfile = $CFG->dirroot."/blocks/{$block->dirname}/search_document.php";
> if (file_exists($documentfile)){
> $mod->location = 'blocks';
> $blocks_searchables[$block->name] = $block;
> $searchables_names[] = $block->name;
> }
> }
> }
> if ($verbose) mtrace(count($blocks_searchables).' blocks to search in / '.count($blocks).' blocks found.');
> $searchables = array_merge($searchables, $blocks_searchables);
> }
>
> /// add virtual modules onto the back of the array
>
> $additional = search_get_additional_modules();
> if (!empty($additional)){
> if ($verbose) mtrace(count($additional).' additional to search in.');
> $searchables = array_merge($searchables, $additional);
> }
>
> if ($namelist)
> return $searchables_names;
> return $searchables;
> }
>
> /**
> * returns all the document type constants that are known in core implementation
66c122
< } //search_get_document_types
---
> }
77a134,137
> if (defined('SEARCH_EXTRAS')){
> $extras = explode(',', SEARCH_EXTRAS);
> }
>
81c141,142
< $ret[] = clone($temp);
---
> $temp->location = 'internal';
> $ret[$temp->name] = clone($temp);
117,133d177
< * get a real php 5 version number, using 5.0.0 arbitrarily
< * @param feedback if true, prints a feedback message to output.
< * @return true if version of PHP is high enough
< */
< function search_check_php5($feedback = false) {
< if (!check_php_version("5.0.0")) {
< if ($feedback) {
< print_heading(get_string('versiontoolow', 'search'));
< }
< return false;
< }
< else {
< return true;
< }
< } //search_check_php5
<
< /**
Index: query.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/query.php,v
retrieving revision 1.16.2.5
diff -r1.16.2.5 query.php
53d52
< if ($check = search_check_php5()) {
59a59,67
>
> /**
> * discard harmfull searches
> */
> if (preg_match("/^[\*\?]+$/", $query_string)){
> $query_string = '';
> $error = get_string('fullwildcardquery','search');
> }
>
64,65c72
< }
< else if ($advanced) {
---
> } elseif ($advanced) {
88c95
< // get all available module types
---
> // get all available module types adding third party modules
89a97
> $module_types = array_merge($module_types, array_values(search_get_document_types('X_SEARCH_TYPE')));
136c144,145
< //run the query against the index
---
> //run the query against the index ensuring internal coding works in UTF-8
> Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
138d146
< }
159,164c167,169
< //keep things pretty, even if php5 isn't available
< if (!$check) {
< print_heading(search_check_php5(true));
< print_footer();
< exit(0);
< }
---
> if (!empty($error)){
> notice ($error);
> }
181d185
<
290c294
< if (!$sq->is_valid_index() and isadmin()) {
---
> if (!$sq->is_valid_index() and has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
299c303,304
< // prints all the results in a box
---
> /// prints all the results in a box
>
326a332,334
>
> $searchables = search_collect_searchables(false, false);
>
327a336,339
>
> $iconpath = $CFG->modpixpath.'/'.$listing->doctype.'/icon.gif';
> $coursename = get_field('course', 'fullname', 'id', $listing->courseid);
> $courseword = mb_convert_case(get_string('course', 'moodle'), MB_CASE_LOWER, 'UTF-8');
332c344,349
< require_once "{$CFG->dirroot}/search/documents/{$listing->doctype}_document.php";
---
> $searchable_instance = $searchables[$listing->doctype];
> if ($searchable_instance->location == 'internal'){
> require_once "{$CFG->dirroot}/search/documents/{$listing->doctype}_document.php";
> } else {
> require_once "{$CFG->dirroot}/{$searchable_instance->location}/{$listing->doctype}/search_document.php";
> }
337,339c354,360
< print "
url)."'>$listing->title
\n"
< ."".search_shorten_url($listing->url, 70)."
\n"
< ."{$typestr}: ".$listing->doctype.", {$scorestr}: ".round($listing->score, 3);
---
> echo "url)
> ."'>
."\" class=\"activityicon\" alt=\"\"/> $listing->title (".$courseword.": '".$coursename."')
\n";
> // print "url)."'>$listing->title
\n"
> // ."".search_shorten_url($listing->url, 70)."
\n"
> echo "{$typestr}: " . $listing->doctype . ", {$scorestr}: " . round($listing->score, 3);
341c362
< print ", {$authorstr}: ".$listing->author."\n"
---
> echo ", {$authorstr}: ".$listing->author."\n"
345,346c366,367
< print "";
< print $page_links;
---
> echo "";
> echo $page_links;
Index: querylib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/querylib.php,v
retrieving revision 1.7.2.3
diff -r1.7.2.3 querylib.php
29c29,30
< $number;
---
> $number,
> $courseid;
223c224,225
<
---
> $page = optional_param('page', 1, PARAM_INT);
>
236c238,242
< $totalpages = ceil($hitcount/$this->results_per_page);
---
> $resultdoc = new SearchResult();
> $resultdocs = array();
> $searchables = search_collect_searchables(false, false);
>
> $realindex = 0;
237a244
> /**
239c246
< if ($hitcount < $this->results_per_page) {
---
> if ($finalresults < $this->results_per_page) {
241c248
< } else if ($this->pagenumber > $totalpages) {
---
> } elseif ($this->pagenumber > $totalpages) {
248,249c255,256
< if ($end > $hitcount) {
< $end = $hitcount;
---
> if ($end > $finalresults) {
> $end = $finalresults;
253,257c260,261
< $end = $hitcount;
< }
<
< $resultdoc = new SearchResult();
< $resultdocs = array();
---
> $end = $finalresults;
> } */
259c263
< for ($i = $start; $i < $end; $i++) {
---
> for ($i = 0; $i < min($hitcount, ($page) * $this->results_per_page); $i++) {
263,272c267,280
< if ($this->can_display($USER, $hit->docid, $hit->doctype, $hit->course_id, $hit->group_id, $hit->path, $hit->itemtype, $hit->context_id )) {
< $resultdoc->number = $i;
< $resultdoc->url = $hit->url;
< $resultdoc->title = $hit->title;
< $resultdoc->score = $hit->score;
< $resultdoc->doctype = $hit->doctype;
< $resultdoc->author = $hit->author;
<
< //and store it
< $resultdocs[] = clone($resultdoc);
---
> if ($this->can_display($USER, $hit->docid, $hit->doctype, $hit->course_id, $hit->group_id, $hit->path, $hit->itemtype, $hit->context_id, $searchables )) {
> if ($i >= ($page - 1) * $this->results_per_page){
> $resultdoc->number = $realindex;
> $resultdoc->url = $hit->url;
> $resultdoc->title = $hit->title;
> $resultdoc->score = $hit->score;
> $resultdoc->doctype = $hit->doctype;
> $resultdoc->author = $hit->author;
> $resultdoc->courseid = $hit->course_id;
>
> //and store it
> $resultdocs[] = clone($resultdoc);
> }
> $realindex++;
278a287,289
> $totalpages = ceil($this->total_results/$this->results_per_page);
>
>
301c312
< //print "Caching disabled!";
---
> // print "Caching disabled!";
373c384
< private function can_display(&$user, $this_id, $doctype, $course_id, $group_id, $path, $item_type, $context_id) {
---
> private function can_display(&$user, $this_id, $doctype, $course_id, $group_id, $path, $item_type, $context_id, &$searchables) {
380c391
< if (isadmin()){
---
> if (has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))){
384,420c395,400
< // first check course compatibility against user : enrolled users to that course can see.
< $myCourses = get_my_courses($user->id);
< $unenroled = !in_array($course_id, array_keys($myCourses));
<
< // if guests are allowed, logged guest can see
< $isallowedguest = (isguest()) ? get_field('course', 'guest', 'id', $course_id) : false ;
<
< if ($unenroled && !$isallowedguest){
< return false;
< }
<
< // if user is enrolled or is allowed user and course is hidden, can he see it ?
< $visibility = get_field('course', 'visible', 'id', $course_id);
< if ($visibility <= 0){
< if (!has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course_id))){
< return false;
< }
< }
<
< /**
< * prerecorded capabilities
< */
< // get context caching information and tries to discard unwanted records here
<
<
< /**
< * final checks
< */
< // then give back indexing data to the module for local check
< include_once "{$CFG->dirroot}/search/documents/{$doctype}_document.php";
< $access_check_function = "{$doctype}_check_text_access";
<
< if (function_exists($access_check_function)){
< $modulecheck = $access_check_function($path, $item_type, $this_id, $user, $group_id, $context_id);
< // echo "module said $modulecheck for item $doctype/$item_type/$this_id";
< return($modulecheck);
< }
---
> // first check course compatibility against user : enrolled users to that course can see.
> $myCourses = get_my_courses($user->id);
> $unenroled = !in_array($course_id, array_keys($myCourses));
>
> // if guests are allowed, logged guest can see
> $isallowedguest = (isguest()) ? get_field('course', 'guest', 'id', $course_id) : false ;
422c402,438
< return true;
---
> if ($unenroled && !$isallowedguest){
> return false;
> }
>
> // if user is enrolled or is allowed user and course is hidden, can he see it ?
> $visibility = get_field('course', 'visible', 'id', $course_id);
> if ($visibility <= 0){
> if (!has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course_id))){
> return false;
> }
> }
>
> /**
> * prerecorded capabilities
> */
> // get context caching information and tries to discard unwanted records here
>
>
> /**
> * final checks
> */
> // then give back indexing data to the module for local check
> $searchable_instance = $searchables[$doctype];
> if ($searchable_instance->location == 'internal'){
> include_once "{$CFG->dirroot}/search/documents/{$doctype}_document.php";
> } else {
> include_once "{$CFG->dirroot}/{$searchable_instance->location}/$doctype/search_document.php";
> }
> $access_check_function = "{$doctype}_check_text_access";
>
> if (function_exists($access_check_function)){
> $modulecheck = $access_check_function($path, $item_type, $this_id, $user, $group_id, $context_id);
> // echo "module said $modulecheck for item $doctype/$item_type/$this_id";
> return($modulecheck);
> }
>
> return true;
Index: stats.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/stats.php,v
retrieving revision 1.11.2.3
diff -r1.11.2.3 stats.php
35,36c35
< if ($check = search_check_php5()) {
< require_once("{$CFG->dirroot}/search/indexlib.php");
---
> require_once("{$CFG->dirroot}/search/indexlib.php");
38,39c37
< $indexinfo = new IndexInfo();
< }
---
> $indexinfo = new IndexInfo();
61,66d58
< if (!$check) {
< print_heading(search_check_php5(true));
< print_footer();
< exit(0);
< }
<
80c72
< if (isadmin()) {
---
> if (has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
150c142
< if (isadmin()) {
---
> if (has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
Index: update.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/update.php,v
retrieving revision 1.5.2.3
diff -r1.5.2.3 update.php
2,22c2,28
< /**
< * Global Search Engine for Moodle
< *
< * @package search
< * @category core
< * @subpackage search_engine
< * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
< * @date 2008/03/31
< * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
< *
< * Index asynchronous updator
< *
< * Major chages in this review is passing the xxxx_db_names return to
< * multiple arity to handle multiple document types modules
< */
<
< /**
< * includes and requires
< */
< require_once('../config.php');
< require_once("$CFG->dirroot/search/lib.php");
---
> /**
> * Global Search Engine for Moodle
> *
> * @package search
> * @category core
> * @subpackage search_engine
> * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
> * @date 2008/03/31
> * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
> *
> * Index asynchronous updator
> *
> * Major chages in this review is passing the xxxx_db_names return to
> * multiple arity to handle multiple document types modules
> */
>
> /**
> * includes and requires
> */
> require_once('../config.php');
>
> /// makes inclusions of the Zend Engine more reliable
> $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
> ini_set('include_path', $CFG->dirroot.'/search'.$separator.ini_get('include_path'));require_login();
>
> require_once("$CFG->dirroot/search/lib.php");
> require_once("$CFG->dirroot/search/indexlib.php");
32c38
< if (!isadmin()) {
---
> if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
36,46c42,47
< /// check for php5 (lib.php)
<
< if (!search_check_php5()) {
< $phpversion = phpversion();
< mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version ".phpversion().")");
< exit(0);
< }
<
< require_once("$CFG->dirroot/search/indexlib.php");
<
< $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
---
> try {
> $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
> } catch(LuceneException $e) {
> mtrace("Could not construct a valid index. Maybe the first indexation was never made, or files might be corrupted. Run complete indexation again.");
> return;
> }
88c89
< doctype = '{$mod->name}'
---
> doctype = ?
91c92
< $docIds = get_records_sql_menu($query);
---
> $docIds = $DB->get_records_sql_menu($query, array($mod->name));
cvs diff: Diffing Zend
cvs diff: Diffing Zend/Search
Index: Zend/Search/Exception.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Exception.php,v
retrieving revision 1.2
diff -r1.2 Exception.php
17c17
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
25c25
< require_once $CFG->dirroot.'/search/Zend/Exception.php';
---
> require_once "Zend/Exception.php";
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene.php,v
retrieving revision 1.2
diff -r1.2 Lucene.php
17c17
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
21d20
<
23c22
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once "Zend/Search/Lucene/Exception.php";
26c25
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Document.php';
---
> require_once "Zend/Search/Lucene/Document.php";
29c28
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Document/Html.php';
---
> require_once "Zend/Search/Lucene/Document/Html.php";
31,32c30,31
< /** Zend_Search_Lucene_Storage_Directory */
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Storage/Directory/Filesystem.php';
---
> /** Zend_Search_Lucene_Storage_Directory_Filesystem */
> require_once "Zend/Search/Lucene/Storage/Directory/Filesystem.php";
35c34
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Storage/File/Memory.php';
---
> require_once "Zend/Search/Lucene/Storage/File/Memory.php";
38c37
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/Term.php';
---
> require_once "Zend/Search/Lucene/Index/Term.php";
41c40
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/TermInfo.php';
---
> require_once "Zend/Search/Lucene/Index/TermInfo.php";
44c43
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/SegmentInfo.php';
---
> require_once "Zend/Search/Lucene/Index/SegmentInfo.php";
47c46
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/FieldInfo.php';
---
> require_once "Zend/Search/Lucene/Index/FieldInfo.php";
50c49
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/Writer.php';
---
> require_once "Zend/Search/Lucene/Index/Writer.php";
53c52
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryParser.php';
---
> require_once "Zend/Search/Lucene/Search/QueryParser.php";
56c55
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryHit.php';
---
> require_once "Zend/Search/Lucene/Search/QueryHit.php";
59c58
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Similarity.php';
---
> require_once "Zend/Search/Lucene/Search/Similarity.php";
62c61,65
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/SegmentInfoPriorityQueue.php';
---
> require_once "Zend/Search/Lucene/Index/SegmentInfoPriorityQueue.php";
>
> /** Zend_Search_Lucene_LockManager */
> require_once "Zend/Search/Lucene/LockManager.php";
>
66c69
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Interface.php';
---
> require_once "Zend/Search/Lucene/Interface.php";
69c72
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Proxy.php';
---
> require_once "Zend/Search/Lucene/Proxy.php";
75c78
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
89a93,101
> * Result set limit
> *
> * 0 means no limit
> *
> * @var integer
> */
> private static $_resultSetLimit = 0;
>
> /**
133,139d144
< * Index lock object
< *
< * @var Zend_Search_Lucene_Storage_File
< */
< private $_lock;
<
< /**
152a158,163
> /**
> * Current segment generation
> *
> * @var integer
> */
> private $_generation;
153a165
>
175a188,193
> /** Generation retrieving counter */
> const GENERATION_RETRIEVE_COUNT = 10;
>
> /** Pause between generation retrieving attempts in milliseconds */
> const GENERATION_RETRIEVE_PAUSE = 50;
>
177c195
< * Opens the index.
---
> * Get current generation number
179,180c197,199
< * IndexReader constructor needs Directory as a parameter. It should be
< * a string with a path to the index folder or a Directory object.
---
> * Returns generation number
> * 0 means pre-2.1 index format
> * -1 means there are no segments files.
182c201,202
< * @param mixed $directory
---
> * @param Zend_Search_Lucene_Storage_Directory $directory
> * @return integer
185c205
< public function __construct($directory = null, $create = false)
---
> public static function getActualGeneration(Zend_Search_Lucene_Storage_Directory $directory)
187,197c207,226
< if ($directory === null) {
< throw new Zend_Search_Exception('No index directory specified');
< }
<
< if ($directory instanceof Zend_Search_Lucene_Storage_Directory_Filesystem) {
< $this->_directory = $directory;
< $this->_closeDirOnExit = false;
< } else {
< $this->_directory = new Zend_Search_Lucene_Storage_Directory_Filesystem($directory);
< $this->_closeDirOnExit = true;
< }
---
> /**
> * Zend_Search_Lucene uses segments.gen file to retrieve current generation number
> *
> * Apache Lucene index format documentation mentions this method only as a fallback method
> *
> * Nevertheless we use it according to the performance considerations
> *
> * @todo check if we can use some modification of Apache Lucene generation determination algorithm
> * without performance problems
> */
>
> try {
> for ($count = 0; $count < self::GENERATION_RETRIEVE_COUNT; $count++) {
> // Try to get generation file
> $genFile = $directory->getFileObject('segments.gen', false);
>
> $format = $genFile->readInt();
> if ($format != (int)0xFFFFFFFE) {
> throw new Zend_Search_Lucene_Exception('Wrong segments.gen file format');
> }
198a228,229
> $gen1 = $genFile->readLong();
> $gen2 = $genFile->readLong();
200,201c231,233
< // Get a shared lock to the index
< $this->_lock = $this->_directory->createFile('index.lock');
---
> if ($gen1 == $gen2) {
> return $gen1;
> }
203c235,236
< $this->_segmentInfos = array();
---
> usleep(self::GENERATION_RETRIEVE_PAUSE * 1000);
> }
205,208c238,256
< if ($create) {
< // Throw an exception if index is under processing now
< if (!$this->_lock->lock(LOCK_EX, true)) {
< throw new Zend_Search_Lucene_Exception('Can\'t create index. It\'s under processing now');
---
> // All passes are failed
> throw new Zend_Search_Lucene_Exception('Index is under processing now');
> } catch (Zend_Search_Lucene_Exception $e) {
> if (strpos($e->getMessage(), 'is not readable') !== false) {
> try {
> // Try to open old style segments file
> $segmentsFile = $directory->getFileObject('segments', false);
>
> // It's pre-2.1 index
> return 0;
> } catch (Zend_Search_Lucene_Exception $e) {
> if (strpos($e->getMessage(), 'is not readable') !== false) {
> return -1;
> } else {
> throw $e;
> }
> }
> } else {
> throw $e;
209a258
> }
211,212c260,261
< // Writer will create segments file for empty segments list
< $this->_writer = new Zend_Search_Lucene_Index_Writer($this->_directory, $this->_segmentInfos, true);
---
> return -1;
> }
214,222c263,272
< if (!$this->_lock->lock(LOCK_SH)) {
< throw new Zend_Search_Lucene_Exception('Can\'t reduce lock level from Exclusive to Shared');
< }
< } else {
< // Wait if index is under switching from one set of segments to another (Index_Writer::_updateSegments())
< if (!$this->_lock->lock(LOCK_SH)) {
< throw new Zend_Search_Lucene_Exception('Can\'t obtain shared index lock');
< }
< $this->_writer = null;
---
> /**
> * Get segments file name
> *
> * @param integer $generation
> * @return string
> */
> public static function getSegmentFileName($generation)
> {
> if ($generation == 0) {
> return 'segments';
224a275,276
> return 'segments_' . base_convert($generation, 10, 36);
> }
225a278,282
> /**
> * Read segments file for pre-2.1 Lucene index format
> */
> private function _readPre21SegmentsFile()
> {
251,252c308,375
< $this->_segmentInfos[] =
< new Zend_Search_Lucene_Index_SegmentInfo($segName,
---
> $this->_segmentInfos[$segName] =
> new Zend_Search_Lucene_Index_SegmentInfo($this->_directory,
> $segName,
> $segSize);
> }
> }
>
> /**
> * Read segments file
> *
> * @throws Zend_Search_Lucene_Exception
> */
> private function _readSegmentsFile()
> {
> $segmentsFile = $this->_directory->getFileObject(self::getSegmentFileName($this->_generation));
>
> $format = $segmentsFile->readInt();
>
> if ($format != (int)0xFFFFFFFD) {
> throw new Zend_Search_Lucene_Exception('Wrong segments file format');
> }
>
> // read version
> // $segmentsFile->readLong();
> $segmentsFile->readInt(); $segmentsFile->readInt();
>
> // read segment name counter
> $segmentsFile->readInt();
>
> $segments = $segmentsFile->readInt();
>
> $this->_docCount = 0;
>
> // read segmentInfos
> for ($count = 0; $count < $segments; $count++) {
> $segName = $segmentsFile->readString();
> $segSize = $segmentsFile->readInt();
>
> // 2.1+ specific properties
> //$delGen = $segmentsFile->readLong();
> $delGenHigh = $segmentsFile->readInt();
> $delGenLow = $segmentsFile->readInt();
> if ($delGenHigh == (int)0xFFFFFFFF && $delGenLow == (int)0xFFFFFFFF) {
> $delGen = -1; // There are no deletes
> } else {
> $delGen = ($delGenHigh << 32) | $delGenLow;
> }
>
> $hasSingleNormFile = $segmentsFile->readByte();
> $numField = $segmentsFile->readInt();
>
> $normGens = array();
> if ($numField != (int)0xFFFFFFFF) {
> for ($count1 = 0; $count1 < $numField; $count1++) {
> $normGens[] = $segmentsFile->readLong();
> }
>
> throw new Zend_Search_Lucene_Exception('Separate norm files are not supported. Optimize index to use it with Zend_Search_Lucene.');
> }
>
> $isCompound = $segmentsFile->readByte();
>
>
> $this->_docCount += $segSize;
>
> $this->_segmentInfos[$segName] =
> new Zend_Search_Lucene_Index_SegmentInfo($this->_directory,
> $segName,
254c377,403
< $this->_directory);
---
> $delGen,
> $hasSingleNormFile,
> $isCompound);
> }
> }
>
> /**
> * Opens the index.
> *
> * IndexReader constructor needs Directory as a parameter. It should be
> * a string with a path to the index folder or a Directory object.
> *
> * @param mixed $directory
> * @throws Zend_Search_Lucene_Exception
> */
> public function __construct($directory = null, $create = false)
> {
> if ($directory === null) {
> throw new Zend_Search_Exception('No index directory specified');
> }
>
> if ($directory instanceof Zend_Search_Lucene_Storage_Directory_Filesystem) {
> $this->_directory = $directory;
> $this->_closeDirOnExit = false;
> } else {
> $this->_directory = new Zend_Search_Lucene_Storage_Directory_Filesystem($directory);
> $this->_closeDirOnExit = true;
255a405,455
>
> $this->_segmentInfos = array();
>
> // Mark index as "under processing" to prevent other processes from premature index cleaning
> Zend_Search_Lucene_LockManager::obtainReadLock($this->_directory);
>
> // Escalate read lock to prevent current generation index files to be deleted while opening process is not done
> // Zend_Search_Lucene_LockManager::escalateReadLock($this->_directory);
>
>
> $this->_generation = self::getActualGeneration($this->_directory);
>
> if ($create) {
> try {
> Zend_Search_Lucene_LockManager::obtainWriteLock($this->_directory);
> } catch (Zend_Search_Lucene_Exception $e) {
> if (strpos($e->getMessage(), 'Can\'t obtain exclusive index lock') === false) {
> throw $e;
> } else {
> throw new Zend_Search_Lucene_Exception('Can\'t create index. It\'s under processing now');
> }
> }
>
> if ($this->_generation == -1) {
> // Directory doesn't contain existing index, start from 1
> $this->_generation = 1;
> $nameCounter = 0;
> } else {
> // Directory contains existing index
> $segmentsFile = $this->_directory->getFileObject(self::getSegmentFileName($this->_generation));
> $segmentsFile->seek(12); // 12 = 4 (int, file format marker) + 8 (long, index version)
>
> $nameCounter = $segmentsFile->readInt();
> $this->_generation++;
> }
>
> Zend_Search_Lucene_Index_Writer::createIndex($this->_directory, $this->_generation, $nameCounter);
>
> Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory);
> }
>
> if ($this->_generation == -1) {
> throw new Zend_Search_Lucene_Exception('Index doesn\'t exists in the specified directory.');
> } else if ($this->_generation == 0) {
> $this->_readPre21SegmentsFile();
> } else {
> $this->_readSegmentsFile();
> }
>
> // De-escalate read lock to prevent current generation index files to be deleted while opening process is not done
> // Zend_Search_Lucene_LockManager::escalateReadLock($this->_directory);
270,272c470,472
< // Free shared lock
< $this->_lock->unlock();
<
---
> // Release "under processing" flag
> Zend_Search_Lucene_LockManager::releaseReadLock($this->_directory);
>
434a635,658
> * Set result set limit.
> *
> * 0 (default) means no limit
> *
> * @param integer $limit
> */
> public static function setResultSetLimit($limit)
> {
> self::$_resultSetLimit = $limit;
> }
>
> /**
> * Set result set limit.
> *
> * 0 means no limit
> *
> * @return integer
> */
> public static function getResultSetLimit()
> {
> return self::$_resultSetLimit;
> }
>
> /**
587a812,815
>
> if (self::$_resultSetLimit != 0 && count($hits) >= self::$_resultSetLimit) {
> break;
> }
592c820
< return array();
---
> return array();
979a1208,1209
>
> $this->_hasChanges = true;
1005,1011c1235,1237
<
< $this->_hasChanges = false;
< }
<
< if ($this->_writer !== null) {
< $this->_writer->commit();
<
---
>
> $this->getIndexWriter()->commit();
>
1012a1239,1240
>
> $this->_hasChanges = false;
1062,1064c1290
< $segmentInfo->nextTerm();
< // check, if segment dictionary is finished
< if ($segmentInfo->currentTerm() !== null) {
---
> if ($segmentInfo->nextTerm() !== null) {
1073a1300,1418
> /**
> * Terms stream queue
> *
> * @var Zend_Search_Lucene_Index_SegmentInfoPriorityQueue
> */
> private $_termsStreamQueue = null;
>
> /**
> * Last Term in a terms stream
> *
> * @var Zend_Search_Lucene_Index_Term
> */
> private $_lastTerm = null;
>
> /**
> * Reset terms stream.
> */
> public function resetTermsStream()
> {
> $this->_termsStreamQueue = new Zend_Search_Lucene_Index_SegmentInfoPriorityQueue();
>
> foreach ($this->_segmentInfos as $segmentInfo) {
> $segmentInfo->reset();
>
> // Skip "empty" segments
> if ($segmentInfo->currentTerm() !== null) {
> $this->_termsStreamQueue->put($segmentInfo);
> }
> }
>
> $this->nextTerm();
> }
>
> /**
> * Skip terms stream up to specified term preffix.
> *
> * Prefix contains fully specified field info and portion of searched term
> *
> * @param Zend_Search_Lucene_Index_Term $prefix
> */
> public function skipTo(Zend_Search_Lucene_Index_Term $prefix)
> {
> $segments = array();
>
> while (($segmentInfo = $this->_termsStreamQueue->pop()) !== null) {
> $segments[] = $segmentInfo;
> }
>
> foreach ($segments as $segmentInfo) {
> $segmentInfo->skipTo($prefix);
>
> if ($segmentInfo->currentTerm() !== null) {
> $this->_termsStreamQueue->put($segmentInfo);
> }
> }
>
> $this->nextTerm();
> }
>
> /**
> * Scans terms dictionary and returns next term
> *
> * @return Zend_Search_Lucene_Index_Term|null
> */
> public function nextTerm()
> {
> while (($segmentInfo = $this->_termsStreamQueue->pop()) !== null) {
> if ($this->_termsStreamQueue->top() === null ||
> $this->_termsStreamQueue->top()->currentTerm()->key() !=
> $segmentInfo->currentTerm()->key()) {
> // We got new term
> $this->_lastTerm = $segmentInfo->currentTerm();
>
> if ($segmentInfo->nextTerm() !== null) {
> // Put segment back into the priority queue
> $this->_termsStreamQueue->put($segmentInfo);
> }
>
> return $this->_lastTerm;
> }
>
> if ($segmentInfo->nextTerm() !== null) {
> // Put segment back into the priority queue
> $this->_termsStreamQueue->put($segmentInfo);
> }
> }
>
> // End of stream
> $this->_lastTerm = null;
>
> return null;
> }
>
> /**
> * Returns term in current position
> *
> * @return Zend_Search_Lucene_Index_Term|null
> */
> public function currentTerm()
> {
> return $this->_lastTerm;
> }
>
> /**
> * Close terms stream
> *
> * Should be used for resources clean up if stream is not read up to the end
> */
> public function closeTermsStream()
> {
> while (($segmentInfo = $this->_termsStreamQueue->pop()) !== null) {
> $segmentInfo->closeTermsStream();
> }
>
> $this->_termsStreamQueue = null;
> $this->_lastTerm = null;
> }
>
>
cvs diff: Diffing Zend/Search/Lucene
Index: Zend/Search/Lucene/Document.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Document.php,v
retrieving revision 1.2
diff -r1.2 Document.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Field.php';
---
> require_once "Zend/Search/Lucene/Field.php";
33c33
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
57,60c57,60
< public function __get($offset)
< {
< return $this->getFieldValue($offset);
< }
---
> public function __get($offset)
> {
> return $this->getFieldValue($offset);
> }
81c81
< return array_keys($this->_fields);
---
> return array_keys($this->_fields);
108c108
< return $this->getField($fieldName)->value;
---
> return $this->getField($fieldName)->value;
119c119
< return $this->getField($fieldName)->getUtf8Value();
---
> return $this->getField($fieldName)->getUtf8Value();
Index: Zend/Search/Lucene/Exception.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Exception.php,v
retrieving revision 1.2
diff -r1.2 Exception.php
17c17
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
25c25
< require_once $CFG->dirroot.'/search/Zend/Search/Exception.php';
---
> require_once "Zend/Search/Exception.php";
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/FSM.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/FSM.php,v
retrieving revision 1.1
diff -r1.1 FSM.php
17c17
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
23c23
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/FSMAction.php';
---
> require_once 'Zend/Search/Lucene/FSMAction.php';
26c26
< require_once $CFG->dirroot.'/search/Zend/Search/Exception.php';
---
> require_once 'Zend/Search/Exception.php';
40c40
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/FSMAction.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/FSMAction.php,v
retrieving revision 1.1
diff -r1.1 FSMAction.php
17c17
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
28c28
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Field.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Field.php,v
retrieving revision 1.3
diff -r1.3 Field.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Interface.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Interface.php,v
retrieving revision 1.1
diff -r1.1 Interface.php
17c17
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
25c25
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
89a90,107
> * Set result set limit.
> *
> * 0 (default) means no limit
> *
> * @param integer $limit
> */
> public static function setResultSetLimit($limit);
>
> /**
> * Set result set limit.
> *
> * 0 means no limit
> *
> * @return integer
> */
> public static function getResultSetLimit();
>
> /**
308a327,363
>
> /**
> * Reset terms stream.
> */
> public function resetTermsStream();
>
> /**
> * Skip terms stream up to specified term preffix.
> *
> * Prefix contains fully specified field info and portion of searched term
> *
> * @param Zend_Search_Lucene_Index_Term $prefix
> */
> public function skipTo(Zend_Search_Lucene_Index_Term $prefix);
>
> /**
> * Scans terms dictionary and returns next term
> *
> * @return Zend_Search_Lucene_Index_Term|null
> */
> public function nextTerm();
>
> /**
> * Returns term in current position
> *
> * @return Zend_Search_Lucene_Index_Term|null
> */
> public function currentTerm();
>
> /**
> * Close terms stream
> *
> * Should be used for resources clean up if stream is not read up to the end
> */
> public function closeTermsStream();
>
>
Index: Zend/Search/Lucene/PriorityQueue.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/PriorityQueue.php,v
retrieving revision 1.1
diff -r1.1 PriorityQueue.php
17c17
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Proxy.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Proxy.php,v
retrieving revision 1.1
diff -r1.1 Proxy.php
17c17
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
22c22
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Interface.php';
---
> require_once 'Zend/Search/Lucene/Interface.php';
32c32
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
147a148,171
> * Set result set limit.
> *
> * 0 (default) means no limit
> *
> * @param integer $limit
> */
> public static function setResultSetLimit($limit)
> {
> Zend_Search_Lucene::setResultSetLimit($limit);
> }
>
> /**
> * Set result set limit.
> *
> * 0 means no limit
> *
> * @return integer
> */
> public static function getResultSetLimit()
> {
> return Zend_Search_Lucene::getResultSetLimit();
> }
>
> /**
438a463,514
>
> /**
> * Reset terms stream.
> */
> public function resetTermsStream()
> {
> $this->_index->resetTermsStream();
> }
>
> /**
> * Skip terms stream up to specified term preffix.
> *
> * Prefix contains fully specified field info and portion of searched term
> *
> * @param Zend_Search_Lucene_Index_Term $prefix
> */
> public function skipTo(Zend_Search_Lucene_Index_Term $prefix)
> {
> return $this->_index->skipTo($prefix);
> }
>
> /**
> * Scans terms dictionary and returns next term
> *
> * @return Zend_Search_Lucene_Index_Term|null
> */
> public function nextTerm()
> {
> return $this->_index->nextTerm();
> }
>
> /**
> * Returns term in current position
> *
> * @return Zend_Search_Lucene_Index_Term|null
> */
> public function currentTerm()
> {
> return $this->_index->currentTerm();
> }
>
> /**
> * Close terms stream
> *
> * Should be used for resources clean up if stream is not read up to the end
> */
> public function closeTermsStream()
> {
> $this->_index->closeTermsStream();
> }
>
>
cvs diff: Diffing Zend/Search/Lucene/Analysis
Index: Zend/Search/Lucene/Analysis/Analyzer.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/Analyzer.php,v
retrieving revision 1.2.2.1
diff -r1.2.2.1 Analyzer.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Token.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Analysis/Token.php";
27c27,30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8.php";
>
> /** Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive */
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8/CaseInsensitive.php";
30c33,36
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num.php";
>
> /** Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive */
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num/CaseInsensitive.php";
33c39
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php";
36c42
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Text/CaseInsensitive.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Text/CaseInsensitive.php";
39c45
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum.php";
42c48
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum/CaseInsensitive.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum/CaseInsensitive.php";
45c51
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/TokenFilter/StopWords.php';
---
> require_once 'Zend/Search/Lucene/Analysis/TokenFilter/StopWords.php';
48c54
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/TokenFilter/ShortWords.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Analysis/TokenFilter/ShortWords.php";
64c70
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
100c106
< public function tokenize($data, $encoding = 'UTF-8')
---
> public function tokenize($data, $encoding = '')
102a109
>
163c170
< self::$_defaultImpl = new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8();
---
> self::$_defaultImpl = new Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive();
Index: Zend/Search/Lucene/Analysis/Token.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/Token.php,v
retrieving revision 1.2
diff -r1.2 Token.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
27c27
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Analysis/TokenFilter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/TokenFilter.php,v
retrieving revision 1.2
diff -r1.2 TokenFilter.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Token.php';
---
> require_once 'Zend/Search/Lucene/Analysis/Token.php';
33c33
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
cvs diff: Diffing Zend/Search/Lucene/Analysis/Analyzer
Index: Zend/Search/Lucene/Analysis/Analyzer/Common.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/Analyzer/Common.php,v
retrieving revision 1.2
diff -r1.2 Common.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer.php';
---
> require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
37c37
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
71c71
< // resulting token can be null if the filter removed it
---
> // resulting token can be null if the filter removes it
cvs diff: Diffing Zend/Search/Lucene/Analysis/Analyzer/Common
Index: Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php,v
retrieving revision 1.2
diff -r1.2 Text.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common.php';
---
> require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php';
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
56c56,58
< $this->_input = iconv($this->_encoding, 'ASCII//TRANSLIT', $this->_input);
---
> //$this->_input = iconv($this->_encoding, 'ASCII//TRANSLIT', $this->_input);
> $this->_input = mb_convert_encoding($this->_input, 'ASCII', 'auto');
>
78c80
< return null;
---
> return null;
Index: Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum.php,v
retrieving revision 1.1
diff -r1.1 TextNum.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common.php';
---
> require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php';
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
77c77
< return null;
---
> return null;
Index: Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8.php,v
retrieving revision 1.1
diff -r1.1 Utf8.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common.php';
---
> require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php';
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
50c50
<
---
>
52c52
< * Stream length
---
> * Object constructor
54c54
< * @var integer
---
> * @throws Zend_Search_Lucene_Exception
56c56,63
< private $_streamLength;
---
> public function __construct()
> {
> if (@preg_match('/\pL/u', 'a') != 1) {
> // PCRE unicode support is turned off
> require_once 'Zend/Search/Lucene/Exception.php';
> throw new Zend_Search_Lucene_Exception('Utf8 analyzer needs PCRE unicode support to be enabled.');
> }
> }
69c76
< $this->_input = iconv($this->_encoding, 'UTF-8', $this->_input);
---
> $this->_input = @iconv($this->_encoding, 'UTF-8', $this->_input);
72,118d78
<
< // Get UTF-8 string length.
< // It also checks if it's a correct utf-8 string
< $this->_streamLength = iconv_strlen($this->_input, 'UTF-8');
< }
<
< /**
< * Check, that character is a letter
< *
< * @param string $char
< * @return boolean
< */
< private static function _isAlpha($char)
< {
< if (strlen($char) > 1) {
< // It's an UTF-8 character
< return true;
< }
<
< return ctype_alpha($char);
< }
<
< /**
< * Get next UTF-8 char
< *
< * @param string $char
< * @return boolean
< */
< private function _nextChar()
< {
< $char = $this->_input[$this->_bytePosition++];
<
< if (( ord($char) & 0xC0 ) == 0xC0) {
< $addBytes = 1;
< if (ord($char) & 0x20 ) {
< $addBytes++;
< if (ord($char) & 0x10 ) {
< $addBytes++;
< }
< }
< $char .= substr($this->_input, $this->_bytePosition, $addBytes);
< $this->_bytePosition += $addBytes;
< }
<
< $this->_position++;
<
< return $char;
134,138c94,98
< while ($this->_position < $this->_streamLength) {
< // skip white space
< while ($this->_position < $this->_streamLength &&
< !self::_isAlpha($char = $this->_nextChar())) {
< $char = '';
---
> do {
> if (! preg_match('/[\p{L}]+/u', $this->_input, $match, PREG_OFFSET_CAPTURE, $this->_bytePosition)) {
> // It covers both cases a) there are no matches (preg_match(...) === 0)
> // b) error occured (preg_match(...) === FALSE)
> return null;
141,148c101,114
< $termStartPosition = $this->_position - 1;
< $termText = $char;
<
< // read token
< while ($this->_position < $this->_streamLength &&
< self::_isAlpha($char = $this->_nextChar())) {
< $termText .= $char;
< }
---
> // matched string
> $matchedWord = $match[0][0];
>
> // binary position of the matched word in the input stream
> $binStartPos = $match[0][1];
>
> // character position of the matched word in the input stream
> $startPos = $this->_position +
> iconv_strlen(substr($this->_input,
> $this->_bytePosition,
> $binStartPos - $this->_bytePosition),
> 'UTF-8');
> // character postion of the end of matched word in the input stream
> $endPos = $startPos + iconv_strlen($matchedWord, 'UTF-8');
150,153c116,117
< // Empty token, end of stream.
< if ($termText == '') {
< return null;
< }
---
> $this->_bytePosition = $binStartPos + strlen($matchedWord);
> $this->_position = $endPos;
155,164c119,120
< $token = new Zend_Search_Lucene_Analysis_Token(
< $termText,
< $termStartPosition,
< $this->_position - 1);
< $token = $this->normalize($token);
< if ($token !== null) {
< return $token;
< }
< // Continue if token is skipped
< }
---
> $token = $this->normalize(new Zend_Search_Lucene_Analysis_Token($matchedWord, $startPos, $endPos));
> } while ($token === null); // try again if token is skipped
166c122
< return null;
---
> return $token;
Index: Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num.php,v
retrieving revision 1.1
diff -r1.1 Utf8Num.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common.php';
---
> require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php';
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
52c52
< * Stream length
---
> * Object constructor
54c54
< * @var integer
---
> * @throws Zend_Search_Lucene_Exception
56c56,63
< private $_streamLength;
---
> public function __construct()
> {
> if (@preg_match('/\pL/u', 'a') != 1) {
> // PCRE unicode support is turned off
> require_once 'Zend/Search/Lucene/Exception.php';
> throw new Zend_Search_Lucene_Exception('Utf8Num analyzer needs PCRE unicode support to be enabled.');
> }
> }
72,118d78
<
< // Get UTF-8 string length.
< // It also checks if it's a correct utf-8 string
< $this->_streamLength = iconv_strlen($this->_input, 'UTF-8');
< }
<
< /**
< * Check, that character is a letter
< *
< * @param string $char
< * @return boolean
< */
< private static function _isAlNum($char)
< {
< if (strlen($char) > 1) {
< // It's an UTF-8 character
< return true;
< }
<
< return ctype_alnum($char);
< }
<
< /**
< * Get next UTF-8 char
< *
< * @param string $char
< * @return boolean
< */
< private function _nextChar()
< {
< $char = $this->_input[$this->_bytePosition++];
<
< if (( ord($char) & 0xC0 ) == 0xC0) {
< $addBytes = 1;
< if (ord($char) & 0x20 ) {
< $addBytes++;
< if (ord($char) & 0x10 ) {
< $addBytes++;
< }
< }
< $char .= substr($this->_input, $this->_bytePosition, $addBytes);
< $this->_bytePosition += $addBytes;
< }
<
< $this->_position++;
<
< return $char;
134,138c94,98
< while ($this->_position < $this->_streamLength) {
< // skip white space
< while ($this->_position < $this->_streamLength &&
< !self::_isAlNum($char = $this->_nextChar())) {
< $char = '';
---
> do {
> if (! preg_match('/[\p{L}\p{N}]+/u', $this->_input, $match, PREG_OFFSET_CAPTURE, $this->_bytePosition)) {
> // It covers both cases a) there are no matches (preg_match(...) === 0)
> // b) error occured (preg_match(...) === FALSE)
> return null;
141,142c101,114
< $termStartPosition = $this->_position - 1;
< $termText = $char;
---
> // matched string
> $matchedWord = $match[0][0];
>
> // binary position of the matched word in the input stream
> $binStartPos = $match[0][1];
>
> // character position of the matched word in the input stream
> $startPos = $this->_position +
> iconv_strlen(substr($this->_input,
> $this->_bytePosition,
> $binStartPos - $this->_bytePosition),
> 'UTF-8');
> // character postion of the end of matched word in the input stream
> $endPos = $startPos + iconv_strlen($matchedWord, 'UTF-8');
144,148c116,117
< // read token
< while ($this->_position < $this->_streamLength &&
< self::_isAlNum($char = $this->_nextChar())) {
< $termText .= $char;
< }
---
> $this->_bytePosition = $binStartPos + strlen($matchedWord);
> $this->_position = $endPos;
150,164c119,120
< // Empty token, end of stream.
< if ($termText == '') {
< return null;
< }
<
< $token = new Zend_Search_Lucene_Analysis_Token(
< $termText,
< $termStartPosition,
< $this->_position - 1);
< $token = $this->normalize($token);
< if ($token !== null) {
< return $token;
< }
< // Continue if token is skipped
< }
---
> $token = $this->normalize(new Zend_Search_Lucene_Analysis_Token($matchedWord, $startPos, $endPos));
> } while ($token === null); // try again if token is skipped
166c122
< return null;
---
> return $token;
cvs diff: Diffing Zend/Search/Lucene/Analysis/Analyzer/Common/Text
Index: Zend/Search/Lucene/Analysis/Analyzer/Common/Text/CaseInsensitive.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Text/CaseInsensitive.php,v
retrieving revision 1.2
diff -r1.2 CaseInsensitive.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php';
---
> require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/TokenFilter/LowerCase.php';
---
> require_once 'Zend/Search/Lucene/Analysis/TokenFilter/LowerCase.php';
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
cvs diff: Diffing Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum
Index: Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum/CaseInsensitive.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum/CaseInsensitive.php,v
retrieving revision 1.1
diff -r1.1 CaseInsensitive.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum.php';
---
> require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/TokenFilter/LowerCase.php';
---
> require_once 'Zend/Search/Lucene/Analysis/TokenFilter/LowerCase.php';
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
cvs diff: Diffing Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8
cvs diff: Diffing Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num
cvs diff: Diffing Zend/Search/Lucene/Analysis/TokenFilter
Index: Zend/Search/Lucene/Analysis/TokenFilter/LowerCase.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/TokenFilter/LowerCase.php,v
retrieving revision 1.2
diff -r1.2 LowerCase.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/TokenFilter.php';
---
> require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php';
33c33
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Analysis/TokenFilter/LowerCaseUtf8.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/TokenFilter/LowerCaseUtf8.php,v
retrieving revision 1.1.4.2
diff -r1.1.4.2 LowerCaseUtf8.php
24c24
< require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Analysis/TokenFilter.php";
43a44
> global $CFG;
46c47
< require_once 'Zend/Search/Lucene/Exception.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Exception.php";
Index: Zend/Search/Lucene/Analysis/TokenFilter/ShortWords.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/TokenFilter/ShortWords.php,v
retrieving revision 1.1
diff -r1.1 ShortWords.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/TokenFilter.php';
---
> require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php';
33c33
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Analysis/TokenFilter/StopWords.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Analysis/TokenFilter/StopWords.php,v
retrieving revision 1.1
diff -r1.1 StopWords.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24,25c24,25
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/TokenFilter.php';
< require_once $CFG->dirroot.'/search/Zend/Search/Exception.php';
---
> require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php';
> require_once 'Zend/Search/Exception.php';
37c37
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
44c44
< * Minimum allowed term length
---
> * Stop Words
66d65
< $t = $srcToken->getTermText();
cvs diff: Diffing Zend/Search/Lucene/Document
Index: Zend/Search/Lucene/Document/Html.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Document/Html.php,v
retrieving revision 1.1
diff -r1.1 Html.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Document.php';
---
> require_once 'Zend/Search/Lucene/Document.php';
33c33
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
293c293
< $matchedNodes = $xpath->query("/html/body/*");
---
> $matchedNodes = $xpath->query("/html/body");
cvs diff: Diffing Zend/Search/Lucene/Index
Index: Zend/Search/Lucene/Index/DictionaryLoader.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Index/DictionaryLoader.php,v
retrieving revision 1.1
diff -r1.1 DictionaryLoader.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
38c38
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
64c64,65
< if ($tiVersion != (int)0xFFFFFFFE) {
---
> if ($tiVersion != (int)0xFFFFFFFE /* pre-2.1 format */ &&
> $tiVersion != (int)0xFFFFFFFD /* 2.1+ format */) {
68c69
< // $indexTermCount = = $tiiFile->readLong();
---
> // $indexTermCount = $tiiFile->readLong();
103a105,109
> if ($tiVersion == (int)0xFFFFFFFD /* 2.1+ format */) {
> /* Skip MaxSkipLevels value */
> $pos += 4;
> }
>
Index: Zend/Search/Lucene/Index/FieldInfo.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Index/FieldInfo.php,v
retrieving revision 1.2
diff -r1.2 FieldInfo.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
27c27
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Index/SegmentInfo.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Index/SegmentInfo.php,v
retrieving revision 1.3
diff -r1.3 SegmentInfo.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
23c23
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/DictionaryLoader.php';
---
> require_once 'Zend/Search/Lucene/Index/DictionaryLoader.php';
27c27,30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
>
> /** Zend_Search_Lucene_LockManager */
> require_once 'Zend/Search/Lucene/LockManager.php';
34c37
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
112a116,144
> /**
> * Delete file generation number
> *
> * -1 means 'there is no delete file'
> * 0 means pre-2.1 format delete file
> * X specifies used delete file
> *
> * @var integer
> */
> private $_delGen;
>
> /**
> * Segment has single norms file
> *
> * If true then one .nrm file is used for all fields
> * Otherwise .fN files are used
> *
> * @var boolean
> */
> private $_hasSingleNormFile;
>
> /**
> * Use compound segment file (*.cfs) to collect all other segment files
> * (excluding .del files)
> *
> * @var boolean
> */
> private $_isCompound;
>
139c171
< private $_deleted;
---
> private $_deleted = null;
150,151c182
< * Zend_Search_Lucene_Index_SegmentInfo constructor needs Segmentname,
< * Documents count and Directory as a parameter.
---
> * Zend_Search_Lucene_Index_SegmentInfo constructor
152a184
> * @param Zend_Search_Lucene_Storage_Directory $directory
155c187,188
< * @param Zend_Search_Lucene_Storage_Directory $directory
---
> * @param integer $delGen
> * @param boolean $isCompound
157c190
< public function __construct($name, $docCount, $directory)
---
> public function __construct(Zend_Search_Lucene_Storage_Directory $directory, $name, $docCount, $delGen = 0, $hasSingleNormFile = false, $isCompound = null)
159,160d191
< $this->_name = $name;
< $this->_docCount = $docCount;
162c193,217
< $this->_termDictionary = null;
---
> $this->_name = $name;
> $this->_docCount = $docCount;
> $this->_hasSingleNormFile = $hasSingleNormFile;
> $this->_delGen = $delGen;
> $this->_termDictionary = null;
>
> if (!is_null($isCompound)) {
> $this->_isCompound = $isCompound;
> } else {
> // It's a pre-2.1 segment
> // detect if it uses compond file
> $this->_isCompound = true;
>
> try {
> // Try to open compound file
> $this->_directory->getFileObject($name . '.cfs');
> } catch (Zend_Search_Lucene_Exception $e) {
> if (strpos($e->getMessage(), 'is not readable') !== false) {
> // Compound file is not found or is not readable
> $this->_isCompound = false;
> } else {
> throw $e;
> }
> }
> }
165c220
< if ($this->_directory->fileExists($name . '.cfs')) {
---
> if ($this->_isCompound) {
205,210c260,279
< try {
< $delFile = $this->openCompoundFile('.del');
<
< $byteCount = $delFile->readInt();
< $byteCount = ceil($byteCount/8);
< $bitCount = $delFile->readInt();
---
> if ($this->_delGen == -1) {
> // There is no delete file for this segment
> // Do nothing
> } else if ($this->_delGen == 0) {
> // It's a segment with pre-2.1 format delete file
> // Try to find delete file
> try {
> // '.del' files always stored in a separate file
> // Segment compound is not used
> $delFile = $this->_directory->getFileObject($this->_name . '.del');
>
> $byteCount = $delFile->readInt();
> $byteCount = ceil($byteCount/8);
> $bitCount = $delFile->readInt();
>
> if ($bitCount == 0) {
> $delBytes = '';
> } else {
> $delBytes = $delFile->readBytes($byteCount);
> }
212,215c281,299
< if ($bitCount == 0) {
< $delBytes = '';
< } else {
< $delBytes = $delFile->readBytes($byteCount);
---
> if (extension_loaded('bitset')) {
> $this->_deleted = $delBytes;
> } else {
> $this->_deleted = array();
> for ($count = 0; $count < $byteCount; $count++) {
> $byte = ord($delBytes{$count});
> for ($bit = 0; $bit < 8; $bit++) {
> if ($byte & (1<<$bit)) {
> $this->_deleted[$count*8 + $bit] = 1;
> }
> }
> }
> }
> } catch(Zend_Search_Exception $e) {
> if (strpos($e->getMessage(), 'is not readable') === false ) {
> throw $e;
> }
> // There is no delete file
> // Do nothing
216a301,305
> } else {
> // It's 2.1+ format delete file
> $delFile = $this->_directory->getFileObject($this->_name . '_' . base_convert($this->_delGen, 10, 36) . '.del');
>
> $format = $delFile->readInt();
218,219c307,312
< if (extension_loaded('bitset')) {
< $this->_deleted = $delBytes;
---
> if ($format == (int)0xFFFFFFFF) {
> /**
> * @todo Implement support of DGaps delete file format.
> * See Lucene file format for details - http://lucene.apache.org/java/docs/fileformats.html#Deleted%20Documents
> */
> throw new Zend_Search_Lucene_Exception('DGaps delete file format is not supported. Optimize index to use it with Zend_Search_Lucene');
221,226c314,333
< $this->_deleted = array();
< for ($count = 0; $count < $byteCount; $count++) {
< $byte = ord($delBytes{$count});
< for ($bit = 0; $bit < 8; $bit++) {
< if ($byte & (1<<$bit)) {
< $this->_deleted[$count*8 + $bit] = 1;
---
> // $format is actually byte count
> $byteCount = ceil($format/8);
> $bitCount = $delFile->readInt();
>
> if ($bitCount == 0) {
> $delBytes = '';
> } else {
> $delBytes = $delFile->readBytes($byteCount);
> }
>
> if (extension_loaded('bitset')) {
> $this->_deleted = $delBytes;
> } else {
> $this->_deleted = array();
> for ($count = 0; $count < $byteCount; $count++) {
> $byte = ord($delBytes{$count});
> for ($bit = 0; $bit < 8; $bit++) {
> if ($byte & (1<<$bit)) {
> $this->_deleted[$count*8 + $bit] = 1;
> }
231,236d337
< } catch(Zend_Search_Exception $e) {
< if (strpos($e->getMessage(), 'compound file doesn\'t contain') !== false ) {
< $this->_deleted = null;
< } else {
< throw $e;
< }
252,253c353
< // Try to open common file first
< if ($this->_directory->fileExists($filename)) {
---
> if (!$this->_isCompound) {
258c358
< throw new Zend_Search_Lucene_Exception('Index compound file doesn\'t contain '
---
> throw new Zend_Search_Lucene_Exception('Segment compound file doesn\'t contain '
346a447,456
> * Returns actual deletions file generation number.
> *
> * @return integer
> */
> public function getDelGen()
> {
> return $this->_delGen;
> }
>
> /**
434a545,579
> * Load terms dictionary index
> *
> * @throws Zend_Search_Lucene_Exception
> */
> private function _loadDictionaryIndex()
> {
> // Check, if index is already serialized
> if ($this->_directory->fileExists($this->_name . '.sti')) {
> // Load serialized dictionary index data
> $stiFile = $this->_directory->getFileObject($this->_name . '.sti');
> $stiFileData = $stiFile->readBytes($this->_directory->fileLength($this->_name . '.sti'));
>
> // Load dictionary index data
> if (($unserializedData = @unserialize($stiFileData)) !== false) {
> list($this->_termDictionary, $this->_termDictionaryInfos) = $unserializedData;
> return;
> }
> }
>
> // Load data from .tii file and generate .sti file
>
> // Prefetch dictionary index data
> $tiiFile = $this->openCompoundFile('.tii');
> $tiiFileData = $tiiFile->readBytes($this->compoundFileLength('.tii'));
>
> // Load dictionary index data
> list($this->_termDictionary, $this->_termDictionaryInfos) =
> Zend_Search_Lucene_Index_DictionaryLoader::load($tiiFileData);
>
> $stiFileData = serialize(array($this->_termDictionary, $this->_termDictionaryInfos));
> $stiFile = $this->_directory->createFile($this->_name . '.sti');
> $stiFile->writeBytes($stiFileData);
> }
>
> /**
455,476c600
< // Check, if index is already serialized
< if ($this->_directory->fileExists($this->_name . '.sti')) {
< // Prefetch dictionary index data
< $stiFile = $this->_directory->getFileObject($this->_name . '.sti');
< $stiFileData = $stiFile->readBytes($this->_directory->fileLength($this->_name . '.sti'));
<
< // Load dictionary index data
< list($this->_termDictionary, $this->_termDictionaryInfos) = unserialize($stiFileData);
< } else {
< // Prefetch dictionary index data
< $tiiFile = $this->openCompoundFile('.tii');
< $tiiFileData = $tiiFile->readBytes($this->compoundFileLength('.tii'));
<
< // Load dictionary index data
< list($this->_termDictionary, $this->_termDictionaryInfos) =
< Zend_Search_Lucene_Index_DictionaryLoader::load($tiiFileData);
<
< $stiFileData = serialize(array($this->_termDictionary, $this->_termDictionaryInfos));
< $stiFile = $this->_directory->createFile($this->_name . '.sti');
< $stiFile->writeBytes($stiFileData);
< }
<
---
> $this->_loadDictionaryIndex();
479,480d602
<
<
529c651,652
< if ($tiVersion != (int)0xFFFFFFFE) {
---
> if ($tiVersion != (int)0xFFFFFFFE /* pre-2.1 format */ &&
> $tiVersion != (int)0xFFFFFFFD /* 2.1+ format */) {
535a659,661
> if ($tiVersion == (int)0xFFFFFFFD /* 2.1+ format */) {
> $maxSkipLevels = $tisFile->readInt();
> }
537c663
< $tisFile->seek($prevTermInfo[4] /* indexPointer */ - 20 /* header size*/, SEEK_CUR);
---
> $tisFile->seek($prevTermInfo[4] /* indexPointer */ - (($tiVersion == (int)0xFFFFFFFD)? 24 : 20) /* header size*/, SEEK_CUR);
668a795
> * @throws Zend_Search_Lucene_Exception
672,673c799,817
< $fFile = $this->openCompoundFile('.f' . $fieldNum);
< $this->_norms[$fieldNum] = $fFile->readBytes($this->_docCount);
---
> if ($this->_hasSingleNormFile) {
> $normfFile = $this->openCompoundFile('.nrm');
>
> $header = $normfFile->readBytes(3);
> $headerFormatVersion = $normfFile->readByte();
>
> if ($header != 'NRM' || $headerFormatVersion != (int)0xFF) {
> throw new Zend_Search_Lucene_Exception('Wrong norms file format.');
> }
>
> foreach ($this->_fields as $fieldNum => $fieldInfo) {
> if ($fieldInfo->isIndexed) {
> $this->_norms[$fieldNum] = $normfFile->readBytes($this->_docCount);
> }
> }
> } else {
> $fFile = $this->openCompoundFile('.f' . $fieldNum);
> $this->_norms[$fieldNum] = $fFile->readBytes($this->_docCount);
> }
734a879,898
> * Returns true if segment has single norms file.
> *
> * @return boolean
> */
> public function hasSingleNormFile()
> {
> return $this->_hasSingleNormFile ? 1 : 0;
> }
>
> /**
> * Returns true if segment is stored using compound segment file.
> *
> * @return boolean
> */
> public function isCompound()
> {
> return $this->_isCompound ? 1 : 0;
> }
>
> /**
806c970,998
< $delFile = $this->_directory->createFile($this->_name . '.del');
---
> // Get new generation number
> Zend_Search_Lucene_LockManager::obtainWriteLock($this->_directory);
>
> $delFileList = array();
> foreach ($this->_directory->fileList() as $file) {
> if ($file == $this->_name . '.del') {
> // Matches .del file name
> $delFileList[] = 0;
> } else if (preg_match('/^' . $this->_name . '_([a-zA-Z0-9]+)\.del$/i', $file, $matches)) {
> // Matches _NNN.del file names
> $delFileList[] = (int)base_convert($matches[1], 36, 10);
> }
> }
>
> if (count($delFileList) == 0) {
> // There is no deletions file for current segment in the directory
> // Set detetions file generation number to 1
> $this->_delGen = 1;
> } else {
> // There are some deletions files for current segment in the directory
> // Set detetions file generation number to the highest + 1
> $this->_delGen = max($delFileList) + 1;
> }
>
> $delFile = $this->_directory->createFile($this->_name . '_' . base_convert($this->_delGen, 10, 36) . '.del');
>
> Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory);
>
>
823a1016,1022
> * Actual offset of the .tis file data
> *
> * @var integer
> */
> private $_tisFileOffset;
>
> /**
831c1030
< * Offset of the .frq file in the compound file
---
> * Actual offset of the .frq file data
845c1044
< * Offset of the .prx file in the compound file
---
> * Actual offset of the .prx file in the compound file
853c1052
< * Number of terms in term stream
---
> * Actual number of terms in term stream
859a1059,1072
> * Overall number of terms in term stream
> *
> * @var integer
> */
> private $_termNum = 0;
>
> /**
> * Segment index interval
> *
> * @var integer
> */
> private $_indexInterval;
>
> /**
894c1107,1109
< * @var array
---
> * Is set to null if term positions loading has to be skipped
> *
> * @var array|null
897a1113,1132
>
> /**
> * Terms scan mode
> *
> * Values:
> *
> * self::SM_TERMS_ONLY - terms are scanned, no additional info is retrieved
> * self::SM_MERGE_INFO - terms are scanned, frequency and position info is retrieved
> * document numbers are compacted (shifted if segment has deleted documents)
> *
> * @var integer
> */
> private $_termsScanMode;
>
> /** Scan modes */
> const SM_TERMS_ONLY = 0; // terms are scanned, no additional info is retrieved
> const SM_FULL_INFO = 1; // terms are scanned, frequency and position info is retrieved
> const SM_MERGE_INFO = 2; // terms are scanned, frequency and position info is retrieved
> // document numbers are compacted (shifted if segment contains deleted documents)
>
907c1142
< * @param boolean $compact
---
> * @param integer $mode
911c1146
< public function reset($startId = 0, $compact = false)
---
> public function reset($startId = 0, $mode = self::SM_TERMS_ONLY)
917a1153,1154
> $this->_tisFileOffset = $this->_tisFile->tell();
>
919c1156,1157
< if ($tiVersion != (int)0xFFFFFFFE) {
---
> if ($tiVersion != (int)0xFFFFFFFE /* pre-2.1 format */ &&
> $tiVersion != (int)0xFFFFFFFD /* 2.1+ format */) {
923,925c1161,1167
< $this->_termCount = $this->_tisFile->readLong();
< $this->_tisFile->readInt(); // Read Index interval
< $this->_skipInterval = $this->_tisFile->readInt(); // Read skip interval
---
> $this->_termCount =
> $this->_termNum = $this->_tisFile->readLong(); // Read terms count
> $this->_indexInterval = $this->_tisFile->readInt(); // Read Index interval
> $this->_skipInterval = $this->_tisFile->readInt(); // Read skip interval
> if ($tiVersion == (int)0xFFFFFFFD /* 2.1+ format */) {
> $maxSkipLevels = $this->_tisFile->readInt();
> }
930,932d1171
< $this->_frqFile = $this->openCompoundFile('.frq', false);
< $this->_frqFileOffset = $this->_frqFile->tell();
<
936,937c1175
< $this->_prxFile = $this->openCompoundFile('.prx', false);
< $this->_prxFileOffset = $this->_prxFile->tell();
---
> $this->_docMap = array();
939,940c1177,1186
< $this->_lastTerm = new Zend_Search_Lucene_Index_Term('', -1);
< $this->_lastTermInfo = new Zend_Search_Lucene_Index_TermInfo(0, 0, 0, 0);
---
> $this->_lastTerm = new Zend_Search_Lucene_Index_Term('', -1);
> $this->_lastTermInfo = new Zend_Search_Lucene_Index_TermInfo(0, 0, 0, 0);
> $this->_lastTermPositions = null;
>
> $this->_termsScanMode = $mode;
>
> switch ($mode) {
> case self::SM_TERMS_ONLY:
> // Do nothing
> break;
942,946c1188,1206
< $this->_docMap = array();
< for ($count = 0; $count < $this->_docCount; $count++) {
< if (!$this->isDeleted($count)) {
< $this->_docMap[$count] = $startId + ($compact ? count($this->_docMap) : $count);
< }
---
> case self::SM_FULL_INFO:
> // break intentionally omitted
> case self::SM_MERGE_INFO:
> $this->_frqFile = $this->openCompoundFile('.frq', false);
> $this->_frqFileOffset = $this->_frqFile->tell();
>
> $this->_prxFile = $this->openCompoundFile('.prx', false);
> $this->_prxFileOffset = $this->_prxFile->tell();
>
> for ($count = 0; $count < $this->_docCount; $count++) {
> if (!$this->isDeleted($count)) {
> $this->_docMap[$count] = $startId + (($mode == self::SM_MERGE_INFO) ? count($this->_docMap) : $count);
> }
> }
> break;
>
> default:
> throw new Zend_Search_Lucene_Exception('Wrong terms scaning mode specified.');
> break;
948a1209
>
950c1211,1358
< return $startId + ($compact ? count($this->_docMap) : $this->_docCount);
---
> return $startId + (($mode == self::SM_MERGE_INFO) ? count($this->_docMap) : $this->_docCount);
> }
>
>
> /**
> * Skip terms stream up to specified term preffix.
> *
> * Prefix contains fully specified field info and portion of searched term
> *
> * @param Zend_Search_Lucene_Index_Term $prefix
> * @throws Zend_Search_Lucene_Exception
> */
> public function skipTo(Zend_Search_Lucene_Index_Term $prefix)
> {
> if ($this->_termDictionary === null) {
> $this->_loadDictionaryIndex();
> }
>
> $searchField = $this->getFieldNum($prefix->field);
>
> if ($searchField == -1) {
> /**
> * Field is not presented in this segment
> * Go to the end of dictionary
> */
> $this->_tisFile = null;
> $this->_frqFile = null;
> $this->_prxFile = null;
>
> $this->_lastTerm = null;
> $this->_lastTermInfo = null;
> $this->_lastTermPositions = null;
>
> return;
> }
> $searchDicField = $this->_getFieldPosition($searchField);
>
> // search for appropriate value in dictionary
> $lowIndex = 0;
> $highIndex = count($this->_termDictionary)-1;
> while ($highIndex >= $lowIndex) {
> // $mid = ($highIndex - $lowIndex)/2;
> $mid = ($highIndex + $lowIndex) >> 1;
> $midTerm = $this->_termDictionary[$mid];
>
> $fieldNum = $this->_getFieldPosition($midTerm[0] /* field */);
> $delta = $searchDicField - $fieldNum;
> if ($delta == 0) {
> $delta = strcmp($prefix->text, $midTerm[1] /* text */);
> }
>
> if ($delta < 0) {
> $highIndex = $mid-1;
> } elseif ($delta > 0) {
> $lowIndex = $mid+1;
> } else {
> // We have reached term we are looking for
> break;
> }
> }
>
> if ($highIndex == -1) {
> // Term is out of the dictionary range
> $this->_tisFile = null;
> $this->_frqFile = null;
> $this->_prxFile = null;
>
> $this->_lastTerm = null;
> $this->_lastTermInfo = null;
> $this->_lastTermPositions = null;
>
> return;
> }
>
> $prevPosition = $highIndex;
> $prevTerm = $this->_termDictionary[$prevPosition];
> $prevTermInfo = $this->_termDictionaryInfos[$prevPosition];
>
> if ($this->_tisFile === null) {
> // The end of terms stream is reached and terms dictionary file is closed
> // Perform mini-reset operation
> $this->_tisFile = $this->openCompoundFile('.tis', false);
>
> if ($this->_termsScanMode == self::SM_FULL_INFO || $this->_termsScanMode == self::SM_MERGE_INFO) {
> $this->_frqFile = $this->openCompoundFile('.frq', false);
> $this->_prxFile = $this->openCompoundFile('.prx', false);
> }
> }
> $this->_tisFile->seek($this->_tisFileOffset + $prevTermInfo[4], SEEK_SET);
>
> $this->_lastTerm = new Zend_Search_Lucene_Index_Term($prevTerm[1] /* text */,
> ($prevTerm[0] == -1) ? '' : $this->_fields[$prevTerm[0] /* field */]->name);
> $this->_lastTermInfo = new Zend_Search_Lucene_Index_TermInfo($prevTermInfo[0] /* docFreq */,
> $prevTermInfo[1] /* freqPointer */,
> $prevTermInfo[2] /* proxPointer */,
> $prevTermInfo[3] /* skipOffset */);
> $this->_termCount = $this->_termNum - $prevPosition*$this->_indexInterval;
>
> if ($highIndex == 0) {
> // skip start entry
> $this->nextTerm();
> } else if ($prefix->field == $this->_lastTerm->field && $prefix->text == $this->_lastTerm->text) {
> // We got exact match in the dictionary index
>
> if ($this->_termsScanMode == self::SM_FULL_INFO || $this->_termsScanMode == self::SM_MERGE_INFO) {
> $this->_lastTermPositions = array();
>
> $this->_frqFile->seek($this->_lastTermInfo->freqPointer + $this->_frqFileOffset, SEEK_SET);
> $freqs = array(); $docId = 0;
> for( $count = 0; $count < $this->_lastTermInfo->docFreq; $count++ ) {
> $docDelta = $this->_frqFile->readVInt();
> if( $docDelta % 2 == 1 ) {
> $docId += ($docDelta-1)/2;
> $freqs[ $docId ] = 1;
> } else {
> $docId += $docDelta/2;
> $freqs[ $docId ] = $this->_frqFile->readVInt();
> }
> }
>
> $this->_prxFile->seek($this->_lastTermInfo->proxPointer + $this->_prxFileOffset, SEEK_SET);
> foreach ($freqs as $docId => $freq) {
> $termPosition = 0; $positions = array();
>
> for ($count = 0; $count < $freq; $count++ ) {
> $termPosition += $this->_prxFile->readVInt();
> $positions[] = $termPosition;
> }
>
> if (isset($this->_docMap[$docId])) {
> $this->_lastTermPositions[$this->_docMap[$docId]] = $positions;
> }
> }
> }
>
> return;
> }
>
> // Search term matching specified prefix
> while ($this->_lastTerm !== null) {
> if ( strcmp($this->_lastTerm->field, $prefix->field) > 0 ||
> ($prefix->field == $this->_lastTerm->field && strcmp($this->_lastTerm->text, $prefix->text) >= 0) ) {
> // Current term matches or greate than the pattern
> return;
> }
>
> $this->nextTerm();
> }
962,963c1370,1373
< $this->_lastTerm = null;
< $this->_lastTermInfo = null;
---
> $this->_lastTerm = null;
> $this->_lastTermInfo = null;
> $this->_lastTermPositions = null;
> $this->_docMap = null;
992c1402,1403
< $this->_lastTermPositions = array();
---
> if ($this->_termsScanMode == self::SM_FULL_INFO || $this->_termsScanMode == self::SM_MERGE_INFO) {
> $this->_lastTermPositions = array();
994,1003c1405,1415
< $this->_frqFile->seek($this->_lastTermInfo->freqPointer + $this->_frqFileOffset, SEEK_SET);
< $freqs = array(); $docId = 0;
< for( $count = 0; $count < $this->_lastTermInfo->docFreq; $count++ ) {
< $docDelta = $this->_frqFile->readVInt();
< if( $docDelta % 2 == 1 ) {
< $docId += ($docDelta-1)/2;
< $freqs[ $docId ] = 1;
< } else {
< $docId += $docDelta/2;
< $freqs[ $docId ] = $this->_frqFile->readVInt();
---
> $this->_frqFile->seek($this->_lastTermInfo->freqPointer + $this->_frqFileOffset, SEEK_SET);
> $freqs = array(); $docId = 0;
> for( $count = 0; $count < $this->_lastTermInfo->docFreq; $count++ ) {
> $docDelta = $this->_frqFile->readVInt();
> if( $docDelta % 2 == 1 ) {
> $docId += ($docDelta-1)/2;
> $freqs[ $docId ] = 1;
> } else {
> $docId += $docDelta/2;
> $freqs[ $docId ] = $this->_frqFile->readVInt();
> }
1005d1416
< }
1007,1014c1418,1425
< $this->_prxFile->seek($this->_lastTermInfo->proxPointer + $this->_prxFileOffset, SEEK_SET);
< foreach ($freqs as $docId => $freq) {
< $termPosition = 0; $positions = array();
<
< for ($count = 0; $count < $freq; $count++ ) {
< $termPosition += $this->_prxFile->readVInt();
< $positions[] = $termPosition;
< }
---
> $this->_prxFile->seek($this->_lastTermInfo->proxPointer + $this->_prxFileOffset, SEEK_SET);
> foreach ($freqs as $docId => $freq) {
> $termPosition = 0; $positions = array();
>
> for ($count = 0; $count < $freq; $count++ ) {
> $termPosition += $this->_prxFile->readVInt();
> $positions[] = $termPosition;
> }
1016,1017c1427,1429
< if (isset($this->_docMap[$docId])) {
< $this->_lastTermPositions[$this->_docMap[$docId]] = $positions;
---
> if (isset($this->_docMap[$docId])) {
> $this->_lastTermPositions[$this->_docMap[$docId]] = $positions;
> }
1021d1432
<
1031a1443,1460
> /**
> * Close terms stream
> *
> * Should be used for resources clean up if stream is not read up to the end
> */
> public function closeTermsStream()
> {
> $this->_tisFile = null;
> $this->_frqFile = null;
> $this->_prxFile = null;
>
> $this->_lastTerm = null;
> $this->_lastTermInfo = null;
> $this->_lastTermPositions = null;
>
> $this->_docMap = null;
> }
>
1036d1464
< * @param Zend_Search_Lucene_Index_Term $term
Index: Zend/Search/Lucene/Index/SegmentInfoPriorityQueue.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Index/SegmentInfoPriorityQueue.php,v
retrieving revision 1.1
diff -r1.1 SegmentInfoPriorityQueue.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/PriorityQueue.php';
---
> require_once 'Zend/Search/Lucene/PriorityQueue.php';
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Index/SegmentMerger.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Index/SegmentMerger.php,v
retrieving revision 1.1
diff -r1.1 SegmentMerger.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/SegmentInfo.php';
---
> require_once 'Zend/Search/Lucene/Index/SegmentInfo.php';
30c30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/SegmentWriter/StreamWriter.php';
---
> require_once 'Zend/Search/Lucene/Index/SegmentWriter/StreamWriter.php';
33c33
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/SegmentInfoPriorityQueue.php';
---
> require_once 'Zend/Search/Lucene/Index/SegmentInfoPriorityQueue.php';
40c40
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
235c235
< $segmentStartId = $segmentInfo->reset($segmentStartId, true);
---
> $segmentStartId = $segmentInfo->reset($segmentStartId, Zend_Search_Lucene_Index_SegmentInfo::SM_MERGE_INFO);
Index: Zend/Search/Lucene/Index/SegmentWriter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Index/SegmentWriter.php,v
retrieving revision 1.2
diff -r1.2 SegmentWriter.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/SegmentInfo.php';
---
> require_once 'Zend/Search/Lucene/Index/SegmentInfo.php';
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
50c50,51
< /** Expert: The fraction of TermDocs entries stored in skip tables.
---
> /**
> * Expert: The fraction of TermDocs entries stored in skip tables.
56,57c57,59
< * 0x0x7FFFFFFF indicates that we don't use skip data
< * Default value is 16
---
> * 0x7FFFFFFF indicates that we don't use skip data
> *
> * Note: not used in current implementation
63a66,77
> * Expert: The maximum number of skip levels. Smaller values result in
> * slightly smaller indexes, but slower skipping in big posting lists.
> *
> * 0 indicates that we don't use skip data
> *
> * Note: not used in current implementation
> *
> * @var integer
> */
> public static $maxSkipLevels = 0;
>
> /**
248a263,272
> * Return segment name
> *
> * @return string
> */
> public function getName()
> {
> return $this->_name;
> }
>
> /**
255a280,285
> $nrmFile = $this->_directory->createFile($this->_name . '.nrm');
> // Write header
> $nrmFile->writeBytes('NRM');
> // Write format specifier
> $nrmFile->writeByte((int)0xFF);
>
265,268c295,301
< $normFileName = $this->_name . '.f' . $field->number;
< $fFile = $this->_directory->createFile($normFileName);
< $fFile->writeBytes($this->_norms[$field->name]);
< $this->_files[] = $normFileName;
---
> // pre-2.1 index mode (not used now)
> // $normFileName = $this->_name . '.f' . $field->number;
> // $fFile = $this->_directory->createFile($normFileName);
> // $fFile->writeBytes($this->_norms[$field->name]);
> // $this->_files[] = $normFileName;
>
> $nrmFile->writeBytes($this->_norms[$field->name]);
272a306
> $this->_files[] = $this->_name . '.nrm';
354c388
< $this->_tisFile->writeInt((int)0xFFFFFFFE);
---
> $this->_tisFile->writeInt((int)0xFFFFFFFD);
357a392
> $this->_tisFile->writeInt(self::$maxSkipLevels);
360c395
< $this->_tiiFile->writeInt((int)0xFFFFFFFE);
---
> $this->_tiiFile->writeInt((int)0xFFFFFFFD);
363a399
> $this->_tiiFile->writeInt(self::$maxSkipLevels);
373c409
< $this->_tiiFile->writeVInt(20); // IndexDelta
---
> $this->_tiiFile->writeVInt(24); // IndexDelta
387c423
< $this->_lastIndexPosition = 20;
---
> $this->_lastIndexPosition = 24;
Index: Zend/Search/Lucene/Index/Term.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Index/Term.php,v
retrieving revision 1.2
diff -r1.2 Term.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
76a77
> * @param string $str
106a108,141
>
> /**
> * Get UTF-8 string length
> *
> * @param string $str
> * @return string
> */
> public static function getLength($str)
> {
> $bytes = 0;
> $chars = 0;
> while ($bytes < strlen($str)) {
> $charBytes = 1;
> if ((ord($str[$bytes]) & 0xC0) == 0xC0) {
> $charBytes++;
> if (ord($str[$bytes]) & 0x20 ) {
> $charBytes++;
> if (ord($str[$bytes]) & 0x10 ) {
> $charBytes++;
> }
> }
> }
>
> if ($bytes + $charBytes > strlen($str)) {
> // wrong character
> break;
> }
>
> $chars++;
> $bytes += $charBytes;
> }
>
> return $chars;
> }
Index: Zend/Search/Lucene/Index/TermInfo.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Index/TermInfo.php,v
retrieving revision 1.2
diff -r1.2 TermInfo.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
29c29
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Index/Writer.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Index/Writer.php,v
retrieving revision 1.2
diff -r1.2 Writer.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
23,24c23,24
< /** Zend_Search_Lucene_Index_SegmentWriter_ */
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/SegmentWriter/DocumentWriter.php';
---
> /** Zend_Search_Lucene_Index_SegmentWriter_DocumentWriter */
> require_once 'Zend/Search/Lucene/Index/SegmentWriter/DocumentWriter.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/SegmentInfo.php';
---
> require_once 'Zend/Search/Lucene/Index/SegmentInfo.php';
30c30,33
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/SegmentMerger.php';
---
> require_once 'Zend/Search/Lucene/Index/SegmentMerger.php';
>
> /** Zend_Search_Lucene_LockManager */
> require_once 'Zend/Search/Lucene/LockManager.php';
38c41
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
156a160
>
158,163c162
< * Opens the index for writing
< *
< * IndexWriter constructor needs Directory as a parameter. It should be
< * a string with a path to the index folder or a Directory object.
< * Second constructor parameter create is optional - true to create the
< * index or overwrite the existing one.
---
> * Create empty index
166,167c165,166
< * @param array $segmentInfos
< * @param boolean $create
---
> * @param integer $generation
> * @param integer $nameCount
169c168
< public function __construct(Zend_Search_Lucene_Storage_Directory $directory, &$segmentInfos, $create = false)
---
> public static function createIndex(Zend_Search_Lucene_Storage_Directory $directory, $generation, $nameCount)
171,172c170,171
< $this->_directory = $directory;
< $this->_segmentInfos = &$segmentInfos;
---
> if ($generation == 0) {
> // Create index in pre-2.1 mode
174,175c173
< if ($create) {
< foreach ($this->_directory->fileList() as $file) {
---
> foreach ($directory->fileList() as $file) {
180c178
< $this->_directory->deleteFile($file);
---
> $directory->deleteFile($file);
183c181,182
< $segmentsFile = $this->_directory->createFile('segments');
---
>
> $segmentsFile = $directory->createFile('segments');
193c192
< $segmentsFile->writeInt(0);
---
> $segmentsFile->writeInt($nameCount);
197c196
< $deletableFile = $this->_directory->createFile('deletable');
---
> $deletableFile = $directory->createFile('deletable');
201,205c200,219
< $segmentsFile = $this->_directory->getFileObject('segments');
< $format = $segmentsFile->readInt();
< if ($format != (int)0xFFFFFFFF) {
< throw new Zend_Search_Lucene_Exception('Wrong segments file format');
< }
---
> $genFile = $directory->createFile('segments.gen');
>
> $genFile->writeInt((int)0xFFFFFFFE);
> // Write generation two times
> $genFile->writeLong($generation);
> $genFile->writeLong($generation);
>
> $segmentsFile = $directory->createFile(Zend_Search_Lucene::getSegmentFileName($generation));
> $segmentsFile->writeInt((int)0xFFFFFFFD);
>
> // write version (is initialized by current time
> // $segmentsFile->writeLong((int)microtime(true));
> $version = microtime(true);
> $segmentsFile->writeInt((int)($version/((double)0xFFFFFFFF + 1)));
> $segmentsFile->writeInt((int)($version & 0xFFFFFFFF));
>
> // write name counter
> $segmentsFile->writeInt($nameCount);
> // write segment counter
> $segmentsFile->writeInt(0);
209a224,241
> * Open the index for writing
> *
> * IndexWriter constructor needs Directory as a parameter. It should be
> * a string with a path to the index folder or a Directory object.
> * Second constructor parameter create is optional - true to create the
> * index or overwrite the existing one.
> *
> * @param Zend_Search_Lucene_Storage_Directory $directory
> * @param array $segmentInfos
> * @param Zend_Search_Lucene_Storage_File $cleanUpLock
> */
> public function __construct(Zend_Search_Lucene_Storage_Directory $directory, &$segmentInfos)
> {
> $this->_directory = $directory;
> $this->_segmentInfos = &$segmentInfos;
> }
>
> /**
226,227d257
< $this->_versionUpdate++;
<
228a259,260
>
> $this->_versionUpdate++;
232a265,308
> * Check if we have anything to merge
> *
> * @return boolean
> */
> private function _hasAnythingToMerge()
> {
> $segmentSizes = array();
> foreach ($this->_segmentInfos as $segName => $segmentInfo) {
> $segmentSizes[$segName] = $segmentInfo->count();
> }
>
> $mergePool = array();
> $poolSize = 0;
> $sizeToMerge = $this->maxBufferedDocs;
> asort($segmentSizes, SORT_NUMERIC);
> foreach ($segmentSizes as $segName => $size) {
> // Check, if segment comes into a new merging block
> while ($size >= $sizeToMerge) {
> // Merge previous block if it's large enough
> if ($poolSize >= $sizeToMerge) {
> return true;
> }
> $mergePool = array();
> $poolSize = 0;
>
> $sizeToMerge *= $this->mergeFactor;
>
> if ($sizeToMerge > $this->maxMergeDocs) {
> return false;
> }
> }
>
> $mergePool[] = $this->_segmentInfos[$segName];
> $poolSize += $size;
> }
>
> if ($poolSize >= $sizeToMerge) {
> return true;
> }
>
> return false;
> }
>
> /**
236a313,327
> if (Zend_Search_Lucene_LockManager::obtainOptimizationLock($this->_directory) === false) {
> return;
> }
>
>
> if (!$this->_hasAnythingToMerge()) {
> Zend_Search_Lucene_LockManager::releaseOptimizationLock($this->_directory);
> return;
> }
>
> // Update segments list to be sure all segments are not merged yet by other process
> $this->_updateSegments();
>
>
> // Perform standard auto-optimization procedure
238,239c329,330
< foreach ($this->_segmentInfos as $segId => $segmentInfo) {
< $segmentSizes[$segId] = $segmentInfo->count();
---
> foreach ($this->_segmentInfos as $segName => $segmentInfo) {
> $segmentSizes[$segName] = $segmentInfo->count();
246c337
< foreach ($segmentSizes as $segId => $size) {
---
> foreach ($segmentSizes as $segName => $size) {
258a350
> Zend_Search_Lucene_LockManager::releaseOptimizationLock($this->_directory);
263c355
< $mergePool[] = $this->_segmentInfos[$segId];
---
> $mergePool[] = $this->_segmentInfos[$segName];
269a362,363
>
> Zend_Search_Lucene_LockManager::releaseOptimizationLock($this->_directory);
281,287d374
< // Try to get exclusive non-blocking lock to the 'index.optimization.lock'
< // Skip optimization if it's performed by other process right now
< $optimizationLock = $this->_directory->createFile('index.optimization.lock');
< if (!$optimizationLock->lock(LOCK_EX,true)) {
< return;
< }
<
302,304d388
<
< // optimization is finished
< $optimizationLock->unlock();
315,364c399
< // Wait, until all parallel searchers or indexers won't stop
< // and stop all next searchers, while we are updating segments file
< $lock = $this->_directory->getFileObject('index.lock');
< if (!$lock->lock(LOCK_EX)) {
< throw new Zend_Search_Lucene_Exception('Can\'t obtain exclusive index lock');
< }
<
<
< // Do not share file handlers to get file updates from other sessions.
< $segmentsFile = $this->_directory->getFileObject('segments', false);
< $newSegmentFile = $this->_directory->createFile('segments.new', false);
<
< // Write format marker
< $newSegmentFile->writeInt((int)0xFFFFFFFF);
<
< // Write index version
< $segmentsFile->seek(4, SEEK_CUR);
< // $version = $segmentsFile->readLong() + $this->_versionUpdate;
< // Process version on 32-bit platforms
< $versionHigh = $segmentsFile->readInt();
< $versionLow = $segmentsFile->readInt();
< $version = $versionHigh * ((double)0xFFFFFFFF + 1) +
< (($versionLow < 0)? (double)0xFFFFFFFF - (-1 - $versionLow) : $versionLow);
< $version += $this->_versionUpdate;
< $this->_versionUpdate = 0;
< $newSegmentFile->writeInt((int)($version/((double)0xFFFFFFFF + 1)));
< $newSegmentFile->writeInt((int)($version & 0xFFFFFFFF));
<
< // Write segment name counter
< $newSegmentFile->writeInt($segmentsFile->readInt());
<
< // Get number of segments offset
< $numOfSegmentsOffset = $newSegmentFile->tell();
< // Write number of segemnts
< $segmentsCount = $segmentsFile->readInt();
< $newSegmentFile->writeInt(0); // Write dummy data (segment counter)
<
< $segments = array();
< for ($count = 0; $count < $segmentsCount; $count++) {
< $segName = $segmentsFile->readString();
< $segSize = $segmentsFile->readInt();
<
< if (!in_array($segName, $this->_segmentsToDelete)) {
< $newSegmentFile->writeString($segName);
< $newSegmentFile->writeInt($segSize);
<
< $segments[$segName] = $segSize;
< }
< }
< $segmentsFile->close();
---
> Zend_Search_Lucene_LockManager::obtainWriteLock($this->_directory);
366,373c401,409
< $segmentsCount = count($segments) + count($this->_newSegments);
<
< // Remove segments, not listed in $segments (deleted)
< // Load segments, not listed in $this->_segmentInfos
< foreach ($this->_segmentInfos as $segId => $segInfo) {
< if (isset($segments[$segInfo->getName()])) {
< // Segment is already included into $this->_segmentInfos
< unset($segments[$segInfo->getName()]);
---
> $generation = Zend_Search_Lucene::getActualGeneration($this->_directory);
> $segmentsFile = $this->_directory->getFileObject(Zend_Search_Lucene::getSegmentFileName($generation), false);
> $newSegmentFile = $this->_directory->createFile(Zend_Search_Lucene::getSegmentFileName(++$generation), false);
>
> try {
> $genFile = $this->_directory->getFileObject('segments.gen', false);
> } catch (Zend_Search_Lucene_Exception $e) {
> if (strpos($e->getMessage(), 'is not readable') !== false) {
> $genFile = $this->_directory->createFile('segments.gen');
375,376c411
< // remove deleted segment from a list
< unset($this->_segmentInfos[$segId]);
---
> throw $e;
379,405c414,625
< // $segments contains a list of segments to load
< // do it later
<
< foreach ($this->_newSegments as $segName => $segmentInfo) {
< $newSegmentFile->writeString($segName);
< $newSegmentFile->writeInt($segmentInfo->count());
<
< $this->_segmentInfos[] = $segmentInfo;
< }
< $this->_newSegments = array();
<
< $newSegmentFile->seek($numOfSegmentsOffset);
< $newSegmentFile->writeInt($segmentsCount); // Update segments count
< $newSegmentFile->close();
< $this->_directory->renameFile('segments.new', 'segments');
<
<
< // Segments file update is finished
< // Switch back to shared lock mode
< $lock->lock(LOCK_SH);
<
<
< $fileList = $this->_directory->fileList();
< foreach ($this->_segmentsToDelete as $nameToDelete) {
< foreach (self::$_indexExtensions as $ext) {
< if ($this->_directory->fileExists($nameToDelete . $ext)) {
< $this->_directory->deleteFile($nameToDelete . $ext);
---
>
> $genFile->writeInt((int)0xFFFFFFFE);
> // Write generation (first copy)
> $genFile->writeLong($generation);
>
> try {
> // Write format marker
> $newSegmentFile->writeInt((int)0xFFFFFFFD);
>
> // Skip format identifier
> $segmentsFile->seek(4, SEEK_CUR);
> // $version = $segmentsFile->readLong() + $this->_versionUpdate;
> // Process version on 32-bit platforms
> $versionHigh = $segmentsFile->readInt();
> $versionLow = $segmentsFile->readInt();
> $version = $versionHigh * ((double)0xFFFFFFFF + 1) +
> (($versionLow < 0)? (double)0xFFFFFFFF - (-1 - $versionLow) : $versionLow);
> $version += $this->_versionUpdate;
> $this->_versionUpdate = 0;
> $newSegmentFile->writeInt((int)($version/((double)0xFFFFFFFF + 1)));
> $newSegmentFile->writeInt((int)($version & 0xFFFFFFFF));
>
> // Write segment name counter
> $newSegmentFile->writeInt($segmentsFile->readInt());
>
> // Get number of segments offset
> $numOfSegmentsOffset = $newSegmentFile->tell();
> // Write dummy data (segment counter)
> $newSegmentFile->writeInt(0);
>
> // Read number of segemnts
> $segmentsCount = $segmentsFile->readInt();
>
> $segments = array();
> for ($count = 0; $count < $segmentsCount; $count++) {
> $segName = $segmentsFile->readString();
> $segSize = $segmentsFile->readInt();
>
> if ($generation == 1 /* retrieved generation is 0 */) {
> // pre-2.1 index format
> $delGenHigh = 0;
> $delGenLow = 0;
> $hasSingleNormFile = false;
> $numField = (int)0xFFFFFFFF;
> $isCompound = 1;
> } else {
> //$delGen = $segmentsFile->readLong();
> $delGenHigh = $segmentsFile->readInt();
> $delGenLow = $segmentsFile->readInt();
> $hasSingleNormFile = $segmentsFile->readByte();
> $numField = $segmentsFile->readInt();
>
> $normGens = array();
> if ($numField != (int)0xFFFFFFFF) {
> for ($count1 = 0; $count1 < $numField; $count1++) {
> $normGens[] = $segmentsFile->readLong();
> }
> }
> $isCompound = $segmentsFile->readByte();
> }
>
> if (!in_array($segName, $this->_segmentsToDelete)) {
> // Load segment if necessary
> if (!isset($this->_segmentInfos[$segName])) {
> $delGen = $delGenHigh * ((double)0xFFFFFFFF + 1) +
> (($delGenLow < 0)? (double)0xFFFFFFFF - (-1 - $delGenLow) : $delGenLow);
> $this->_segmentInfos[$segName] =
> new Zend_Search_Lucene_Index_SegmentInfo($this->_directory,
> $segName,
> $segSize,
> $delGen,
> $hasSingleNormFile,
> $isCompound);
> } else {
> // Retrieve actual detetions file generation number
> $delGen = $this->_segmentInfos[$segName]->getDelGen();
>
> if ($delGen >= 0) {
> $delGenHigh = (int)($delGen/((double)0xFFFFFFFF + 1));
> $delGenLow =(int)($delGen & 0xFFFFFFFF);
> } else {
> $delGenHigh = $delGenLow = (int)0xFFFFFFFF;
> }
> }
>
> $newSegmentFile->writeString($segName);
> $newSegmentFile->writeInt($segSize);
> $newSegmentFile->writeInt($delGenHigh);
> $newSegmentFile->writeInt($delGenLow);
> $newSegmentFile->writeByte($hasSingleNormFile);
> $newSegmentFile->writeInt($numField);
> if ($numField != (int)0xFFFFFFFF) {
> foreach ($normGens as $normGen) {
> $newSegmentFile->writeLong($normGen);
> }
> }
> $newSegmentFile->writeByte($isCompound);
>
> $segments[$segName] = $segSize;
> }
> }
> $segmentsFile->close();
>
> $segmentsCount = count($segments) + count($this->_newSegments);
>
> foreach ($this->_newSegments as $segName => $segmentInfo) {
> $newSegmentFile->writeString($segName);
> $newSegmentFile->writeInt($segmentInfo->count());
>
> // delete file generation: -1 (there is no delete file yet)
> $newSegmentFile->writeInt((int)0xFFFFFFFF);$newSegmentFile->writeInt((int)0xFFFFFFFF);
> // HasSingleNormFile
> $newSegmentFile->writeByte($segmentInfo->hasSingleNormFile());
> // NumField
> $newSegmentFile->writeInt((int)0xFFFFFFFF);
> // IsCompoundFile
> $newSegmentFile->writeByte($segmentInfo->isCompound());
>
> $segments[$segmentInfo->getName()] = $segmentInfo->count();
> $this->_segmentInfos[$segName] = $segmentInfo;
> }
> $this->_newSegments = array();
>
> $newSegmentFile->seek($numOfSegmentsOffset);
> $newSegmentFile->writeInt($segmentsCount); // Update segments count
> $newSegmentFile->close();
> } catch (Exception $e) {
> /** Restore previous index generation */
> $generation--;
> $genFile->seek(4, SEEK_SET);
> // Write generation number twice
> $genFile->writeLong($generation); $genFile->writeLong($generation);
>
> // Release index write lock
> Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory);
>
> // Throw the exception
> throw $e;
> }
>
> // Write generation (second copy)
> $genFile->writeLong($generation);
>
>
> // Check if another update process is not running now
> // If yes, skip clean-up procedure
> if (Zend_Search_Lucene_LockManager::escalateReadLock($this->_directory)) {
> /**
> * Clean-up directory
> */
> $filesToDelete = array();
> $filesTypes = array();
> $filesNumbers = array();
>
> // list of .del files of currently used segments
> // each segment can have several generations of .del files
> // only last should not be deleted
> $delFiles = array();
>
> foreach ($this->_directory->fileList() as $file) {
> if ($file == 'deletable') {
> // 'deletable' file
> $filesToDelete[] = $file;
> $filesTypes[] = 0; // delete this file first, since it's not used starting from Lucene v2.1
> $filesNumbers[] = 0;
> } else if ($file == 'segments') {
> // 'segments' file
>
> $filesToDelete[] = $file;
> $filesTypes[] = 1; // second file to be deleted "zero" version of segments file (Lucene pre-2.1)
> $filesNumbers[] = 0;
> } else if (preg_match('/^segments_[a-zA-Z0-9]+$/i', $file)) {
> // 'segments_xxx' file
> // Check if it's not a just created generation file
> if ($file != Zend_Search_Lucene::getSegmentFileName($generation)) {
> $filesToDelete[] = $file;
> $filesTypes[] = 2; // first group of files for deletions
> $filesNumbers[] = (int)base_convert(substr($file, 9), 36, 10); // ordered by segment generation numbers
> }
> } else if (preg_match('/(^_([a-zA-Z0-9]+))\.f\d+$/i', $file, $matches)) {
> // one of per segment files ('.f')
> // Check if it's not one of the segments in the current segments set
> if (!isset($segments[$matches[1]])) {
> $filesToDelete[] = $file;
> $filesTypes[] = 3; // second group of files for deletions
> $filesNumbers[] = (int)base_convert($matches[2], 36, 10); // order by segment number
> }
> } else if (preg_match('/(^_([a-zA-Z0-9]+))(_([a-zA-Z0-9]+))\.del$/i', $file, $matches)) {
> // one of per segment files ('_.del' where is '_')
> // Check if it's not one of the segments in the current segments set
> if (!isset($segments[$matches[1]])) {
> $filesToDelete[] = $file;
> $filesTypes[] = 3; // second group of files for deletions
> $filesNumbers[] = (int)base_convert($matches[2], 36, 10); // order by segment number
> } else {
> $segmentNumber = (int)base_convert($matches[2], 36, 10);
> $delGeneration = (int)base_convert($matches[4], 36, 10);
> if (!isset($delFiles[$segmentNumber])) {
> $delFiles[$segmentNumber] = array();
> }
> $delFiles[$segmentNumber][$delGeneration] = $file;
> }
> } else if (isset(self::$_indexExtensions[substr($file, strlen($file)-4)])) {
> // one of per segment files ('.')
> $segmentName = substr($file, 0, strlen($file) - 4);
> // Check if it's not one of the segments in the current segments set
> if (!isset($segments[$segmentName]) &&
> ($this->_currentSegment === null || $this->_currentSegment->getName() != $segmentName)) {
> $filesToDelete[] = $file;
> $filesTypes[] = 3; // second group of files for deletions
> $filesNumbers[] = (int)base_convert(substr($file, 1 /* skip '_' */, strlen($file)-5), 36, 10); // order by segment number
> }
409,412c629,661
< foreach ($fileList as $file) {
< if (substr($file, 0, strlen($nameToDelete) + 2) == ($nameToDelete . '.f') &&
< ctype_digit( substr($file, strlen($nameToDelete) + 2) )) {
< $this->_directory->deleteFile($file);
---
> $maxGenNumber = 0;
> // process .del files of currently used segments
> foreach ($delFiles as $segmentNumber => $segmentDelFiles) {
> ksort($delFiles[$segmentNumber], SORT_NUMERIC);
> array_pop($delFiles[$segmentNumber]); // remove last delete file generation from candidates for deleting
>
> end($delFiles[$segmentNumber]);
> $lastGenNumber = key($delFiles[$segmentNumber]);
> if ($lastGenNumber > $maxGenNumber) {
> $maxGenNumber = $lastGenNumber;
> }
> }
> foreach ($delFiles as $segmentNumber => $segmentDelFiles) {
> foreach ($segmentDelFiles as $delGeneration => $file) {
> $filesToDelete[] = $file;
> $filesTypes[] = 4; // third group of files for deletions
> $filesNumbers[] = $segmentNumber*$maxGenNumber + $delGeneration; // order by , pair
> }
> }
>
> // Reorder files for deleting
> array_multisort($filesTypes, SORT_ASC, SORT_NUMERIC,
> $filesNumbers, SORT_ASC, SORT_NUMERIC,
> $filesToDelete, SORT_ASC, SORT_STRING);
>
> foreach ($filesToDelete as $file) {
> try {
> $this->_directory->deleteFile($file);
> } catch (Zend_Search_Lucene_Exception $e) {
> if (strpos($e->getMessage(), 'Can\'t delete file') === false) {
> // That's not "file is under processing or already deleted" exception
> // Pass it through
> throw $e;
413a663,673
> }
> }
>
> // Return read lock into the previous state
> Zend_Search_Lucene_LockManager::deEscalateReadLock($this->_directory);
> } else {
> // Only release resources if another index reader is running now
> foreach ($this->_segmentsToDelete as $segName) {
> foreach (self::$_indexExtensions as $ext) {
> $this->_directory->purgeFile($segName . $ext);
> }
415a676,677
>
> // Clean-up _segmentsToDelete container
416a679
>
418,423c681,688
< // Load segments, created by other process
< foreach ($segments as $segName => $segSize) {
< // Load new segments
< $this->_segmentInfos[] = new Zend_Search_Lucene_Index_SegmentInfo($segName,
< $segSize,
< $this->_directory);
---
> // Release index write lock
> Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory);
>
> // Remove unused segments from segments list
> foreach ($this->_segmentInfos as $segName => $segmentInfo) {
> if (!isset($segments[$segName])) {
> unset($this->_segmentInfos[$segName]);
> }
427d691
<
441,444c705
< if (count($this->_newSegments) != 0 ||
< count($this->_segmentsToDelete) != 0) {
< $this->_updateSegments();
< }
---
> $this->_updateSegments();
462,464c723,726
< * Merges all segments together into a single segment, optimizing
< * an index for search.
< * Input is an array of Zend_Search_Lucene_Index_SegmentInfo objects
---
> * Merges all segments together into new one
> *
> * Returns true on success and false if another optimization or auto-optimization process
> * is running now
466c728
< * @throws Zend_Search_Lucene_Exception
---
> * @return boolean
469a732,735
> if (Zend_Search_Lucene_LockManager::obtainOptimizationLock($this->_directory) === false) {
> return false;
> }
>
470a737,740
>
> Zend_Search_Lucene_LockManager::releaseOptimizationLock($this->_directory);
>
> return true;
480,489c750,753
< // Do not share file handler to get file updates from other sessions.
< $segmentsFile = $this->_directory->getFileObject('segments', false);
<
< // Get exclusive segments file lock
< // We have guarantee, that we will not intersect with _updateSegments() call
< // of other process, because it needs exclusive index lock and waits
< // until all other searchers won't stop
< if (!$segmentsFile->lock(LOCK_EX)) {
< throw new Zend_Search_Lucene_Exception('Can\'t obtain exclusive index lock');
< }
---
> Zend_Search_Lucene_LockManager::obtainWriteLock($this->_directory);
>
> $generation = Zend_Search_Lucene::getActualGeneration($this->_directory);
> $segmentsFile = $this->_directory->getFileObject(Zend_Search_Lucene::getSegmentFileName($generation), false);
501,502c765,766
< $segmentsFile->unlock();
<
---
> Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory);
>
cvs diff: Diffing Zend/Search/Lucene/Index/SegmentWriter
Index: Zend/Search/Lucene/Index/SegmentWriter/DocumentWriter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Index/SegmentWriter/DocumentWriter.php,v
retrieving revision 1.1
diff -r1.1 DocumentWriter.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer.php';
---
> require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
30c30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/SegmentWriter.php';
---
> require_once 'Zend/Search/Lucene/Index/SegmentWriter.php';
37c37
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
207c207,208
< return new Zend_Search_Lucene_Index_SegmentInfo($this->_name,
---
> return new Zend_Search_Lucene_Index_SegmentInfo($this->_directory,
> $this->_name,
209c210,212
< $this->_directory);
---
> -1,
> true,
> true);
Index: Zend/Search/Lucene/Index/SegmentWriter/StreamWriter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Index/SegmentWriter/StreamWriter.php,v
retrieving revision 1.1
diff -r1.1 StreamWriter.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/SegmentInfo.php';
---
> require_once 'Zend/Search/Lucene/Index/SegmentInfo.php';
30c30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/SegmentWriter.php';
---
> require_once 'Zend/Search/Lucene/Index/SegmentWriter.php';
37c37
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
89c89,90
< return new Zend_Search_Lucene_Index_SegmentInfo($this->_name,
---
> return new Zend_Search_Lucene_Index_SegmentInfo($this->_directory,
> $this->_name,
91c92,94
< $this->_directory);
---
> -1,
> true,
> true);
cvs diff: Diffing Zend/Search/Lucene/Search
Index: Zend/Search/Lucene/Search/BooleanExpressionRecognizer.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/BooleanExpressionRecognizer.php,v
retrieving revision 1.1
diff -r1.1 BooleanExpressionRecognizer.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/FSM.php';
---
> require_once 'Zend/Search/Lucene/FSM.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryToken.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryToken.php';
30c30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryParser.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryParser.php';
34c34
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
40c40
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/Query.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Query.php,v
retrieving revision 1.2
diff -r1.2 Query.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
23c23
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Document/Html.php';
---
> require_once 'Zend/Search/Lucene/Document/Html.php';
30c30
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/QueryEntry.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/QueryEntry.php,v
retrieving revision 1.1
diff -r1.1 QueryEntry.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/Term.php';
---
> require_once 'Zend/Search/Lucene/Index/Term.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
30c30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryEntry/Term.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryEntry/Term.php';
33c33
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryEntry/Phrase.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryEntry/Phrase.php';
36c36
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryEntry/Subquery.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryEntry/Subquery.php';
40c40
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryParserException.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
47c47
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/QueryHit.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/QueryHit.php,v
retrieving revision 1.2
diff -r1.2 QueryHit.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
27c27
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/QueryLexer.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/QueryLexer.php,v
retrieving revision 1.1
diff -r1.1 QueryLexer.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/FSM.php';
---
> require_once 'Zend/Search/Lucene/FSM.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryToken.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryToken.php';
30c30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
33c33
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryParserException.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
40c40
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/QueryParser.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/QueryParser.php,v
retrieving revision 1.2
diff -r1.2 QueryParser.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/Term.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Index/Term.php";
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query/Term.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/Query/Term.php";
30c30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query/MultiTerm.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/Query/MultiTerm.php";
33c33
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query/Boolean.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/Query/Boolean.php";
36c36,45
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query/Phrase.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/Query/Phrase.php";
>
> /** Zend_Search_Lucene_Search_Query_Wildcard */
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/Query/Wildcard.php";
>
> /** Zend_Search_Lucene_Search_Query_Range */
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/Query/Range.php";
>
> /** Zend_Search_Lucene_Search_Query_Fuzzy */
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/Query/Fuzzy.php";
39c48,51
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query/Empty.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/Query/Empty.php";
>
> /** Zend_Search_Lucene_Search_Query_Insignificant */
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/Query/Insignificant.php";
43c55
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryLexer.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/QueryLexer.php";
46c58
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryParserContext.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/QueryParserContext.php";
50c62
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/FSM.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/FSM.php";
53c65
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Exception.php";
56c68
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryParserException.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/QueryParserException.php";
63c75
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
141a154,173
> /**
> * Defines query parsing mode.
> *
> * If this option is turned on, then query parser suppress query parser exceptions
> * and constructs multi-term query using all words from a query.
> *
> * That helps to avoid exceptions caused by queries, which don't conform to query language,
> * but limits possibilities to check, that query entered by user has some inconsistencies.
> *
> *
> * Default is true.
> *
> * Use {@link Zend_Search_Lucene::suppressQueryParsingExceptions()},
> * {@link Zend_Search_Lucene::dontSuppressQueryParsingExceptions()} and
> * {@link Zend_Search_Lucene::checkQueryParsingExceptionsSuppressMode()} to operate
> * with this setting.
> *
> * @var boolean
> */
> private $_suppressQueryParsingExceptions = true;
258a291,302
> /**
> * Get query parser instance
> *
> * @return Zend_Search_Lucene_Search_QueryParser
> */
> private static function _getInstance()
> {
> if (self::$_instance === null) {
> self::$_instance = new self();
> }
> return self::$_instance;
> }
267,271c311
< if (self::$_instance === null) {
< self::$_instance = new Zend_Search_Lucene_Search_QueryParser();
< }
<
< self::$_instance->_defaultEncoding = $encoding;
---
> self::_getInstance()->_defaultEncoding = $encoding;
281,285c321
< if (self::$_instance === null) {
< self::$_instance = new Zend_Search_Lucene_Search_QueryParser();
< }
<
< return self::$_instance->_defaultEncoding;
---
> return self::_getInstance()->_defaultEncoding;
295,299c331
< if (self::$_instance === null) {
< self::$_instance = new Zend_Search_Lucene_Search_QueryParser();
< }
<
< self::$_instance->_defaultOperator = $operator;
---
> self::_getInstance()->_defaultOperator = $operator;
309,311c341,342
< if (self::$_instance === null) {
< self::$_instance = new Zend_Search_Lucene_Search_QueryParser();
< }
---
> return self::_getInstance()->_defaultOperator;
> }
313c344,349
< return self::$_instance->_defaultOperator;
---
> /**
> * Turn on 'suppress query parser exceptions' mode.
> */
> public static function suppressQueryParsingExceptions()
> {
> self::_getInstance()->_suppressQueryParsingExceptions = true;
314a351,366
> /**
> * Turn off 'suppress query parser exceptions' mode.
> */
> public static function dontSuppressQueryParsingExceptions()
> {
> self::_getInstance()->_suppressQueryParsingExceptions = false;
> }
> /**
> * Check 'suppress query parser exceptions' mode.
> * @return boolean
> */
> public static function queryParsingExceptionsSuppressed()
> {
> return self::_getInstance()->_suppressQueryParsingExceptions;
> }
>
315a368
>
326,350c379,408
< if (self::$_instance === null) {
< self::$_instance = new Zend_Search_Lucene_Search_QueryParser();
< }
<
< self::$_instance->_encoding = ($encoding !== null) ? $encoding : self::$_instance->_defaultEncoding;
< self::$_instance->_lastToken = null;
< self::$_instance->_context = new Zend_Search_Lucene_Search_QueryParserContext(self::$_instance->_encoding);
< self::$_instance->_contextStack = array();
< self::$_instance->_tokens = self::$_instance->_lexer->tokenize($strQuery, self::$_instance->_encoding);
<
< // Empty query
< if (count(self::$_instance->_tokens) == 0) {
< return new Zend_Search_Lucene_Search_Query_Empty();
< }
<
<
< foreach (self::$_instance->_tokens as $token) {
< try {
< self::$_instance->_currentToken = $token;
< self::$_instance->process($token->type);
<
< self::$_instance->_lastToken = $token;
< } catch (Exception $e) {
< if (strpos($e->getMessage(), 'There is no any rule for') !== false) {
< throw new Zend_Search_Lucene_Search_QueryParserException( 'Syntax error at char position ' . $token->position . '.' );
---
> self::_getInstance();
>
> // Reset FSM if previous parse operation didn't return it into a correct state
> self::$_instance->reset();
>
> try {
> self::$_instance->_encoding = ($encoding !== null) ? $encoding : self::$_instance->_defaultEncoding;
> self::$_instance->_lastToken = null;
> self::$_instance->_context = new Zend_Search_Lucene_Search_QueryParserContext(self::$_instance->_encoding);
> self::$_instance->_contextStack = array();
> self::$_instance->_tokens = self::$_instance->_lexer->tokenize($strQuery, self::$_instance->_encoding);
>
> // Empty query
> if (count(self::$_instance->_tokens) == 0) {
> return new Zend_Search_Lucene_Search_Query_Insignificant();
> }
>
>
> foreach (self::$_instance->_tokens as $token) {
> try {
> self::$_instance->_currentToken = $token;
> self::$_instance->process($token->type);
>
> self::$_instance->_lastToken = $token;
> } catch (Exception $e) {
> if (strpos($e->getMessage(), 'There is no any rule for') !== false) {
> throw new Zend_Search_Lucene_Search_QueryParserException( 'Syntax error at char position ' . $token->position . '.' );
> }
>
> throw $e;
352c410,431
<
---
> }
>
> if (count(self::$_instance->_contextStack) != 0) {
> throw new Zend_Search_Lucene_Search_QueryParserException('Syntax Error: mismatched parentheses, every opening must have closing.' );
> }
>
> return self::$_instance->_context->getQuery();
> } catch (Zend_Search_Lucene_Search_QueryParserException $e) {
> if (self::$_instance->_suppressQueryParsingExceptions) {
> $queryTokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($strQuery, self::$_instance->_encoding);
>
> $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
> $termsSign = (self::$_instance->_defaultOperator == self::B_AND) ? true /* required term */ :
> null /* optional term */;
>
> foreach ($queryTokens as $token) {
> $query->addTerm(new Zend_Search_Lucene_Index_Term($token->getTermText()), $termsSign);
> }
>
>
> return $query;
> } else {
356,361d434
<
< if (count(self::$_instance->_contextStack) != 0) {
< throw new Zend_Search_Lucene_Search_QueryParserException('Syntax Error: mismatched parentheses, every opening must have closing.' );
< }
<
< return self::$_instance->_context->getQuery();
436c509
< throw new Zend_Search_Lucene_Exception('Lexeme modifier parameter must follow lexeme modifier. Char position .' );
---
> throw new Zend_Search_Lucene_Exception('Lexeme modifier parameter must follow lexeme modifier. Char position 0.' );
488c561,577
< throw new Zend_Search_Lucene_Search_QueryParserException('Range queries are not supported yet.');
---
> $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_rqFirstTerm, $this->_encoding);
> if (count($tokens) > 1) {
> throw new Zend_Search_Lucene_Search_QueryParserException('Range query boundary terms must be non-multiple word terms');
> } else if (count($tokens) == 1) {
> $from = new Zend_Search_Lucene_Index_Term(reset($tokens)->getTermText(), $this->_context->getField());
> } else {
> $from = null;
> }
>
> $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_currentToken->text, $this->_encoding);
> if (count($tokens) > 1) {
> throw new Zend_Search_Lucene_Search_QueryParserException('Range query boundary terms must be non-multiple word terms');
> } else if (count($tokens) == 1) {
> $to = new Zend_Search_Lucene_Index_Term(reset($tokens)->getTermText(), $this->_context->getField());
> } else {
> $to = null;
> }
490,491c579,581
< // $firstTerm = new Zend_Search_Lucene_Index_Term($this->_rqFirstTerm, $this->_context->getField());
< // $lastTerm = new Zend_Search_Lucene_Index_Term($this->_currentToken->text, $this->_context->getField());
---
> if ($from === null && $to === null) {
> throw new Zend_Search_Lucene_Search_QueryParserException('At least one range query boundary term must be non-empty term');
> }
493,494c583,585
< // $query = new Zend_Search_Lucene_Search_Query_Range($firstTerm, $lastTerm, false);
< // $this->_context->addentry($query);
---
> $rangeQuery = new Zend_Search_Lucene_Search_Query_Range($from, $to, false);
> $entry = new Zend_Search_Lucene_Search_QueryEntry_Subquery($rangeQuery);
> $this->_context->addEntry($entry);
512c603,619
< throw new Zend_Search_Lucene_Search_QueryParserException('Range queries are not supported yet.');
---
> $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_rqFirstTerm, $this->_encoding);
> if (count($tokens) > 1) {
> throw new Zend_Search_Lucene_Search_QueryParserException('Range query boundary terms must be non-multiple word terms');
> } else if (count($tokens) == 1) {
> $from = new Zend_Search_Lucene_Index_Term(reset($tokens)->getTermText(), $this->_context->getField());
> } else {
> $from = null;
> }
>
> $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_currentToken->text, $this->_encoding);
> if (count($tokens) > 1) {
> throw new Zend_Search_Lucene_Search_QueryParserException('Range query boundary terms must be non-multiple word terms');
> } else if (count($tokens) == 1) {
> $to = new Zend_Search_Lucene_Index_Term(reset($tokens)->getTermText(), $this->_context->getField());
> } else {
> $to = null;
> }
514,515c621,623
< // $firstTerm = new Zend_Search_Lucene_Index_Term($this->_rqFirstTerm, $this->_context->getField());
< // $lastTerm = new Zend_Search_Lucene_Index_Term($this->_currentToken->text, $this->_context->getField());
---
> if ($from === null && $to === null) {
> throw new Zend_Search_Lucene_Search_QueryParserException('At least one range query boundary term must be non-empty term');
> }
517,518c625,627
< // $query = new Zend_Search_Lucene_Search_Query_Range($firstTerm, $lastTerm, true);
< // $this->_context->addentry($query);
---
> $rangeQuery = new Zend_Search_Lucene_Search_Query_Range($from, $to, true);
> $entry = new Zend_Search_Lucene_Search_QueryEntry_Subquery($rangeQuery);
> $this->_context->addEntry($entry);
Index: Zend/Search/Lucene/Search/QueryParserContext.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/QueryParserContext.php,v
retrieving revision 1.1
diff -r1.1 QueryParserContext.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
23c23
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/FSM.php';
---
> require_once 'Zend/Search/Lucene/FSM.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/Term.php';
---
> require_once 'Zend/Search/Lucene/Index/Term.php';
30c30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryToken.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryToken.php';
33c33
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query/Term.php';
---
> require_once 'Zend/Search/Lucene/Search/Query/Term.php';
36c36
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query/MultiTerm.php';
---
> require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
39c39
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query/Boolean.php';
---
> require_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
42c42
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query/Phrase.php';
---
> require_once 'Zend/Search/Lucene/Search/Query/Phrase.php';
45c45
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
48c48
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryParserException.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
51c51
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/BooleanExpressionRecognizer.php';
---
> require_once 'Zend/Search/Lucene/Search/BooleanExpressionRecognizer.php';
54c54
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryEntry.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryEntry.php';
61c61
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
363c363
< unset($conjuctions[$conjuctionId]);
---
> unset($conjuctions[$conjuctionId]);
385c385
< return new Zend_Search_Lucene_Search_Query_Empty();
---
> return new Zend_Search_Lucene_Search_Query_Insignificant();
Index: Zend/Search/Lucene/Search/QueryParserException.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/QueryParserException.php,v
retrieving revision 1.1
diff -r1.1 QueryParserException.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
26c26
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
33c33
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/QueryToken.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/QueryToken.php,v
retrieving revision 1.2
diff -r1.2 QueryToken.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/Similarity.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Similarity.php,v
retrieving revision 1.2
diff -r1.2 Similarity.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Similarity/Default.php';
---
> require_once 'Zend/Search/Lucene/Search/Similarity/Default.php';
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/Weight.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Weight.php,v
retrieving revision 1.2
diff -r1.2 Weight.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
35c35
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
cvs diff: Diffing Zend/Search/Lucene/Search/Query
Index: Zend/Search/Lucene/Search/Query/Boolean.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Query/Boolean.php,v
retrieving revision 1.1
diff -r1.1 Boolean.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query.php';
---
> require_once 'Zend/Search/Lucene/Search/Query.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Weight/Boolean.php';
---
> require_once 'Zend/Search/Lucene/Search/Weight/Boolean.php';
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
42c42
< * Array of Zend_Search_Lucene_Query
---
> * Array of Zend_Search_Lucene_Search_Query
108c108
< * Add a $subquery (Zend_Search_Lucene_Query) to this query.
---
> * Add a $subquery (Zend_Search_Lucene_Search_Query) to this query.
121a122
> $this->_signs = array();
167a169,193
> // Remove insignificant subqueries
> foreach ($subqueries as $id => $subquery) {
> if ($subquery instanceof Zend_Search_Lucene_Search_Query_Insignificant) {
> // Insignificant subquery has to be removed anyway
> unset($subqueries[$id]);
> unset($signs[$id]);
> }
> }
> if (count($subqueries) == 0) {
> // Boolean query doesn't has non-insignificant subqueries
> return new Zend_Search_Lucene_Search_Query_Insignificant();
> }
> // Check if all non-insignificant subqueries are prohibited
> $allProhibited = true;
> foreach ($signs as $sign) {
> if ($sign !== false) {
> $allProhibited = false;
> break;
> }
> }
> if ($allProhibited) {
> return new Zend_Search_Lucene_Search_Query_Insignificant();
> }
>
>
182a209,212
> // Check, if reduced subqueries list is empty
> if (count($subqueries) == 0) {
> return new Zend_Search_Lucene_Search_Query_Empty();
> }
213,218d242
< // Check, if reduced subqueries list is empty
< if (count($subqueries) == 0) {
< return new Zend_Search_Lucene_Search_Query_Empty();
< }
<
<
459c483,496
< foreach ($this->_subqueries as $subquery) {
---
> $resVectors = array();
> $resVectorsSizes = array();
> $resVectorsIds = array(); // is used to prevent arrays comparison
> foreach ($this->_subqueries as $subqueryId => $subquery) {
> $resVectors[] = $subquery->matchedDocs();
> $resVectorsSizes[] = count(end($resVectors));
> $resVectorsIds[] = $subqueryId;
> }
> // sort resvectors in order of subquery cardinality increasing
> array_multisort($resVectorsSizes, SORT_ASC, SORT_NUMERIC,
> $resVectorsIds, SORT_ASC, SORT_NUMERIC,
> $resVectors);
>
> foreach ($resVectors as $nextResVector) {
461c498
< $this->_resVector = $subquery->matchedDocs();
---
> $this->_resVector = $nextResVector;
463c500,511
< $this->_resVector = array_intersect_key($this->_resVector, $subquery->matchedDocs());
---
> //$this->_resVector = array_intersect_key($this->_resVector, $nextResVector);
>
> /**
> * This code is used as workaround for array_intersect_key() slowness problem.
> */
> $updatedVector = array();
> foreach ($this->_resVector as $id => $value) {
> if (isset($nextResVector[$id])) {
> $updatedVector[$id] = $value;
> }
> }
> $this->_resVector = $updatedVector;
472c520,521
< ksort($this->_resVector, SORT_NUMERIC);
---
> // ksort($this->_resVector, SORT_NUMERIC);
> // Used algorithm doesn't change elements order
482,483c531,533
< $required = null;
< $optional = array();
---
> $requiredVectors = array();
> $requiredVectorsSizes = array();
> $requiredVectorsIds = array(); // is used to prevent arrays comparison
485,486c535
< foreach ($this->_subqueries as $subqueryId => $subquery) {
< $docs = $subquery->matchedDocs();
---
> $optional = array();
487a537
> foreach ($this->_subqueries as $subqueryId => $subquery) {
490,495c540,542
< if ($required !== null) {
< // array intersection
< $required = array_intersect_key($required, $docs);
< } else {
< $required = $docs;
< }
---
> $requiredVectors[] = $subquery->matchedDocs();
> $requiredVectorsSizes[] = count(end($requiredVectors));
> $requiredVectorsIds[] = $subqueryId;
498a546,547
> // Calculating prohibited vector may take significant time, but do not affect the result
> // Skipped.
502c551
< $optional += $docs;
---
> $optional += $subquery->matchedDocs();
505a555,585
> // sort resvectors in order of subquery cardinality increasing
> array_multisort($requiredVectorsSizes, SORT_ASC, SORT_NUMERIC,
> $requiredVectorsIds, SORT_ASC, SORT_NUMERIC,
> $requiredVectors);
>
> $required = null;
> foreach ($requiredVectors as $nextResVector) {
> if($required === null) {
> $required = $nextResVector;
> } else {
> //$required = array_intersect_key($required, $nextResVector);
>
> /**
> * This code is used as workaround for array_intersect_key() slowness problem.
> */
> $updatedVector = array();
> foreach ($required as $id => $value) {
> if (isset($nextResVector[$id])) {
> $updatedVector[$id] = $value;
> }
> }
> $required = $updatedVector;
> }
>
> if (count($required) == 0) {
> // Empty result set, we don't need to check other terms
> break;
> }
> }
>
>
708c788
< $query .= '^' . $subquery->getBoost();
---
> $query .= '^' . round($subquery->getBoost(), 4);
Index: Zend/Search/Lucene/Search/Query/Empty.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Query/Empty.php,v
retrieving revision 1.1
diff -r1.1 Empty.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query.php';
---
> require_once 'Zend/Search/Lucene/Search/Query.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Weight/Empty.php';
---
> require_once 'Zend/Search/Lucene/Search/Weight/Empty.php';
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/Query/MultiTerm.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Query/MultiTerm.php,v
retrieving revision 1.2
diff -r1.2 MultiTerm.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query.php';
---
> require_once 'Zend/Search/Lucene/Search/Query.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Weight/MultiTerm.php';
---
> require_once 'Zend/Search/Lucene/Search/Weight/MultiTerm.php';
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
106d105
< * @return void
141a141
> $this->_signs = array();
319c319,334
< foreach( $this->_terms as $termId=>$term ) {
---
> $resVectors = array();
> $resVectorsSizes = array();
> $resVectorsIds = array(); // is used to prevent arrays comparison
> foreach ($this->_terms as $termId => $term) {
> $resVectors[] = array_flip($reader->termDocs($term));
> $resVectorsSizes[] = count(end($resVectors));
> $resVectorsIds[] = $termId;
>
> $this->_termsFreqs[$termId] = $reader->termFreqs($term);
> }
> // sort resvectors in order of subquery cardinality increasing
> array_multisort($resVectorsSizes, SORT_ASC, SORT_NUMERIC,
> $resVectorsIds, SORT_ASC, SORT_NUMERIC,
> $resVectors);
>
> foreach ($resVectors as $nextResVector) {
321c336
< $this->_resVector = array_flip($reader->termDocs($term));
---
> $this->_resVector = $nextResVector;
323c338,349
< $this->_resVector = array_intersect_key($this->_resVector, array_flip($reader->termDocs($term)));
---
> //$this->_resVector = array_intersect_key($this->_resVector, $nextResVector);
>
> /**
> * This code is used as workaround for array_intersect_key() slowness problem.
> */
> $updatedVector = array();
> foreach ($this->_resVector as $id => $value) {
> if (isset($nextResVector[$id])) {
> $updatedVector[$id] = $value;
> }
> }
> $this->_resVector = $updatedVector;
330,331d355
<
< $this->_termsFreqs[$termId] = $reader->termFreqs($term);
334c358,359
< ksort($this->_resVector, SORT_NUMERIC);
---
> // ksort($this->_resVector, SORT_NUMERIC);
> // Docs are returned ordered. Used algorithm doesn't change elements order.
346c371,374
< $required = null;
---
> $requiredVectors = array();
> $requiredVectorsSizes = array();
> $requiredVectorsIds = array(); // is used to prevent arrays comparison
>
349c377
<
---
>
355,360c383,385
< if ($required !== null) {
< // array intersection
< $required = array_intersect_key($required, $termDocs);
< } else {
< $required = $termDocs;
< }
---
> $requiredVectors[] = $termDocs;
> $requiredVectorsSizes[] = count($termDocs);
> $requiredVectorsIds[] = $termId;
373a399,428
> // sort resvectors in order of subquery cardinality increasing
> array_multisort($requiredVectorsSizes, SORT_ASC, SORT_NUMERIC,
> $requiredVectorsIds, SORT_ASC, SORT_NUMERIC,
> $requiredVectors);
>
> $required = null;
> foreach ($requiredVectors as $nextResVector) {
> if($required === null) {
> $required = $nextResVector;
> } else {
> //$required = array_intersect_key($required, $nextResVector);
>
> /**
> * This code is used as workaround for array_intersect_key() slowness problem.
> */
> $updatedVector = array();
> foreach ($required as $id => $value) {
> if (isset($nextResVector[$id])) {
> $updatedVector[$id] = $value;
> }
> }
> $required = $updatedVector;
> }
>
> if (count($required) == 0) {
> // Empty result set, we don't need to check other terms
> break;
> }
> }
>
375,377c430
< $this->_resVector = (count($prohibited) > 0) ?
< array_diff_key($required, $prohibited) :
< $required;
---
> $this->_resVector = $required;
379,381c432
< $this->_resVector = (count($prohibited) > 0) ?
< array_diff_key($optional, $prohibited) :
< $optional;
---
> $this->_resVector = $optional;
383a435,457
> if (count($prohibited) != 0) {
> // $this->_resVector = array_diff_key($this->_resVector, $prohibited);
>
> /**
> * This code is used as workaround for array_diff_key() slowness problem.
> */
> if (count($this->_resVector) < count($prohibited)) {
> $updatedVector = $this->_resVector;
> foreach ($this->_resVector as $id => $value) {
> if (isset($prohibited[$id])) {
> unset($updatedVector[$id]);
> }
> }
> $this->_resVector = $updatedVector;
> } else {
> $updatedVector = $this->_resVector;
> foreach ($prohibited as $id => $value) {
> unset($updatedVector[$id]);
> }
> $this->_resVector = $updatedVector;
> }
> }
>
Index: Zend/Search/Lucene/Search/Query/Phrase.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Query/Phrase.php,v
retrieving revision 1.2
diff -r1.2 Phrase.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
26c26
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query.php';
---
> require_once 'Zend/Search/Lucene/Search/Query.php';
31c31
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Weight/Phrase.php';
---
> require_once 'Zend/Search/Lucene/Search/Weight/Phrase.php';
40c40
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
419c419,434
< foreach( $this->_terms as $termId=>$term ) {
---
> $resVectors = array();
> $resVectorsSizes = array();
> $resVectorsIds = array(); // is used to prevent arrays comparison
> foreach ($this->_terms as $termId => $term) {
> $resVectors[] = array_flip($reader->termDocs($term));
> $resVectorsSizes[] = count(end($resVectors));
> $resVectorsIds[] = $termId;
>
> $this->_termsPositions[$termId] = $reader->termPositions($term);
> }
> // sort resvectors in order of subquery cardinality increasing
> array_multisort($resVectorsSizes, SORT_ASC, SORT_NUMERIC,
> $resVectorsIds, SORT_ASC, SORT_NUMERIC,
> $resVectors);
>
> foreach ($resVectors as $nextResVector) {
421c436
< $this->_resVector = array_flip($reader->termDocs($term));
---
> $this->_resVector = $nextResVector;
423c438,449
< $this->_resVector = array_intersect_key($this->_resVector, array_flip($reader->termDocs($term)));
---
> //$this->_resVector = array_intersect_key($this->_resVector, $nextResVector);
>
> /**
> * This code is used as workaround for array_intersect_key() slowness problem.
> */
> $updatedVector = array();
> foreach ($this->_resVector as $id => $value) {
> if (isset($nextResVector[$id])) {
> $updatedVector[$id] = $value;
> }
> }
> $this->_resVector = $updatedVector;
430,431d455
<
< $this->_termsPositions[$termId] = $reader->termPositions($term);
434,435c458,460
< ksort($this->_resVector, SORT_NUMERIC);
<
---
> // ksort($this->_resVector, SORT_NUMERIC);
> // Docs are returned ordered. Used algorithm doesn't change elements order.
>
Index: Zend/Search/Lucene/Search/Query/Term.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Query/Term.php,v
retrieving revision 1.2
diff -r1.2 Term.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Query.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/Query.php";
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Weight/Term.php';
---
> require_once "{$CFG->dirroot}/search/Zend/Search/Lucene/Search/Weight/Term.php";
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
68c68
< public function __construct($term)
---
> public function __construct(Zend_Search_Lucene_Index_Term $term)
cvs diff: Diffing Zend/Search/Lucene/Search/QueryEntry
Index: Zend/Search/Lucene/Search/QueryEntry/Phrase.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/QueryEntry/Phrase.php,v
retrieving revision 1.1
diff -r1.1 Phrase.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/Term.php';
---
> require_once 'Zend/Search/Lucene/Index/Term.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
30c30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryEntry.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryEntry.php';
33c33
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryParserException.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
36c36
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer.php';
---
> require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
44c44
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
121c121
< return new Zend_Search_Lucene_Search_Query_Empty();
---
> return new Zend_Search_Lucene_Search_Query_Insignificant();
132a133
> $position = -1;
134a136
> $position += $token->getPositionIncrement();
136c138
< $query->addTerm($term);
---
> $query->addTerm($term, $position);
Index: Zend/Search/Lucene/Search/QueryEntry/Subquery.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/QueryEntry/Subquery.php,v
retrieving revision 1.1
diff -r1.1 Subquery.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/Term.php';
---
> require_once 'Zend/Search/Lucene/Index/Term.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
30c30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryEntry.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryEntry.php';
33c33
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryParserException.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
40c40
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/QueryEntry/Term.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/QueryEntry/Term.php,v
retrieving revision 1.1
diff -r1.1 Term.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Index/Term.php';
---
> require_once 'Zend/Search/Lucene/Index/Term.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
30c30
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryEntry.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryEntry.php';
33c33
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/QueryParserException.php';
---
> require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
36c36
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer.php';
---
> require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
44c44
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
103c103
< $this->_similarity = 0.5;
---
> $this->_similarity = Zend_Search_Lucene_Search_Query_Fuzzy::DEFAULT_MIN_SIMILARITY;
116,119d115
< if ($this->_fuzzyQuery) {
< throw new Zend_Search_Lucene_Search_QueryParserException('Fuzzy search is not supported yet.');
< }
<
121c117,158
< throw new Zend_Search_Lucene_Search_QueryParserException('Wildcard queries are not supported yet.');
---
> if ($this->_fuzzyQuery) {
> throw new Zend_Search_Lucene_Search_QueryParserException('Fuzzy search is not supported for terms with wildcards.');
> }
>
> $pattern = '';
>
> $subPatterns = explode('*', $this->_term);
>
> $astericFirstPass = true;
> foreach ($subPatterns as $subPattern) {
> if (!$astericFirstPass) {
> $pattern .= '*';
> } else {
> $astericFirstPass = false;
> }
>
> $subPatternsL2 = explode('?', $subPattern);
>
> $qMarkFirstPass = true;
> foreach ($subPatternsL2 as $subPatternL2) {
> if (!$qMarkFirstPass) {
> $pattern .= '?';
> } else {
> $qMarkFirstPass = false;
> }
>
> $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($subPatternL2, $encoding);
> if (count($tokens) > 1) {
> throw new Zend_Search_Lucene_Search_QueryParserException('Wildcard search is supported only for non-multiple word terms');
> }
>
> foreach ($tokens as $token) {
> $pattern .= $token->getTermText();
> }
> }
> }
>
> $term = new Zend_Search_Lucene_Index_Term($pattern, $this->_field);
> $query = new Zend_Search_Lucene_Search_Query_Wildcard($term);
> $query->setBoost($this->_boost);
>
> return $query;
127c164
< return new Zend_Search_Lucene_Search_Query_Empty();
---
> return new Zend_Search_Lucene_Search_Query_Insignificant();
130,131c167,168
< if (count($tokens) == 1) {
< $term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field);
---
> if (count($tokens) == 1 && !$this->_fuzzyQuery) {
> $term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field);
137a175,186
> if (count($tokens) == 1 && $this->_fuzzyQuery) {
> $term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field);
> $query = new Zend_Search_Lucene_Search_Query_Fuzzy($term, $this->_similarity);
> $query->setBoost($this->_boost);
>
> return $query;
> }
>
> if ($this->_fuzzyQuery) {
> throw new Zend_Search_Lucene_Search_QueryParserException('Fuzzy search is supported only for non-multiple word terms');
> }
>
cvs diff: Diffing Zend/Search/Lucene/Search/Similarity
Index: Zend/Search/Lucene/Search/Similarity/Default.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Similarity/Default.php,v
retrieving revision 1.2
diff -r1.2 Default.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Similarity.php';
---
> require_once 'Zend/Search/Lucene/Search/Similarity.php';
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
41c41
< * @param integer numTerms
---
> * @param integer $numTerms
cvs diff: Diffing Zend/Search/Lucene/Search/Weight
Index: Zend/Search/Lucene/Search/Weight/Boolean.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Weight/Boolean.php,v
retrieving revision 1.1
diff -r1.1 Boolean.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Weight.php';
---
> require_once 'Zend/Search/Lucene/Search/Weight.php';
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/Weight/Empty.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Weight/Empty.php,v
retrieving revision 1.1
diff -r1.1 Empty.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Weight.php';
---
> require_once 'Zend/Search/Lucene/Search/Weight.php';
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/Weight/MultiTerm.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Weight/MultiTerm.php,v
retrieving revision 1.2
diff -r1.2 MultiTerm.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Weight.php';
---
> require_once 'Zend/Search/Lucene/Search/Weight.php';
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/Weight/Phrase.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Weight/Phrase.php,v
retrieving revision 1.2
diff -r1.2 Phrase.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
26c26
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Weight.php';
---
> require_once 'Zend/Search/Lucene/Search/Weight.php';
33c33
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
Index: Zend/Search/Lucene/Search/Weight/Term.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Search/Weight/Term.php,v
retrieving revision 1.2
diff -r1.2 Term.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Weight.php';
---
> require_once 'Zend/Search/Lucene/Search/Weight.php';
31c31
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
cvs diff: Diffing Zend/Search/Lucene/Storage
Index: Zend/Search/Lucene/Storage/Directory.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Storage/Directory.php,v
retrieving revision 1.2
diff -r1.2 Directory.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
27c27
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
64c64,73
<
---
> /**
> * Purge file if it's cached by directory object
> *
> * Method is used to prevent 'too many open files' error
> *
> * @param string $filename
> * @return void
> */
> abstract public function purgeFile($filename);
>
Index: Zend/Search/Lucene/Storage/File.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Storage/File.php,v
retrieving revision 1.3
diff -r1.3 File.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
25c25
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
32c32
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
cvs diff: Diffing Zend/Search/Lucene/Storage/Directory
Index: Zend/Search/Lucene/Storage/Directory/Filesystem.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Storage/Directory/Filesystem.php,v
retrieving revision 1.2
diff -r1.2 Filesystem.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Storage/Directory.php';
---
> require_once 'Zend/Search/Lucene/Storage/Directory.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Storage/File/Filesystem.php';
---
> require_once 'Zend/Search/Lucene/Storage/File/Filesystem.php';
36c36
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
46c46
< private $_dirPath = null;
---
> protected $_dirPath = null;
55c55,83
< private $_fileHandlers;
---
> protected $_fileHandlers;
>
> /**
> * Default file permissions
> *
> * @var integer
> */
> protected static $_defaultFilePermissions = 0666;
>
>
> /**
> * Get default file permissions
> *
> * @return integer
> */
> public static function getDefaultFilePermissions()
> {
> return self::$_defaultFilePermissions;
> }
>
> /**
> * Set default file permissions
> *
> * @param integer $mode
> */
> public static function setDefaultFilePermissions($mode)
> {
> self::$_defaultFilePermissions = $mode;
> }
146a175
> * @throws Zend_Search_Lucene_Exception
154a184,192
>
> global $php_errormsg;
> $trackErrors = ini_get('track_errors'); ini_set('track_errors', '1');
> if (!@chmod($this->_dirPath . '/' . $filename, self::$_defaultFilePermissions)) {
> ini_set('track_errors', $trackErrors);
> throw new Zend_Search_Lucene_Exception($php_errormsg);
> }
> ini_set('track_errors', $trackErrors);
>
163a202
> * @throws Zend_Search_Lucene_Exception
167,172d205
< /**
< * @todo add support of "deletable" file
< * "deletable" is used on Windows systems if file can't be deleted
< * (while it is still open).
< */
<
177c210,219
< unlink($this->_dirPath . '/' . $filename);
---
>
> global $php_errormsg;
> $trackErrors = ini_get('track_errors'); ini_set('track_errors', '1');
> if (!@unlink($this->_dirPath . '/' . $filename)) {
> ini_set('track_errors', $trackErrors);
> throw $e;
>
> throw new Zend_Search_Lucene_Exception('Can\'t delete file: ' . $php_errormsg);
> }
> ini_set('track_errors', $trackErrors);
179a222,237
> /**
> * Purge file if it's cached by directory object
> *
> * Method is used to prevent 'too many open files' error
> *
> * @param string $filename
> * @return void
> */
> public function purgeFile($filename)
> {
> if (isset($this->_fileHandlers[$filename])) {
> $this->_fileHandlers[$filename]->close();
> }
> unset($this->_fileHandlers[$filename]);
> }
>
cvs diff: Diffing Zend/Search/Lucene/Storage/File
Index: Zend/Search/Lucene/Storage/File/Filesystem.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Storage/File/Filesystem.php,v
retrieving revision 1.2
diff -r1.2 Filesystem.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Storage/File.php';
---
> require_once 'Zend/Search/Lucene/Storage/File.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
44c44,45
< private $_fileHandle;
---
> protected $_fileHandle;
>
55a57,61
> if (strpos($mode, 'w') === false && !is_readable($filename)) {
> // opening for reading non-readable file
> throw new Zend_Search_Lucene_Exception('File \'' . $filename . '\' is not readable.');
> }
>
188c194
< * @param boolean $nonBlockinLock
---
> * @param boolean $nonBlockingLock
191c197
< public function lock($lockType, $nonBlockinLock = false)
---
> public function lock($lockType, $nonBlockingLock = false)
193c199
< if ($nonBlockinLock) {
---
> if ($nonBlockingLock) {
Index: Zend/Search/Lucene/Storage/File/Memory.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/Zend/Search/Lucene/Storage/File/Memory.php,v
retrieving revision 1.1
diff -r1.1 Memory.php
18c18
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
24c24
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Storage/File.php';
---
> require_once 'Zend/Search/Lucene/Storage/File.php';
27c27
< require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php';
---
> require_once 'Zend/Search/Lucene/Exception.php';
34c34
< * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
---
> * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
cvs diff: Diffing documents
Index: documents/chat_document.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/chat_document.php,v
retrieving revision 1.2.2.2
diff -r1.2.2.2 chat_document.php
35c35
< public function __construct(&$chatsession, $chat_module_id, $course_id, $group_id, $context_id) {
---
> public function __construct(&$chatsession, $chat_id, $chat_module_id, $course_id, $group_id, $context_id) {
37c37
< $doc->docid = $chat_module_id.'-'.$chatsession['sessionstart'].'-'.$chatsession['sessionend'];
---
> $doc->docid = $chat_id.'-'.$chatsession['sessionstart'].'-'.$chatsession['sessionend'];
53c53
< $data->chat = $chat_module_id;
---
> $data->chat = $chat_id;
56c56
< parent::__construct($doc, $data, $course_id, $group_id, 0, PATH_FOR_SEARCH_TYPE_CHAT);
---
> parent::__construct($doc, $data, $course_id, $group_id, 0, 'mod/'.SEARCH_TYPE_CHAT);
179c179
< $documents[] = new ChatTrackSearchDocument(get_object_vars($aTrack), $cm->id, $chat->course, $aTrack->groupid, $context->id);
---
> $documents[] = new ChatTrackSearchDocument(get_object_vars($aTrack), $chat->id, $cm->id, $chat->course, $aTrack->groupid, $context->id);
210c210
< $document = new ChatTrackSearchDocument(get_object_vars($aTrack), $cm->id, $chat->course, $aTrack->groupid, $context->id);
---
> $document = new ChatTrackSearchDocument(get_object_vars($aTrack), $chat_id, $cm->id, $chat->course, $aTrack->groupid, $context->id);
258,259c258
< list($chat_id, $sessionstart, $sessionend) = split('-', $id);
<
---
> list($chat_id, $sessionstart, $sessionend) = split('-', $this_id);
274d272
< $current_group = get_current_group($course->id);
Index: documents/data_document.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/data_document.php,v
retrieving revision 1.3.2.2
diff -r1.3.2.2 data_document.php
57c57
< parent::__construct($doc, $data, $course_id, $record['groupid'], $record['userid'], PATH_FOR_SEARCH_TYPE_DATA);
---
> parent::__construct($doc, $data, $course_id, $record['groupid'], $record['userid'], 'mod/'.SEARCH_TYPE_DATA);
351d350
< $current_group = get_current_group($course->id);
371c370
< if (!$approval && !isteacher($data->course) && !has_capability('mod/data:manageentries', $context)){
---
> if (!$approval && !has_capability('mod/data:manageentries', $context)){
380c379
< if ($data->requiredentriestoview > $recordsAmount && !isteacher($data->course) && !has_capability('mod/data:manageentries', $context)) {
---
> if ($data->requiredentriestoview > $recordsAmount && !has_capability('mod/data:manageentries', $context)) {
390c389
< if ($now < $data->timeviewfrom && !isteacher($data->course) && !has_capability('mod/data:manageentries', $context)) {
---
> if ($now < $data->timeviewfrom && !has_capability('mod/data:manageentries', $context)) {
395c394
< if ($now > $data->timeviewto && !isteacher($data->course) && !has_capability('mod/data:manageentries', $context)) {
---
> if ($now > $data->timeviewto && !has_capability('mod/data:manageentries', $context)) {
Index: documents/forum_document.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/forum_document.php,v
retrieving revision 1.10.2.3
diff -r1.10.2.3 forum_document.php
54c54
< parent::__construct($doc, $data, $course_id, $post['groupid'], $post['userid'], PATH_FOR_SEARCH_TYPE_FORUM);
---
> parent::__construct($doc, $data, $course_id, $post['groupid'], $post['userid'], 'mod/'.SEARCH_TYPE_FORUM);
89a90
> mtrace("Found ".count($posts)." discussions to analyse in forum ".$forum->name);
99c100,101
< if (strlen($aPost->message) > 0) {
---
> if (!empty($aPost->message)) {
> echo "*";
103a106
> echo ".";
111a115
> mtrace("Finished discussion");
169c173,174
< if (!((isadmin() and !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum_id)))) {
---
> if (!((has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))
> and !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum_id)))) {
305c310,311
< return mb_convert_encoding($title, 'UTF-8', 'auto');
---
> // return mb_convert_encoding($title, 'UTF-8', 'auto');
> return mb_convert_encoding($title, 'auto', 'UTF-8');
Index: documents/glossary_document.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/glossary_document.php,v
retrieving revision 1.7.2.2
diff -r1.7.2.2 glossary_document.php
55c55
< parent::__construct($doc, $data, $course_id, -1, $entry['userid'], PATH_FOR_SEARCH_TYPE_GLOSSARY);
---
> parent::__construct($doc, $data, $course_id, -1, $entry['userid'], 'mod/'.SEARCH_TYPE_GLOSSARY);
124a125
> global $DB;
147,148c148
< $entryIdList = implode(',', $entryIds);
< $comments = get_records_list('glossary_comments', 'entryid', $entryIdList);
---
> $comments = $DB->get_records_list('glossary_comments', 'entryid', $entryIds);
230c230
< $entry = get_record('glossary_entries', 'id', $id);
---
> $entry = get_record('glossary_entries', 'id', $this_id);
254c254
< return mb_convert_encoding($title, 'UTF-8', 'auto');
---
> return mb_convert_encoding($title, 'auto', 'UTF-8');
Index: documents/lesson_document.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/lesson_document.php,v
retrieving revision 1.4.4.4
diff -r1.4.4.4 lesson_document.php
52c52
< parent::__construct($doc, $data, $course_id, 0, 0, PATH_FOR_SEARCH_TYPE_LESSON);
---
> parent::__construct($doc, $data, $course_id, 0, 0, 'mod/'.SEARCH_TYPE_LESSON);
213c213
< return mb_convert_encoding($title, 'UTF-8', 'auto');
---
> return mb_convert_encoding($title, 'auto', 'UTF-8');
Index: documents/physical_doc.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/physical_doc.php,v
retrieving revision 1.1.2.3
diff -r1.1.2.3 physical_doc.php
19c19
< * @uses CFG, USER
---
> * @uses $CFG
21,22c21,22
< function get_text_for_indexing_doc(&$resource){
< global $CFG, $USER;
---
> function get_text_for_indexing_doc(&$resource, $directfile = ''){
> global $CFG;
25c25
< if (!isadmin($USER->id)) return;
---
> if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
33,35c33,38
< }
< else{
< $file = escapeshellarg($CFG->dataroot.'/'.$resource->course.'/'.$resource->reference);
---
> } else {
> if ($directfile == ''){
> $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
> } else {
> $file = escapeshellarg("{$CFG->dataroot}/{$directfile}");
> }
37c40
< $text_converter_cmd = "{$moodleroot}{$command} $file";
---
> $text_converter_cmd = "{$moodleroot}{$command} -m UTF-8.txt $file";
44,46c47,48
< return mb_convert_encoding($result, 'UTF8', 'auto');
< }
< else{
---
> return mb_convert_encoding($result, 'UTF-8', 'auto');
> } else {
51,52c53
< }
< else {
---
> } else {
Index: documents/physical_htm.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/physical_htm.php,v
retrieving revision 1.2.2.1
diff -r1.2.2.1 physical_htm.php
18c18
< * @uses CFG, USER
---
> * @uses $CFG
20,21c20,21
< function get_text_for_indexing_htm(&$resource){
< global $CFG, $USER;
---
> function get_text_for_indexing_htm(&$resource, $directfile = ''){
> global $CFG;
24c24
< if (!isadmin($USER->id)) return;
---
> if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
27c27,31
< $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
---
> if ($directfile == ''){
> $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
> } else {
> $text = implode('', file("{$CFG->dataroot}/{$directfile}"));
> }
43c47
< $text = mb_convert_encoding($text, 'UTF-8', 'AUTO');
---
> $text = mb_convert_encoding($text, 'UTF-8', 'auto');
Index: documents/physical_html.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/physical_html.php,v
retrieving revision 1.1.2.1
diff -r1.1.2.1 physical_html.php
19c19
< function get_text_for_indexing_html(&$resource){
---
> function get_text_for_indexing_html(&$resource, $directfile = ''){
23c23
< return get_text_for_indexing_htm($resource);
---
> return get_text_for_indexing_htm($resource, $directfile);
Index: documents/physical_pdf.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/physical_pdf.php,v
retrieving revision 1.1.2.5
diff -r1.1.2.5 physical_pdf.php
18c18
< * @uses CFG, USER
---
> * @uses $CFG
20,21c20,21
< function get_text_for_indexing_pdf(&$resource){
< global $CFG, $USER;
---
> function get_text_for_indexing_pdf(&$resource, $directfile = ''){
> global $CFG;
24c24
< if (!isadmin($USER->id)) return;
---
> if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
38,40c38,43
< }
< else{
< $file = escapeshellarg($CFG->dataroot.'/'.$resource->course.'/'.$resource->reference);
---
> } else {
> if ($directfile == ''){
> $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
> } else {
> $file = escapeshellarg("{$CFG->dataroot}/{$directfile}");
> }
46,47c49
< }
< else{
---
> } else {
52,53c54
< }
< else {
---
> } else {
Index: documents/physical_ppt.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/physical_ppt.php,v
retrieving revision 1.1.2.2
diff -r1.1.2.2 physical_ppt.php
32c32
< * @uses CFG, USER
---
> * @uses $CFG
34,35c34,35
< function get_text_for_indexing_ppt(&$resource){
< global $CFG, $USER;
---
> function get_text_for_indexing_ppt(&$resource, $directfile = ''){
> global $CFG;
40c40
< if (!isadmin($USER->id)) return;
---
> if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
42c42,46
< $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
---
> if ($directfile == ''){
> $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
> } else {
> $text = implode('', file("{$CFG->dataroot}/{$directfile}"));
> }
Index: documents/physical_txt.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/physical_txt.php,v
retrieving revision 1.1.2.1
diff -r1.1.2.1 physical_txt.php
18c18
< * @uses CFG, USER
---
> * @uses $CFG
20,21c20,21
< function get_text_for_indexing_txt(&$resource){
< global $CFG, $USER;
---
> function get_text_for_indexing_txt(&$resource, $directfile = ''){
> global $CFG;
24c24
< if (!isadmin($USER->id)) return;
---
> if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
27c27,32
< $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
---
> if ($directfile == ''){
> $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
> } else {
> $text = implode('', file("{$CFG->dataroot}/{$directfile}"));
> }
>
Index: documents/physical_xml.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/physical_xml.php,v
retrieving revision 1.1.2.2
diff -r1.1.2.2 physical_xml.php
18c18
< * @uses CFG, USER
---
> * @uses $CFG
21c21
< global $CFG, $USER;
---
> global $CFG;
24c24
< if (!isadmin($USER->id)) return;
---
> if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
Index: documents/resource_document.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/resource_document.php,v
retrieving revision 1.9.2.3
diff -r1.9.2.3 resource_document.php
47c47
< parent::__construct($doc, $data, $resource['course'], 0, 0, PATH_FOR_SEARCH_TYPE_RESOURCE);
---
> parent::__construct($doc, $data, $resource['course'], 0, 0, 'mod/'.SEARCH_TYPE_RESOURCE);
326c326,327
< return mb_convert_encoding($title, 'UTF-8', 'auto');
---
> // return mb_convert_encoding($title, 'UTF-8', 'auto');
> return mb_convert_encoding($title, 'auto', 'UTF-8');
cvs diff: cannot find documents/techproject_document.php
Index: documents/wiki_document.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/documents/wiki_document.php,v
retrieving revision 1.11.2.2
diff -r1.11.2.2 wiki_document.php
53c53
< parent::__construct($doc, $data, $course_id, $group_id, $user_id, PATH_FOR_SEARCH_TYPE_WIKI);
---
> parent::__construct($doc, $data, $course_id, $group_id, $user_id, 'mod/'.SEARCH_TYPE_WIKI);
cvs diff: Diffing tests
Index: tests/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/search/tests/index.php,v
retrieving revision 1.6.4.1
diff -r1.6.4.1 index.php
3,57c3,18
< /* Used to test if modules/blocks are ready to included in the search index.
< * Carries out some basic function/file existence tests - the search module
< * is expected to exist, along with the db schema files and the search data
< * directory.
< * */
<
< @set_time_limit(0);
< @ob_implicit_flush(true);
< @ob_end_flush();
<
< require_once('../../config.php');
< require_once("$CFG->dirroot/search/lib.php");
<
< require_login();
<
< $strsearch = get_string('search', 'search');
< $strquery = get_string('stats');
<
< $navlinks[] = array('name' => $strsearch, 'link' => "../index.php", 'type' => 'misc');
< $navlinks[] = array('name' => $strquery, 'link' => "../stats.php", 'type' => 'misc');
< $navlinks[] = array('name' => get_string('runindexertest','search'), 'link' => null, 'type' => 'misc');
< $navigation = build_navigation($navlinks);
< $site = get_site();
< print_header("$strsearch", "$site->fullname" , $navigation, "", "", true, " ", navmenu($site));
<
< if (empty($CFG->enableglobalsearch)) {
< error('Global searching is not enabled.');
< }
<
< if (!isadmin()) {
< error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
< } //if
<
< mtrace('Server Time: '.date('r',time()));
< mtrace("Testing global search capabilities:\n");
<
< $phpversion = phpversion();
<
< if (!search_check_php5()) {
< mtrace("ERROR: PHP 5.0.0 or later required (currently using version $phpversion).");
< exit(0);
< } else {
< mtrace("Success: PHP 5.0.0 or later is installed ($phpversion).\n");
< } //else
<
< //fix paths for testing
< set_include_path(get_include_path().":../");
< require_once("$CFG->dirroot/search/Zend/Search/Lucene.php");
<
< mtrace("Checking activity modules:\n");
<
< //the presence of the required search functions -
< // * mod_iterator
< // * mod_get_content_for_index
< //are the sole basis for including a module in the index at the moment.
---
> /* Used to test if modules/blocks are ready to included in the search index.
> * Carries out some basic function/file existence tests - the search module
> * is expected to exist, along with the db schema files and the search data
> * directory.
> **/
>
> @set_time_limit(0);
> @ob_implicit_flush(true);
> @ob_end_flush();
>
> require_once('../../config.php');
> require_once("$CFG->dirroot/search/lib.php");
>
> /// makes inclusions of the Zend Engine more reliable
> $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
> ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path'));
59,60c20,47
< if ($mods = get_records_select('modules')) {
< $mods = array_merge($mods, search_get_additional_modules());
---
> require_login();
>
> if (empty($CFG->enableglobalsearch)) {
> error('Global searching is not enabled.');
> }
>
> if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
> error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
> } //if
>
> mtrace('Server Time: '.date('r',time()));
> mtrace("Testing global search capabilities:\n");
>
> $phpversion = phpversion();
>
> //fix paths for testing
> set_include_path(get_include_path().":../");
> require_once("$CFG->dirroot/search/Zend/Search/Lucene.php");
>
> mtrace("Checking activity modules:\n");
>
> //the presence of the required search functions -
> // * mod_iterator
> // * mod_get_content_for_index
> //are the sole basis for including a module in the index at the moment.
>
> /// get all installed modules
> if ($mods = get_records('modules', '', '', 'name', 'id,name')){
62,63c49
< foreach ($mods as $mod) {
< $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
---
> $searchabletypes = array_values(search_get_document_types());
64a51,100
> foreach($mods as $mod){
> if (in_array($mod->name, $searchabletypes)){
> $mod->location = 'internal';
> $searchables[] = $mod;
> } else {
> $documentfile = $CFG->dirroot."/mod/{$mod->name}/search_document.php";
> $mod->location = 'mod';
> if (file_exists($documentfile)){
> $searchables[] = $mod;
> }
> }
> }
> mtrace(count($searchables).' modules to search in / '.count($mods).' modules found.');
> }
>
> /// collects blocks as indexable information may be found in blocks either
> if ($blocks = get_records('block', '', '', 'name', 'id,name')) {
> $blocks_searchables = array();
> // prepend the "block_" prefix to discriminate document type plugins
> foreach($blocks as $block){
> $block->dirname = $block->name;
> $block->name = 'block_'.$block->name;
> if (in_array('SEARCH_TYPE_'.strtoupper($block->name), $searchabletypes)){
> $mod->location = 'internal';
> $blocks_searchables[] = $block;
> } else {
> $documentfile = $CFG->dirroot."/blocks/{$block->dirname}/search_document.php";
> if (file_exists($documentfile)){
> $mod->location = 'blocks';
> $blocks_searchables[] = $block;
> }
> }
> }
> mtrace(count($blocks_searchables).' blocks to search in / '.count($blocks).' blocks found.');
> $searchables = array_merge($searchables, $blocks_searchables);
> }
>
> /// add virtual modules onto the back of the array
>
> $additional = search_get_additional_modules();
> mtrace(count($additional).' additional to search in.');
> $searchables = array_merge($searchables, $additional);
>
> foreach ($searchables as $mod) {
> if ($mod->location == 'internal'){
> $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
> } else {
> $class_file = $CFG->dirroot.'/'.$mod->location.'/'.$mod->name.'/search_document.php';
> }
>
67,69c103,105
<
< if (!defined('SEARCH_TYPE_'.strtoupper($mod->name))) {
< mtrace("ERROR: Constant 'SEARCH_TYPE_".strtoupper($mod->name)."' is not defined in /search/lib.php");
---
>
> if (!defined('X_SEARCH_TYPE_'.strtoupper($mod->name))) {
> mtrace("ERROR: Constant 'X_SEARCH_TYPE_".strtoupper($mod->name)."' is not defined in search/searchtypes.php or in module");
71,72c107,108
< } //if
<
---
> }
>
75c111
<
---
>
79c115
<
---
>
84c120
< } //else
---
> }
87c123
< } //else
---
> }
90c126
< } //else
---
> }
93,105c129,139
< } //else
< } //foreach
< } //if
<
< //finished modules
< mtrace("\nFinished checking activity modules.");
<
< //now blocks...
< //
<
< mtrace("
Back to query page or Start indexing.");
< mtrace('');
< print_footer();
---
> }
> }
>
> //finished modules
> mtrace("\nFinished checking activity modules.");
>
> //now blocks...
> //
>
> mtrace("
Back to query page or Start indexing.");
> mtrace('');