]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/dumb/TextSearchIter.php
improve match: pagename first, fulltext only if failed
[SourceForge/phpwiki.git] / lib / WikiDB / backend / dumb / TextSearchIter.php
1 <?php // -*-php-*-
2 rcs_id('$Id: TextSearchIter.php,v 1.4 2004-11-29 17:55:04 rurban Exp $');
3
4 class WikiDB_backend_dumb_TextSearchIter
5 extends WikiDB_backend_iterator
6 {
7     function WikiDB_backend_dumb_TextSearchIter(&$backend, &$pages, $search, $fulltext=false) {
8         $this->_backend = &$backend;
9         $this->_pages = $pages;
10         $this->_fulltext = $fulltext;
11         $this->_search = $search;
12     }
13
14     function _get_content(&$page) {
15         $backend = &$this->_backend;
16         $pagename = $page['pagename'];
17         
18         if (!isset($page['versiondata'])) {
19             $version = $backend->get_latest_version($pagename);
20             $page['versiondata'] = $backend->get_versiondata($pagename, $version, true);
21         }
22         return $page['versiondata']['%content'];
23     }
24         
25     function _match(&$page) {
26         $text = $page['pagename'];
27         if ($result = $this->_search->match($text)) // first match the pagename only
28             return $result;
29
30         if ($this->_fulltext) {
31             $text .= "\n" . $this->_get_content($page);
32             return $this->_search->match($text);
33         } else
34             return $result;
35     }
36
37     function next() {
38         $pages = &$this->_pages;
39         while ($page = $pages->next()) {
40             if ($this->_match($page))
41                 return $page;
42         }
43         return false;
44     }
45
46     function free() {
47         $this->_pages->free();
48     }
49 };
50
51 // (c-file-style: "gnu")
52 // Local Variables:
53 // mode: php
54 // tab-width: 8
55 // c-basic-offset: 4
56 // c-hanging-comment-ender-p: nil
57 // indent-tabs-mode: nil
58 // End:   
59 ?>