2 class WikiDB_backend_dumb_TextSearchIter
3 extends WikiDB_backend_iterator
5 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;
13 $this->_stoplist =& $search->_stoplist;
14 $this->stoplisted = array();
17 if (isset($options['limit'])) // extract from,count from limit
18 list($this->_from, $this->_count) = WikiDB_backend::limit($options['limit']);
21 if (isset($options['exclude'])) $this->_exclude = $options['exclude'];
22 else $this->_exclude = false;
25 function _get_content(&$page) {
26 $backend = &$this->_backend;
27 $pagename = $page['pagename'];
29 if (!isset($page['versiondata'])) {
30 $version = $backend->get_latest_version($pagename);
31 $page['versiondata'] = $backend->get_versiondata($pagename, $version, true);
33 return $page['versiondata']['%content'];
36 function _match(&$page) {
37 $text = $page['pagename'];
38 if ($result = $this->_search->match($text)) { // first match the pagename only
39 return $this->_search->score($text) * 2.0;
42 if ($this->_fulltext) {
43 // eliminate stoplist words from fulltext search
44 if (preg_match("/^".$this->_stoplist."$/i", $text)) {
45 $this->stoplisted[] = $text;
48 $text .= "\n" . $this->_get_content($page);
49 // Todo: Bonus for meta keywords (* 1.5) and headers
50 if ($this->_search->match($text))
51 return $this->_search->score($text);
58 $pages = &$this->_pages;
59 while ($page = $pages->next()) {
60 if ($score = $this->_match($page)) {
62 if (($this->_from > 0) and ($this->_index <= $this->_from))
63 // not yet reached the offset
65 /*if ($this->_count and ($this->_index > $this->_count)) {
66 // reached the limit, but need getTotal
71 $page['score'] = $score;
73 $page->score = $score;
81 $this->_pages->free();
89 // c-hanging-comment-ender-p: nil
90 // indent-tabs-mode: nil