Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mchampan committed Jun 25, 2006
1 parent 1cd1252 commit 682d403
Show file tree
Hide file tree
Showing 55 changed files with 7,732 additions and 0 deletions.
70 changes: 70 additions & 0 deletions blocks/search/block_search.php
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/* This is the global search shortcut block - a single query can be entered, and
the user will be redirected to the query page where they can enter more
advanced queries, and view the results of their search. When searching from
this block, the broadest possible selection of documents is searched.
Author: Michael Champanis (mchampan)
Date: 2006 06 23
Todo: make strings -> get_string()
*/

class block_search extends block_base {

function init() {
$this->title = "Global Search"; //get_string()
$this->version = 20060625;
} //init

// only one instance of this block is required
function instance_allow_multiple() {
return false;
} //instance_allow_multiple

// label and button values can be set in admin
function has_config() {
return true;
} //has_config

function get_content() {
global $CFG;

//cache block contents
if ($this->content !== NULL) {
return $this->content;
} //if

$this->content = new stdClass;

//lazy check for the moment
if (check_php_version("5.0.0")) {
//fetch values if defined in admin, otherwise use defaults
$label = (isset($CFG->block_search_text)) ? $CFG->block_search_text : "Search Moodle";
$button = (isset($CFG->block_search_button)) ? $CFG->block_search_button : "Go";

//basic search form
$this->content->text =
'<form name="query" method="post" action="search/query.php">'
. "<label for=''>$label</label>"
. '<input type="text" name="query_string" length="50" value=""/>'
. '<input type="submit" value="'.$button.'"/>'
. '</form>';
} else {
$this->content->text = "Sorry folks, PHP 5 is needed for the new search module.";
} //else

//no footer, thanks
$this->content->footer = '';

return $this->content;
} //get_content

function specialisation() {
//empty!
} //specialisation

} //block_search

?>
19 changes: 19 additions & 0 deletions blocks/search/config_global.html
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,19 @@
<div style="text-align:center;">
<label for="block_search_text">Search label</label>
<input type="text" name="block_search_text" value="<?php
if(isset($CFG->block_search_text)) {
p($CFG->block_search_text);
} else {
p("Search Moodle");
} ?>"/><br>

<label for="block_search_button">Button label</label>
<input type="text" name="block_search_button" value="<?php
if(isset($CFG->block_search_button)) {
p($CFG->block_search_button);
} else {
p("Go");
} ?>"/><br><br>

<input type="submit" value="<?php print_string('savechanges'); ?>" />
</div>
120 changes: 120 additions & 0 deletions mod/wiki/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -352,6 +352,126 @@ function wiki_get_entries(&$wiki, $byindex=NULL) {
} }
} }
/*==== Global search modifications
* Author: Michael Champanis (mchampan)
* Last date: 2006 06 25
* These modifications allow wiki documents to be indexed in the new
* search engine module - they are probably not final, and as such
* shouldn't be used by other stuff for the time being
**/
//rescued and converted from ewikimoodlelib.php
//retrieves latest version of a page
function wiki_get_latest_page(&$entry, $pagename, $version=0) {
global $CFG;
//need something like this in datalib.php?
switch ($CFG->dbtype) {
case 'mysql':
$f = 'mysql_real_escape_string';
break;
case 'postgres7':
$f = 'pg_escape_string';
break;
default:
$f = 'addslashes';
} //switch
$pagename = "'".$f($pagename)."'";

if ($version > 0 and is_int($version)) {
$version = "AND (version=$version)";
} else {
$version = '';
} //else

$select = "(pagename=$pagename) AND wiki=".$entry->id." $version ";
$sort = 'version DESC';

//change this to recordset_select, as per http://docs.moodle.org/en/Datalib_Notes
if ($result_arr = get_records_select('wiki_pages', $select, $sort, '*', 0, 1)) {
foreach ($result_arr as $obj) {
$result_obj = $obj;
} //foreach
} //if

if (isset($result_obj)) {
$result_obj->meta = @unserialize($result_obj->meta);
return $result_obj;
} else {
return false;
} //else
} //wiki_get_latest_page

//fetches all pages, including old versions
function wiki_get_pages(&$entry) {
return get_records('wiki_pages', 'wiki', $entry->id);
} //wiki_get_pages

