Skip to content

Commit

Permalink
Only search at begin of titles to find sub-pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Mar 2, 2015
1 parent b60f9fa commit 31a0ed0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion wicked/lib/Driver.php
Expand Up @@ -353,7 +353,7 @@ public function removeAllVersions($pagename)
$this->removeAllAttachments($this->getPageId($pagename));
}

abstract function searchTitles($searchtext);
abstract function searchTitles($searchtext, $begin = false);

/**
* Returns the charset used by the backend.
Expand Down
19 changes: 17 additions & 2 deletions wicked/lib/Driver/Sql.php
Expand Up @@ -199,11 +199,26 @@ public function leastPopular($limit = 10)
'page_hits ASC', $limit);
}

public function searchTitles($searchtext)
/**
* Finds pages with matches in the title.
*
* @param string $searchtext The search expression (Google-like).
* @param boolean $begin Search only at the begin of the titles?
*
* @return array A list of pages.
* @throws Wicked_Exception
*/
public function searchTitles($searchtext, $begin = false)
{
$searchtext = $this->_convertToDriver($searchtext);
try {
$where = $this->_db->buildClause('page_name', 'LIKE', $searchtext);
$where = $this->_db->buildClause(
'page_name',
'LIKE',
$searchtext,
false,
array('begin' => $begin)
);
} catch (Horde_Db_Exception $e) {
throw new Wicked_Exception($e);
}
Expand Down
20 changes: 12 additions & 8 deletions wicked/lib/View/Helper/Navigation.php
Expand Up @@ -70,7 +70,10 @@ public function navigation($name)
return '';
}

$siblings = $wicked->searchTitles(substr($name, 0, strrpos($name, '/') + 1));
$siblings = $wicked->searchTitles(
substr($name, 0, strrpos($name, '/') + 1),
true
);
usort(
$siblings,
function($a, $b) {
Expand Down Expand Up @@ -138,14 +141,9 @@ public function hasSubPages($name)
*/
public function subPages($name)
{
$slashes = substr_count($name, '/') + 1;
$pages = $this->_getSubPages($name);
$children = array();
foreach ($pages as $page) {
foreach ($this->_getSubPages($name) as $page) {
$name = $page['page_name'];
if (substr_count($name, '/') != $slashes) {
continue;
}
$children[$name] = '<li>' . Wicked::url($name)->link()
. $this->h($name) . '</a></li>';
}
Expand All @@ -168,7 +166,13 @@ protected function _getSubPages($name)
global $wicked;

if (!isset($this->_subPages)) {
$this->_subPages = $wicked->searchTitles($name . '/');
$slashes = substr_count($name, '/') + 1;
$this->_subPages = array();
foreach ($wicked->searchTitles($name . '/', true) as $page) {
if (substr_count($page['page_name'], '/') == $slashes) {
$this->_subPages[] = $page;
}
}
}

return $this->_subPages;
Expand Down

0 comments on commit 31a0ed0

Please sign in to comment.