File: TextSearchTest.php

package info (click to toggle)
phpwiki 1.3.12p3-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 16,956 kB
  • ctags: 21,608
  • sloc: php: 82,335; xml: 3,840; sh: 1,522; sql: 1,198; perl: 625; makefile: 562; awk: 28
file content (79 lines) | stat: -rw-r--r-- 4,514 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
78
79
<?php

require_once 'lib/TextSearchQuery.php';
require_once 'PHPUnit.php';

class TextSearchTest extends phpwiki_TestCase {

    function testTitleSearch() {
        global $request;
	// find subpages
	$pagename = "PgsrcTranslation";
        $query = new TextSearchQuery($pagename . SUBPAGE_SEPARATOR . '*', true, 'glob');
	$sortby = false; $limit = 20; $exclude = "";
        $dbi = $request->getDbh();
        $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude);

	$result = array();
	while ($page = $subpages->next())
	    $result[] = $page->getName();
        $this->assertTrue(count($result) > 0, "glob count > 0");

	// apply limit
	$sortby = false; $limit = 5; $exclude = "";
        $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude);

	// don't trust count() with limit
	$this->assertTrue($subpages->count() > 0 and $subpages->count() <= 7, 
			  "0 < count() <= 7");
	$result = array();
	// but the iterator should limit
	while ($page = $subpages->next())
	    $result[] = $page->getName();
	$this->assertEquals(5, count($result), "limit 5");
	
    }

    function testFulltextSearch() {
        global $request;
        $dbi = $request->getDbh();
	$sortby = false; $limit = 2; $exclude = "";

        $query = new TextSearchQuery('WikiPlugin to let users attach comments', true); // auto
        $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
        $result = array();
	while ($page = $pages->next())
	    $result[] = $page->getName();
        $this->assertTrue(in_array("AddCommentPlugin", $result), "found all, no regex");

        $query = new TextSearchQuery('WikiPlugin* to let users attach comments*', false); // auto
	/* => (LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (LOWER(pagename) LIKE '%to%') AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%')
	 SELECT page.id AS id, page.pagename AS pagename, page.hits AS hits,page.pagedata as pagedata,version.version AS version, version.mtime AS mtime, version.minor_edit AS minor_edit, version.content AS content, version.versiondata AS versiondata FROM nonempty, page, recent, version WHERE nonempty.id=page.id AND page.id=recent.id AND page.id=version.id AND latestversion=version AND ((LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (LOWER(pagename) LIKE '%to%') AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%'))
	 SELECT page.id AS id, page.pagename AS pagename, page.hits AS hits,page.pagedata as pagedata,version.version AS version, version.mtime AS mtime, version.minor_edit AS minor_edit, version.content AS content, version.versiondata AS versiondata FROM nonempty, page, recent, version WHERE nonempty.id=page.id AND page.id=recent.id AND page.id=version.id AND latestversion=version AND ((LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (1=1) AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%'))
	 */
        $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
        $result = array();
	while ($page = $pages->next())
	    $result[] = $page->getName();
        $this->assertTrue(in_array("AddCommentPlugin", $result), "found regex all");

	$sortby = false; $limit = 2; $exclude = "";
        $query = new TextSearchQuery('"Indent the paragraph"', false); // case-insensitive, auto
        $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
        $result = array();
	while ($page = $pages->next())
	    $result[] = $page->getName();
        $this->assertTrue(in_array("TextFormattingRules", $result), "found phrase");

        $query = new TextSearchQuery('"Indent the paragraph"', false); // case-insensitive, auto
        $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
        $result = array();
	while ($page = $pages->next())
	    $result[] = $page->getName();
        $this->assertTrue(in_array("TextFormattingRules", $result), "found case phrase");
        
    }
}


?>