//fetches all the latest versions of all the pages
function wiki_get_latest_pages(&$entry) {
//== (My)SQL for this
/* select * from wiki_pages
inner join
(select wiki_pages.pagename, max(wiki_pages.version) as ver
from wiki_pages group by pagename) as a
on ((wiki_pages.version = a.ver) and
(wiki_pages.pagename like a.pagename)) */

$pages = array();

//http://moodle.org/bugs/bug.php?op=show&bugid=5877&pos=0
//if ($ids = get_records('wiki_pages', 'wiki', $entry->id, '', 'distinct pagename')) {
if ($rs = get_recordset('wiki_pages', 'wiki', $entry->id, '', 'distinct pagename')) {
$ids = $rs->GetRows();
//--
foreach ($ids as $id) {
$pages[] = wiki_get_latest_page($entry, $id[0]);
} //foreach
} else {
return false;
} //else

return $pages;
} //wiki_get_latest_pages

function wiki_iterator() {
return get_all_instances_in_courses("wiki", get_courses());
} //wiki_search_index

function wiki_get_content_for_index(&$wiki) {
$documents = array();

$entries = wiki_get_entries($wiki);
foreach($entries as $entry) {
//all pages
//$pages = wiki_get_pages($entry);

//latest pages
$pages = wiki_get_latest_pages($entry);
$i = 0;

if (is_array($pages)) {
foreach($pages as $page) {
if (strlen($page->content) > 0) {
$i++;
$documents[] = new WikiSearchDocument($page, $entry->wikiid, $entry->course, $entry->userid, $entry->groupid);
} //if
} //foreach

//print "$entry->id : $i"; print "<br>";
} else {
print $pages;
} //else
} //foreach

return $documents;
} //wiki_get_content_for_index

/*==== Global search modifications end */


function wiki_get_default_entry(&$wiki, &$course, $userid=0, $groupid=0) { function wiki_get_default_entry(&$wiki, &$course, $userid=0, $groupid=0) {
/// Returns the wiki entry according to the wiki type. /// Returns the wiki entry according to the wiki type.
/// Optionally, will return wiki entry for $userid student wiki, or /// Optionally, will return wiki entry for $userid student wiki, or
Expand Down
22 changes: 22 additions & 0 deletions search/README.txt
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,22 @@
This is the initial release (prototype) of Moodle's new search module -
so basically watch out for sharp edges.

The structure has not been finalised, but this is what is working at the
moment, when I start looking at other content to index, it will most likely
change. I don't recommend trying to make your own content modules indexable,
at least not until the whole flow is finalised. I will be implementing the
functions needed to index all of the default content modules on Moodle, so
expect that around mid-August.

Wiki pages were my goal for this release, they can be indexed and searched,
but not updated or deleted at this stage (was waiting for ZF 0.14 actually).

I need to check the PostgreSQL sql file, I don't have a PG7 install lying
around to test on, so the script is untested.

To index for the first time, login as an admin user and browse to /search/index.php
or /search/stats.php - there will be a message and a link telling you to go index.

-- Michael Champanis (mchampan)
cynnical@gmail.com
Summer of Code 2006
30 changes: 30 additions & 0 deletions search/Zend/Exception.php
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend
* @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/


/**
* @category Zend
* @package Zend
* @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Exception extends Exception
{}

15 changes: 15 additions & 0 deletions search/Zend/IMPORTANT.txt
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,15 @@
We are running cutting-edge (i.e. HEAD) Zend Framework:
URL: http://framework.zend.com/svn/framework/trunk
Revision: 696
Last Changed Rev: 696
Last Changed Date: 2006-06-23 02:14:54 +0200 (Fri, 23 Jun 2006)

This Zend Framework present in this directory only contains the minimum
to run Zend_Search_Lucene - I don't foresee any problems, since the license
is new BSD...

To obtain a full Zend Framework package, please visit:
http://framework.zend.com/

Or alternatively check it out from SVN:
svn checkout http://framework.zend.com/svn/framework/trunk
27 changes: 27 additions & 0 deletions search/Zend/LICENSE.txt
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2006, Zend Technologies USA, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of Zend Technologies USA, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 changes: 36 additions & 0 deletions search/Zend/Search/Exception.php
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Search
* @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/


/**
* Framework base exception
*/
require_once 'Zend/Exception.php';


/**
* @category Zend
* @package Zend_Search
* @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Search_Exception extends Zend_Exception
{}

Loading

0 comments on commit 682d403

Please sign in to comment.