Permalink
Browse files

Initial commit

  • Loading branch information...
1 parent 1cd1252 commit 682d4032591a033060e3683c3f0c300c9de4d87e mchampan committed Jun 25, 2006
Showing with 7,732 additions and 0 deletions.
  1. +70 −0 blocks/search/block_search.php
  2. +19 −0 blocks/search/config_global.html
  3. +120 −0 mod/wiki/lib.php
  4. +22 −0 search/README.txt
  5. +30 −0 search/Zend/Exception.php
  6. +15 −0 search/Zend/IMPORTANT.txt
  7. +27 −0 search/Zend/LICENSE.txt
  8. +36 −0 search/Zend/Search/Exception.php
  9. +614 −0 search/Zend/Search/Lucene.php
  10. +96 −0 search/Zend/Search/Lucene/Analysis/Analyzer.php
  11. +75 −0 search/Zend/Search/Lucene/Analysis/Analyzer/Common.php
  12. +78 −0 search/Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php
  13. +46 −0 search/Zend/Search/Lucene/Analysis/Analyzer/Common/Text/CaseInsensitive.php
  14. +171 −0 search/Zend/Search/Lucene/Analysis/Token.php
  15. +47 −0 search/Zend/Search/Lucene/Analysis/TokenFilter.php
  16. +57 −0 search/Zend/Search/Lucene/Analysis/TokenFilter/LowerCase.php
  17. +111 −0 search/Zend/Search/Lucene/Document.php
  18. +32 −0 search/Zend/Search/Lucene/EncodingConverter.php
  19. +36 −0 search/Zend/Search/Lucene/Exception.php
  20. +161 −0 search/Zend/Search/Lucene/Field.php
  21. +45 −0 search/Zend/Search/Lucene/Index/FieldInfo.php
  22. +575 −0 search/Zend/Search/Lucene/Index/SegmentInfo.php
  23. +519 −0 search/Zend/Search/Lucene/Index/SegmentWriter.php
  24. +72 −0 search/Zend/Search/Lucene/Index/Term.php
  25. +79 −0 search/Zend/Search/Lucene/Index/TermInfo.php
  26. +331 −0 search/Zend/Search/Lucene/Index/Writer.php
  27. +100 −0 search/Zend/Search/Lucene/Search/Query.php
  28. +439 −0 search/Zend/Search/Lucene/Search/Query/MultiTerm.php
  29. +426 −0 search/Zend/Search/Lucene/Search/Query/Phrase.php
  30. +128 −0 search/Zend/Search/Lucene/Search/Query/Term.php
  31. +108 −0 search/Zend/Search/Lucene/Search/QueryHit.php
  32. +142 −0 search/Zend/Search/Lucene/Search/QueryParser.php
  33. +104 −0 search/Zend/Search/Lucene/Search/QueryToken.php
  34. +164 −0 search/Zend/Search/Lucene/Search/QueryTokenizer.php
  35. +553 −0 search/Zend/Search/Lucene/Search/Similarity.php
  36. +105 −0 search/Zend/Search/Lucene/Search/Similarity/Default.php
  37. +61 −0 search/Zend/Search/Lucene/Search/Weight.php
  38. +135 −0 search/Zend/Search/Lucene/Search/Weight/MultiTerm.php
  39. +141 −0 search/Zend/Search/Lucene/Search/Weight/Phrase.php
  40. +146 −0 search/Zend/Search/Lucene/Search/Weight/Term.php
  41. +120 −0 search/Zend/Search/Lucene/Storage/Directory.php
  42. +272 −0 search/Zend/Search/Lucene/Storage/Directory/Filesystem.php
  43. +371 −0 search/Zend/Search/Lucene/Storage/File.php
  44. +171 −0 search/Zend/Search/Lucene/Storage/File/Filesystem.php
  45. +14 −0 search/Zend/Search/TODO.txt
  46. +15 −0 search/db/mysql.sql
  47. +21 −0 search/db/postgres7.sql
  48. +12 −0 search/documents/document.php
  49. +28 −0 search/documents/wiki_document.php
  50. +10 −0 search/index.php
  51. +152 −0 search/indexer.php
  52. +44 −0 search/indexersplash.php
  53. +59 −0 search/lib.php
  54. +116 −0 search/query.php
  55. +91 −0 search/stats.php
@@ -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
+
+?>
@@ -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>
View
@@ -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) {
/// Returns the wiki entry according to the wiki type.
/// Optionally, will return wiki entry for $userid student wiki, or
View
@@ -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
View
@@ -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
+{}
+
View
@@ -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
View
@@ -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.
@@ -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
+{}
+
Oops, something went wrong.

0 comments on commit 682d403

Please sign in to comment.