3 require_once 'lib/TextSearchQuery.php';
4 require_once 'PHPUnit.php';
6 class TextSearchTest extends phpwiki_TestCase {
8 function testTitleSearch() {
11 $pagename = "PgsrcTranslation";
12 $query = new TextSearchQuery($pagename . SUBPAGE_SEPARATOR . '*', true, 'glob');
13 $sortby = false; $limit = 20; $exclude = "";
14 $dbi = $request->getDbh();
15 $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude);
18 while ($page = $subpages->next())
19 $result[] = $page->getName();
20 $this->assertTrue(count($result) > 0, "glob count > 0");
23 $sortby = false; $limit = 5; $exclude = "";
24 $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude);
26 // don't trust count() with limit
27 $this->assertTrue($subpages->count() > 0 and $subpages->count() <= 7,
30 // but the iterator should limit
31 while ($page = $subpages->next())
32 $result[] = $page->getName();
33 $this->assertEquals(5, count($result), "limit 5");
37 function testFulltextSearch() {
39 $dbi = $request->getDbh();
40 $sortby = false; $limit = 2; $exclude = "";
42 $query = new TextSearchQuery('WikiPlugin to let users attach comments', true); // auto
43 $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
45 while ($page = $pages->next())
46 $result[] = $page->getName();
47 $this->assertTrue(in_array("AddCommentPlugin", $result), "found all, no regex");
49 $query = new TextSearchQuery('WikiPlugin* to let users attach comments*', false); // auto
50 /* => (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%')
51 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%'))
52 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%'))
54 $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
56 while ($page = $pages->next())
57 $result[] = $page->getName();
58 $this->assertTrue(in_array("AddCommentPlugin", $result), "found regex all");
60 $sortby = false; $limit = 2; $exclude = "";
61 $query = new TextSearchQuery('"Indent the paragraph"', false); // case-insensitive, auto
62 $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
64 while ($page = $pages->next())
65 $result[] = $page->getName();
66 $this->assertTrue(in_array("TextFormattingRules", $result), "found phrase");
68 $query = new TextSearchQuery('"Indent the paragraph"', false); // case-insensitive, auto
69 $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
71 while ($page = $pages->next())
72 $result[] = $page->getName();
73 $this->assertTrue(in_array("TextFormattingRules", $result), "found case phrase");