Update of /cvsroot/phpwiki/phpwiki/lib/WikiDB/backend
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14174/backend
Modified Files:
ADODB.php ADODB_oci8po.php PDO.php PearDB.php PearDB_oci8.php
PearDB_pgsql.php cvs.php
Log Message:
fix fulltext search,
Eliminate stoplist words,
don't extract %pagedate twice in ADODB,
add SemanticWeb support: link(relation),
major postgresql update: stored procedures, tsearch2 for fulltext
Index: ADODB.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/WikiDB/backend/ADODB.php,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -2 -b -p -d -r1.82 -r1.83
--- ADODB.php 31 Oct 2005 16:48:22 -0000 1.82
+++ ADODB.php 14 Nov 2005 22:24:33 -0000 1.83
@@ -413,5 +413,7 @@ extends WikiDB_backend
$data['%content'] = '';
if (!empty($pagedata)) {
- $data['%pagedata'] = $this->_extract_page_data($pagedata, $hits);
+ // hmm, $pagedata = is already extracted by WikiDB_backend_ADODB_iter
+ //$data['%pagedata'] = $this->_extract_page_data($pagedata, $hits);
+ $data['%pagedata'] = $pagedata;
}
return $data;
@@ -574,11 +576,18 @@ extends WikiDB_backend
$dbh->Execute("DELETE FROM $link_tbl WHERE linkfrom=$pageid");
foreach ($links as $link) {
- if (isset($linkseen[$link]))
+ $linkto = $link['linkto'];
+ if ($link['relation'])
+ $relation = $this->_get_pageid($link['relation'], true);
+ else
+ $relation = 0;
+ // avoid duplicates
+ if (isset($linkseen[$linkto]) and !$relation)
continue;
- $linkseen[$link] = true;
- $linkid = $this->_get_pageid($link, true);
+ if (!$relation)
+ $linkseen[$linkto] = true;
+ $linkid = $this->_get_pageid($linkto, true);
assert($linkid);
- $dbh->Execute("INSERT INTO $link_tbl (linkfrom, linkto)"
- . " VALUES ($pageid, $linkid)");
+ $dbh->Execute("INSERT INTO $link_tbl (linkfrom, linkto, relation)"
+ . " VALUES ($pageid, $linkid, $relation)");
}
} elseif (DEBUG) {
@@ -611,5 +620,7 @@ extends WikiDB_backend
*/
function get_links($pagename, $reversed=true, $include_empty=false,
- $sortby=false, $limit=false, $exclude='') {
+ $sortby=false, $limit=false, $exclude='',
+ $want_relations = false)
+ {
$dbh = &$this->_dbh;
extract($this->_table_names);
@@ -628,8 +639,10 @@ extends WikiDB_backend
$qpagename = $dbh->qstr($pagename);
// removed ref to FETCH_MODE in next line
- $sql = "SELECT $want.id AS id, $want.pagename AS pagename,"
- . " $want.hits AS hits"
- . " FROM $link_tbl, $page_tbl linker, $page_tbl linkee"
- . (!$include_empty ? ", $nonempty_tbl" : '')
+ $sql = "SELECT $want.id AS id, $want.pagename AS pagename, "
+ . ($want_relations ? " related.pagename as linkrelation" : " $want.hits AS hits")
+ . " FROM "
+ . (!$include_empty ? "$nonempty_tbl, " : '')
+ . " $page_tbl linkee, $page_tbl linker, $link_tbl "
+ . ($want_relations ? " JOIN $page_tbl related ON ($link_tbl.relation=related.id)" : '')
. " WHERE linkfrom=linker.id AND linkto=linkee.id"
. " AND $have.pagename=$qpagename"
@@ -638,4 +651,9 @@ extends WikiDB_backend
. $exclude
. $orderby;
+/*
+ echo "SELECT linkee.id AS id, linkee.pagename AS pagename, related.pagename as linkrelation FROM link, page linkee, page linker JOIN page related ON (link.relation=related.id) WHERE linkfrom=linker.id AND linkto=linkee.id AND linker.pagename='SanDiego'" | mysql phpwiki
+id pagename linkrelation
+2268 California located_in
+*/
if ($limit) {
// extract from,count from limit
@@ -645,5 +663,8 @@ extends WikiDB_backend
$result = $dbh->Execute($sql);
}
- return new WikiDB_backend_ADODB_iter($this, $result, $this->page_tbl_field_list);
+ $fields = $this->page_tbl_field_list;
+ if ($want_relations) // instead of hits
+ $fields[2] = 'linkrelation';
+ return new WikiDB_backend_ADODB_iter($this, $result, $fields);
}
@@ -731,7 +752,9 @@ extends WikiDB_backend
/**
- * Title search.
+ * Title and fulltext search.
*/
- function text_search($search, $fullsearch=false, $sortby=false, $limit=false, $exclude=false) {
+ function text_search($search, $fullsearch=false,
+ $sortby=false, $limit=false, $exclude=false)
+ {
$dbh = &$this->_dbh;
extract($this->_table_names);
@@ -753,5 +776,6 @@ extends WikiDB_backend
$fields .= ",$page_tbl.pagedata as pagedata," . $this->version_tbl_fields;
- $field_list = array_merge($field_list, array('pagedata'), $this->version_tbl_field_list);
+ $field_list = array_merge($field_list, array('pagedata'),
+ $this->version_tbl_field_list);
$callback = new WikiMethodCb($searchobj, "_fulltext_match_clause");
} else {
@@ -771,27 +795,9 @@ extends WikiDB_backend
$result = $dbh->Execute($sql);
}
- return new WikiDB_backend_ADODB_iter($this, $result, $field_list);
- }
- /*
- function _sql_match_clause($word) {
- //not sure if we need this. ADODB may do it for usand function_exists('pg_escape_bytea')
- $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);
-
- // (we need it for at least % and _ --- they're the wildcard characters
- // for the LIKE operator, and we need to quote them if we're searching
- // for literal '%'s or '_'s. --- I'm not sure about \, but it seems to
- // work as is.
- $word = $this->_dbh->qstr("%".strtolower($word)."%");
- $page_tbl = $this->_table_names['page_tbl'];
- return "LOWER($page_tbl.pagename) LIKE $word";
- }
- function _fullsearch_sql_match_clause($word) {
- $word = preg_replace('/(?=[%_\\\\])/', "\\", $word); //not sure if we need this
- // (see above)
- $word = $this->_dbh->qstr("%".strtolower($word)."%");
- $page_tbl = $this->_table_names['page_tbl'];
- return "LOWER($page_tbl.pagename) LIKE $word OR content LIKE $word";
+ $iter = new WikiDB_backend_ADODB_iter($this, $result, $field_list);
+ if ($fullsearch)
+ $iter->stoplisted = $searchobj->stoplisted;
+ return $iter;
}
- */
/*
@@ -812,5 +818,5 @@ extends WikiDB_backend
* Find highest or lowest hit counts.
*/
- function most_popular($limit=20, $sortby='-hits') {
+ function most_popular ($limit=20, $sortby='-hits') {
$dbh = &$this->_dbh;
extract($this->_table_names);
@@ -1240,39 +1246,15 @@ extends WikiDB_backend_ADODB_generic_ite
$rec_assoc['versiondata'] = $backend->_extract_version_data_assoc($rec_assoc);
}
+ if (!empty($rec_assoc['linkrelation'])) {
+ $rec_assoc['linkrelation'] = $rec_assoc['linkrelation']; // pagename enough?
+ }
return $rec_assoc;
}
}
-class WikiDB_backend_ADODB_search
-extends WikiDB_backend_search
+class WikiDB_backend_ADODB_search extends WikiDB_backend_search_sql
{
- function WikiDB_backend_ADODB_search(&$search, &$dbh) {
- $this->_dbh =& $dbh;
- $this->_case_exact = $search->_case_exact;
- $this->_stoplist =& $search->_stoplist;
- }
- function _pagename_match_clause($node) {
- $word = $node->sql();
- if ($word == '%')
- return "1=1";
- else
- return ($this->_case_exact
- ? "pagename LIKE '$word'"
- : "LOWER(pagename) LIKE '$word'");
- }
- function _fulltext_match_clause($node) {
- $word = $node->sql();
- if ($word == '%')
- return "1=1";
- // Eliminate stoplist words
- if (preg_match("/^%".$this->_stoplist."%/i", $word)
- or preg_match("/^".$this->_stoplist."$/i", $word))
- return $this->_pagename_match_clause($node);
- else
- return $this->_pagename_match_clause($node)
- . ($this->_case_exact
- ? " OR content LIKE '$word'"
- : " OR content LIKE '$word'");
- }
+ // no surrounding quotes because we know it's a string
+ // function _quote($word) { return $this->_dbh->escapeSimple($word); }
}
@@ -1437,4 +1419,11 @@ extends WikiDB_backend_search
// $Log$
+// Revision 1.83 2005/11/14 22:24:33 rurban
+// fix fulltext search,
+// Eliminate stoplist words,
+// don't extract %pagedate twice in ADODB,
+// add SemanticWeb support: link(relation),
+// major postgresql update: stored procedures, tsearch2 for fulltext
+//
// Revision 1.82 2005/10/31 16:48:22 rurban
// move mysql-specifics into its special class
Index: ADODB_oci8po.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/WikiDB/backend/ADODB_oci8po.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -2 -b -p -d -r1.3 -r1.4
--- ADODB_oci8po.php 18 Jan 2005 20:55:47 -0000 1.3
+++ ADODB_oci8po.php 14 Nov 2005 22:24:33 -0000 1.4
@@ -131,6 +131,8 @@ extends WikiDB_backend_ADODB_search
// Note that this does only an exact fulltext search, not using MATCH or LIKE.
function _fulltext_match_clause($node) {
- $page = $node->sql($word);
- $exactword = $node->_sql_quote();
+ if ($this->isStoplisted($node))
+ return "1=1";
+ $page = $node->sql();
+ $exactword = $node->_sql_quote($node->word);
return ($this->_case_exact
? "pagename LIKE '$page' OR DBMS_LOB.INSTR(content, '$exactword') > 0"
Index: PDO.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/WikiDB/backend/PDO.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -2 -b -p -d -r1.5 -r1.6
--- PDO.php 14 Sep 2005 06:04:43 -0000 1.5
+++ PDO.php 14 Nov 2005 22:24:33 -0000 1.6
@@ -866,5 +866,7 @@ extends WikiDB_backend
$sth->execute();
$result = $sth->fetch(PDO_FETCH_NUM);
- return new WikiDB_backend_PDO_iter($this, $result, $field_list);
+ $iter = new WikiDB_backend_PDO_iter($this, $result, $field_list);
+ $iter->stoplisted = $searchobj->stoplisted;
+ return $iter;
}
@@ -1296,35 +1298,5 @@ extends WikiDB_backend_PDO_generic_iter
}
-class WikiDB_backend_PDO_search
-extends WikiDB_backend_search
-{
- function WikiDB_backend_PDO_search(&$search, &$dbh) {
- $this->_dbh =& $dbh;
- $this->_case_exact = $search->_case_exact;
- }
- function _pagename_match_clause($node) {
- // word already quoted by TextSearchQuery_node_word::_sql_quote()
- $word = $node->sql();
- if ($word == '%')
- return "1=1";
- else
- return ($this->_case_exact
- ? "pagename LIKE '$word'"
- : "LOWER(pagename) LIKE '$word'");
- }
- function _fulltext_match_clause($node) {
- $word = $node->sql();
- if ($word == '%')
- return "1=1";
- // eliminate stoplist words
- if (preg_match("/^%".$this->_stoplist."%/i", $word)
- or preg_match("/^".$this->_stoplist."$/i", $word))
- return $this->_pagename_match_clause($node);
- else
- return $this->_pagename_match_clause($node)
- . ($this->_case_exact ? " OR content LIKE '$word'"
- : " OR LOWER(content) LIKE '$word'");
- }
-}
+class WikiDB_backend_PDO_search extends WikiDB_backend_search_sql {}
// Following function taken from Pear::DB (prev. from adodb-pear.inc.php).
@@ -1488,4 +1460,11 @@ extends WikiDB_backend_search
// $Log$
+// Revision 1.6 2005/11/14 22:24:33 rurban
+// fix fulltext search,
+// Eliminate stoplist words,
+// don't extract %pagedate twice in ADODB,
+// add SemanticWeb support: link(relation),
+// major postgresql update: stored procedures, tsearch2 for fulltext
+//
// Revision 1.5 2005/09/14 06:04:43 rurban
// optimize searching for ALL (ie %), use the stoplist on PDO
Index: PearDB.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/WikiDB/backend/PearDB.php,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -2 -b -p -d -r1.93 -r1.94
--- PearDB.php 10 Oct 2005 19:42:15 -0000 1.93
+++ PearDB.php 14 Nov 2005 22:24:33 -0000 1.94
@@ -418,4 +418,5 @@ extends WikiDB_backend
* Delete an old revision of a page.
*/
+
function delete_versiondata($pagename, $version) {
$dbh = &$this->_dbh;
@@ -511,10 +512,18 @@ extends WikiDB_backend
if ($links) {
foreach($links as $link) {
- if (isset($linkseen[$link]))
+ $linkto = $link['linkto'];
+ if ($link['relation'])
+ $relation = $this->_get_pageid($link['relation'], true);
+ else
+ $relation = 0;
+ // avoid duplicates
+ if (isset($linkseen[$linkto]) and !$relation)
continue;
- $linkseen[$link] = true;
- $linkid = $this->_get_pageid($link, true);
- $dbh->query("INSERT INTO $link_tbl (linkfrom, linkto)"
- . " VALUES ($pageid, $linkid)");
+ if (!$relation)
+ $linkseen[$linkto] = true;
+ $linkid = $this->_get_pageid($linkto, true);
+ assert($linkid);
+ $dbh->query("INSERT INTO $link_tbl (linkfrom, linkto, relation)"
+ . " VALUES ($pageid, $linkid, $relation)");
}
}
@@ -526,5 +535,7 @@ extends WikiDB_backend
*/
function get_links($pagename, $reversed=true, $include_empty=false,
- $sortby=false, $limit=false, $exclude='') {
+ $sortby=false, $limit=false, $exclude='',
+ $want_relations = false)
+ {
$dbh = &$this->_dbh;
extract($this->_table_names);
@@ -542,10 +553,10 @@ extends WikiDB_backend
$qpagename = $dbh->escapeSimple($pagename);
- $sql = "SELECT $want.id as id, $want.pagename as pagename, $want.hits as hits"
- // Looks like 'AS' in column alias is a MySQL thing, Oracle does not like it
- // and the PostgresSQL manual does not have it either
- // Since it is optional in mySQL, just remove it...
- . " FROM $link_tbl, $page_tbl linker, $page_tbl linkee"
- . (!$include_empty ? ", $nonempty_tbl" : '')
+ $sql = "SELECT $want.id AS id, $want.pagename AS pagename, "
+ . ($want_relations ? " related.pagename as linkrelation" : " $want.hits AS hits")
+ . " FROM "
+ . (!$include_empty ? "$nonempty_tbl, " : '')
+ . " $page_tbl linkee, $page_tbl linker, $link_tbl "
+ . ($want_relations ? " JOIN $page_tbl related ON ($link_tbl.relation=related.id)" : '')
. " WHERE linkfrom=linker.id AND linkto=linkee.id"
. " AND $have.pagename='$qpagename'"
@@ -647,9 +658,12 @@ extends WikiDB_backend
* Title search.
*/
- function text_search($search, $fulltext=false, $sortby=false, $limit=false, $exclude=false) {
+ function text_search($search, $fulltext=false, $sortby=false, $limit=false,
+ $exclude=false)
+ {
$dbh = &$this->_dbh;
extract($this->_table_names);
$orderby = $this->sortby($sortby, 'db');
if ($orderby) $orderby = ' ORDER BY ' . $orderby;
+ //else " ORDER BY rank($field, to_tsquery('$searchon')) DESC";
$searchclass = get_class($this)."_search";
@@ -688,5 +702,7 @@ extends WikiDB_backend
}
- return new WikiDB_backend_PearDB_iter($this, $result);
+ $iter = new WikiDB_backend_PearDB_iter($this, $result);
+ $iter->stoplisted = @$searchobj->stoplisted;
+ return $iter;
}
@@ -877,5 +893,5 @@ extends WikiDB_backend
* Rename page in the database.
*/
- function rename_page($pagename, $to) {
+ function rename_page ($pagename, $to) {
$dbh = &$this->_dbh;
extract($this->_table_names);
@@ -1211,39 +1227,18 @@ extends WikiDB_backend_PearDB_generic_it
}
-// word search
-class WikiDB_backend_PearDB_search
-extends WikiDB_backend_search
+class WikiDB_backend_PearDB_search extends WikiDB_backend_search_sql
{
- function WikiDB_backend_PearDB_search(&$search, &$dbh) {
- $this->_dbh = $dbh;
- $this->_case_exact = $search->_case_exact;
- $this->_stoplist =& $search->_stoplist;
- }
- function _pagename_match_clause($node) {
- $word = $node->sql();
- if ($word == '%')
- return "1=1";
- else
- return ($this->_case_exact
- ? "pagename LIKE '$word'"
- : "LOWER(pagename) LIKE '$word'");
- }
- function _fulltext_match_clause($node) {
- $word = $node->sql();
- if ($word == '%')
- return "1=1";
- // eliminate stoplist words
- if (preg_match("/^%".$this->_stoplist."%/i", $word)
- or preg_match("/^".$this->_stoplist."$/i", $word))
- return $this->_pagename_match_clause($node);
- else
- return $this->_pagename_match_clause($node)
- // probably convert this MATCH AGAINST or SUBSTR/POSITION without wildcards
- . ($this->_case_exact ? " OR content LIKE '$word'"
- : " OR LOWER(content) LIKE '$word'");
- }
+ // no surrounding quotes because we know it's a string
+ // function _quote($word) { return $this->_dbh->addq($word); }
}
// $Log$
+// Revision 1.94 2005/11/14 22:24:33 rurban
+// fix fulltext search,
+// Eliminate stoplist words,
+// don't extract %pagedate twice in ADODB,
+// add SemanticWeb support: link(relation),
+// major postgresql update: stored procedures, tsearch2 for fulltext
+//
// Revision 1.93 2005/10/10 19:42:15 rurban
// fix wanted_pages SQL syntax
Index: PearDB_oci8.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/WikiDB/backend/PearDB_oci8.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -2 -b -p -d -r1.8 -r1.9
--- PearDB_oci8.php 18 Jan 2005 20:55:48 -0000 1.8
+++ PearDB_oci8.php 14 Nov 2005 22:24:33 -0000 1.9
@@ -74,6 +74,8 @@ extends WikiDB_backend_PearDB_search
// Note that this does only an exact fulltext search, not using MATCH or LIKE.
function _fulltext_match_clause($node) {
- $page = $node->sql($word);
- $exactword = $node->_sql_quote();
+ if ($this->isStoplisted($node))
+ return "1=1";
+ $page = $node->sql();
+ $exactword = $node->_sql_quote($node->word);
return ($this->_case_exact
? "pagename LIKE '$page' OR DBMS_LOB.INSTR(content, '$exactword') > 0"
Index: PearDB_pgsql.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/WikiDB/backend/PearDB_pgsql.php,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -2 -b -p -d -r1.19 -r1.20
--- PearDB_pgsql.php 10 Oct 2005 19:42:15 -0000 1.19
+++ PearDB_pgsql.php 14 Nov 2005 22:24:33 -0000 1.20
@@ -6,13 +6,13 @@ require_once('lib/WikiDB/backend/PearDB.
if (!defined("USE_BYTEA")) // see schemas/psql-initialize.sql
- define("USE_BYTEA", true);
+ define("USE_BYTEA", false);
//define("USE_BYTEA", false);
-/*
- * Since 1.3.12 changed to use Foreign Keys and ON DELETE CASCADE
- */
/*
- * Since 1.3.12 changed to use Foreign Keys and ON DELETE CASCADE
- */
+Since 1.3.12 changed to use:
+ * Foreign Keys
+ * ON DELETE CASCADE
+ * tsearch2
+*/
class WikiDB_backend_PearDB_pgsql
@@ -100,4 +100,65 @@ extends WikiDB_backend_PearDB
/**
+ * Create a new revision of a page.
+ */
+ function set_versiondata($pagename, $version, $data) {
+ $dbh = &$this->_dbh;
+ $version_tbl = $this->_table_names['version_tbl'];
+
+ $minor_edit = (int) !empty($data['is_minor_edit']);
+ unset($data['is_minor_edit']);
+
+ $mtime = (int)$data['mtime'];
+ unset($data['mtime']);
+ assert(!empty($mtime));
+
+ @$content = (string) $data['%content'];
+ unset($data['%content']);
+ unset($data['%pagedata']);
+
+ $id = $this->_get_pageid($pagename, true);
+ $dbh->query(sprintf("SELECT set_versiondata (%d, %d, %d; %d, '%s'::text, '%s'::text)",
+ $id, $version, $mtime, $minor_edit,
+ $this->_quote($content),
+ $this->_serialize($data)));
+ }
+
+ /**
+ * Delete an old revision of a page.
+ */
+ function delete_versiondata($pagename, $version) {
+ $dbh = &$this->_dbh;
+ $dbh->query(sprintf("SELECT delete_versiondata (%d, %d)", $id, $version));
+ }
+
+ /**
+ * Rename page in the database.
+ */
+ function rename_page ($pagename, $to) {
+ $dbh = &$this->_dbh;
+ extract($this->_table_names);
+
+ $this->lock();
+ if (($id = $this->_get_pageid($pagename, false)) ) {
+ if ($new = $this->_get_pageid($to, false)) {
+ // Cludge Alert!
+ // This page does not exist (already verified before), but exists in the page table.
+ // So we delete this page.
+ $dbh->query("DELETE FROM $page_tbl WHERE id=$new");
+ $dbh->query("DELETE FROM $version_tbl WHERE id=$new");
+ $dbh->query("DELETE FROM $recent_tbl WHERE id=$new");
+ $dbh->query("DELETE FROM $nonempty_tbl WHERE id=$new");
+ // We have to fix all referring tables to the old id
+ $dbh->query("UPDATE $link_tbl SET linkfrom=$id WHERE linkfrom=$new");
+ $dbh->query("UPDATE $link_tbl SET linkto=$id WHERE linkto=$new");
+ }
+ $dbh->query(sprintf("UPDATE $page_tbl SET pagename='%s' WHERE id=$id",
+ $dbh->escapeSimple($to)));
+ }
+ $this->unlock();
+ return $id;
+ }
+
+ /**
* Lock all tables we might use.
*/
@@ -135,4 +196,61 @@ extends WikiDB_backend_PearDB
return unserialize($this->_unquote($data));
}
+
+ /**
+ * Title search.
+ */
+ function text_search($search, $fulltext=false, $sortby=false, $limit=false,
+ $exclude=false)
+ {
+ $dbh = &$this->_dbh;
+ extract($this->_table_names);
+ $orderby = $this->sortby($sortby, 'db');
+ if ($sortby and $orderby) $orderby = ' ORDER BY ' . $orderby;
+
+ $searchclass = get_class($this)."_search";
+ // no need to define it everywhere and then fallback. memory!
+ if (!class_exists($searchclass))
+ $searchclass = "WikiDB_backend_PearDB_search";
+ $searchobj = new $searchclass($search, $dbh);
+
+ $table = "$nonempty_tbl, $page_tbl";
+ $join_clause = "$nonempty_tbl.id=$page_tbl.id";
+ $fields = $this->page_tbl_fields;
+
+ if ($fulltext) {
+ $table .= ", $recent_tbl";
+ $join_clause .= " AND $page_tbl.id=$recent_tbl.id";
+
+ $table .= ", $version_tbl";
+ $join_clause .= " AND $page_tbl.id=$version_tbl.id AND latestversion=version";
+
+ $fields .= ", $page_tbl.pagedata as pagedata, " . $this->version_tbl_fields;
+ $callback = new WikiMethodCb($searchobj, "_fulltext_match_clause");
+ $search_string = $search->makeTsearch2SqlClauseObj($callback);
+ $search_string = str_replace(array("%"," "), array("","&"), $search_string);
+ $search_clause = "idxFTI @@ to_tsquery('$search_string')";
+ if (!$orderby)
+ $orderby = " ORDER BY rank(idxFTI, to_tsquery('$search_string')) DESC";
+ } else {
+ $callback = new WikiMethodCb($searchobj, "_pagename_match_clause");
+ $search_clause = $search->makeSqlClauseObj($callback);
+ }
+
+ $sql = "SELECT $fields FROM $table"
+ . " WHERE $join_clause"
+ . " AND ($search_clause)"
+ . $orderby;
+ if ($limit) {
+ list($from, $count) = $this->limit($limit);
+ $result = $dbh->limitQuery($sql, $from, $count);
+ } else {
+ $result = $dbh->query($sql);
+ }
+
+ $iter = new WikiDB_backend_PearDB_iter($this, $result);
+ $iter->stoplisted = @$searchobj->stoplisted;
+ return $iter;
+ }
+
};
@@ -153,6 +271,43 @@ extends WikiDB_backend_PearDB_search
}
- // TODO: use tsearch2. For now the same as parent
- //function _fulltext_match_clause($node)
+ /*
+ most used words:
+select * from stat('select idxfti from version') order by ndoc desc, nentry desc, word limit 10;
+ word | ndoc | nentry
+-----------------+------+--------
+ plugin | 112 | 418
+ page | 85 | 446
+ phpwikidocument | 62 | 62
+ use | 48 | 169
+ help | 46 | 96
+ wiki | 44 | 102
+ name | 43 | 131
+ phpwiki | 42 | 173
+ see | 42 | 69
+ default | 39 | 124
+ */
+
+ /**
+ * use tsearch2. See schemas/psql-tsearch2.sql and /usr/share/postgresql/contrib/tsearch2.sql
+ * TODO: don't parse the words into nodes. rather replace "[ +]" with & and "-" with "!" and " or " with "|"
+ * tsearch2 query language: @@ "word | word", "word & word", ! word
+ * ~* '.*something that does not exist.*'
+ */
+ /*
+ phrase search for "history lesson":
+
+ SELECT id FROM tab WHERE ts_idx_col @@ to_tsquery('history&lesson')
+ AND text_col ~* '.*history\\s+lesson.*';
+
+ The full-text index will still be used, and the regex will be used to
+ prune the results afterwards.
+ */
+ function _fulltext_match_clause($node) {
+ $word = strtolower($node->word);
+ $word = str_replace(" ", "&", $word); // phrase fix
+ return $word;
+
+ return $this->_pagename_match_clause($node) . " OR idxFTI @@ to_tsquery('$word')";
+ }
}
Index: cvs.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/WikiDB/backend/cvs.php,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -2 -b -p -d -r1.25 -r1.26
--- cvs.php 11 Sep 2005 13:23:21 -0000 1.25
+++ cvs.php 14 Nov 2005 22:24:33 -0000 1.26
@@ -414,11 +414,13 @@ extends WikiDB_backend
}
- function text_search($search = '', $fullsearch = false, $orderby=false, $limit=false, $exclude=false)
+ function text_search($search, $fullsearch = false, $orderby=false, $limit=false, $exclude=false)
{
if ( $fullsearch ) {
- return new Cvs_Backend_Full_Search_Iterator(
+ $iter = new Cvs_Backend_Full_Search_Iterator(
$this->_getAllFileNamesInDir( $this->_docDir ),
$search,
$this->_docDir );
+ $iter->stoplisted =& $search->stoplisted;
+ return $iter;
} else {
return new Cvs_Backend_Title_Search_Iterator(
|