]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/dumb/TextSearchIter.php
support limit
[SourceForge/phpwiki.git] / lib / WikiDB / backend / dumb / TextSearchIter.php
1 <?php // -*-php-*-
2 rcs_id('$Id: TextSearchIter.php,v 1.5 2005-09-11 13:20:52 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                                                 $options=array()) 
9     {
10         $this->_backend = &$backend;
11         $this->_pages = $pages;
12         $this->_fulltext = $fulltext;
13         $this->_search  = $search;
14         $this->_index   = 0;
15
16         if (isset($options['limit'])) $this->_limit = $options['limit'];
17         else $this->_limit = 0;
18         if (isset($options['exclude'])) $this->_exclude = $options['exclude'];
19         else $this->_exclude = false;
20     }
21
22     function _get_content(&$page) {
23         $backend = &$this->_backend;
24         $pagename = $page['pagename'];
25         
26         if (!isset($page['versiondata'])) {
27             $version = $backend->get_latest_version($pagename);
28             $page['versiondata'] = $backend->get_versiondata($pagename, $version, true);
29         }
30         return $page['versiondata']['%content'];
31     }
32         
33     function _match(&$page) {
34         $text = $page['pagename'];
35         if ($result = $this->_search->match($text)) // first match the pagename only
36             return $result;
37
38         if ($this->_fulltext) {
39             $text .= "\n" . $this->_get_content($page);
40             return $this->_search->match($text);
41         } else
42             return $result;
43     }
44
45     function next() {
46         $pages = &$this->_pages;
47         while ($page = $pages->next()) {
48             if ($this->_match($page)) {
49                 if ($this->_limit and ($this->_index++ >= $this->_limit))
50                     return false;
51                 return $page;
52             }
53         }
54         return false;
55     }
56
57     function free() {
58         $this->_pages->free();
59     }
60 };
61
62 // (c-file-style: "gnu")
63 // Local Variables:
64 // mode: php
65 // tab-width: 8
66 // c-basic-offset: 4
67 // c-hanging-comment-ender-p: nil
68 // indent-tabs-mode: nil
69 // End:   
70 ?>