File: TextSearchIter.php

package info (click to toggle)
phpwiki 1.3.14-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 15,716 kB
  • ctags: 23,548
  • sloc: php: 88,295; sql: 1,476; sh: 1,378; perl: 765; makefile: 602; awk: 28
file content (77 lines) | stat: -rwxr-xr-x 2,357 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php // -*-php-*-
rcs_id('$Id: TextSearchIter.php,v 1.7 2005/11/14 22:24:33 rurban Exp $');

class WikiDB_backend_dumb_TextSearchIter
extends WikiDB_backend_iterator
{
    function WikiDB_backend_dumb_TextSearchIter(&$backend, &$pages, $search, $fulltext=false, 
                                                $options=array()) 
    {
        $this->_backend = &$backend;
        $this->_pages = $pages;
        $this->_fulltext = $fulltext;
        $this->_search  =& $search;
        $this->_index   = 0;
        $this->_stoplist =& $search->_stoplist;
        $this->stoplisted = array();

        if (isset($options['limit'])) $this->_limit = $options['limit'];
        else $this->_limit = 0;
        if (isset($options['exclude'])) $this->_exclude = $options['exclude'];
        else $this->_exclude = false;
    }

    function _get_content(&$page) {
        $backend = &$this->_backend;
        $pagename = $page['pagename'];
        
        if (!isset($page['versiondata'])) {
            $version = $backend->get_latest_version($pagename);
            $page['versiondata'] = $backend->get_versiondata($pagename, $version, true);
        }
        return $page['versiondata']['%content'];
    }
        
    function _match(&$page) {
        $text = $page['pagename'];
        if ($result = $this->_search->match($text)) // first match the pagename only
            return $result;

        if ($this->_fulltext) {
            // eliminate stoplist words from fulltext search
            if (preg_match("/^".$this->_stoplist."$/i", $text)) {
                $this->stoplisted[] = $text;
                return $result;
            }
            $text .= "\n" . $this->_get_content($page);
            return $this->_search->match($text);
        } else
            return $result;
    }

    function next() {
        $pages = &$this->_pages;
        while ($page = $pages->next()) {
            if ($this->_match($page)) {
                if ($this->_limit and ($this->_index++ >= $this->_limit))
                    return false;
                return $page;
            }
        }
        return false;
    }

    function free() {
        $this->_pages->free();
    }
};

// (c-file-style: "gnu")
// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:   
?>