function _find($h, $words = '', $offset = 0, $maxRecords = -1, $fulltext = false) { $words = trim($words); $sql = sprintf( 'SELECT %s AS name, LEFT(%s, 240) AS data, %s AS hits, %s AS lastModif, %s AS pageName', $h['name'], $h['data'], $h['hits'], $h['lastModif'], $h['pageName']); $id = $h['id']; for ($i = 0; $i < count($id); ++$i) $sql .= ',' . $id[$i] . ' AS id' . ($i + 1); if (count($id) < 2) $sql .= ',1 AS id2'; $sql2 = ' FROM ' . $h['from'] . ' WHERE '; $sql2 .= (isset($h['filter']))? $h['filter'] : '1'; $orderby = (isset($h['orderby']) ? $h['orderby'] : $h['hits']); if ($fulltext) { $qwords = $this->db->quote($words); $sqlft = 'MATCH(' . join(',', $h['search']). ') AGAINST (' . $qwords . ' IN BOOLEAN MODE)'; $sql2 .= ' AND ' . $sqlft ; $sql .= ', ' . $sqlft . ' AS relevance'; $orderby = 'relevance desc, ' . $orderby; } else if ($words) { $sql .= ', -1 AS relevance'; $vwords = split(' ',$words); foreach ($vwords as $aword) { //$aword = $this->db->quote('[[:<:]]' . strtoupper($aword) . '[[:>:]]'); $aword = $this->db->quote('.*'.strtoupper($aword).'.*'); $sql2 .= ' AND ('; for ($i = 0; $i < count($h['search']); ++$i) { if ($i) $sql2 .= ' OR '; $sql2 .= 'UPPER(' . $h['search'][$i] . ') REGEXP ' . $aword; } $sql2 .= ')'; } } else { $sql .= ', -1 AS relevance'; } $cant = $this->getOne('SELECT COUNT(*)' . $sql2); //if (!$cant) { // no result // if ($fulltext && $words) // try a simple search // return $this->_find($h, $words, $offset, $maxRecords, false); // else // return array( // 'data' => array(), // 'cant' => 0 // ); //} //note: above cant block causes following error in MySQL 4.0.15 boolean search //*************************************************************** //Warning: mysql error: Got error 'repetition-operator operand invalid' from regexp in query: //SELECT COUNT(*) FROM tiki_comments c, tiki_pages p WHERE c.objectType = "wiki page" AND p.pageName=c.object AND (UPPER(c.title) REGEXP '.*+LISTENING.*' OR UPPER(c.data) REGEXP '.*+LISTENING.*') AND (UPPER(c.title) REGEXP '.*+PAGE.*' OR UPPER(c.data) REGEXP '.*+PAGE.*') //in c:\program files\easyphp1-7\www\tw\lib\tikidblib.php on line 125 //Values: //$result is false //$result is empty //***************************************************************** $sql .= $sql2 . ' ORDER BY ' . $orderby . ' DESC LIMIT ' . $offset . ',' . $maxRecords; $result = $this->query($sql); $ret = array(); while ($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { $href = sprintf(urldecode($h['href']), $res['id1'], $res['id2']); $ret[] = array( 'pageName' => $res["pageName"], 'data' => $res["data"], 'hits' => $res["hits"], 'lastModif' => $res["lastModif"], 'href' => $href, 'relevance' => round($res["relevance"], 3), ); } return array( 'data' => $ret, 'cant' => $cant ); }