From d031ba7226e2aff521eaa046b7dd551f073db294 Mon Sep 17 00:00:00 2001 From: rurban Date: Thu, 17 Sep 2009 08:44:13 +0000 Subject: [PATCH] new titleSearch option 16 for fallback if not found git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@7137 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/XmlRpcServer.php | 15 +++++++++++++-- themes/default/templates/search.tmpl | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/XmlRpcServer.php b/lib/XmlRpcServer.php index 585603243..471404eef 100644 --- a/lib/XmlRpcServer.php +++ b/lib/XmlRpcServer.php @@ -636,7 +636,7 @@ function mailPasswordToUser($params) $wiki_dmap['titleSearch'] = array('signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString)), 'documentation' => "Return matching pagenames. -Option 1: caseexact, 2: regex, 4: starts_with, 8: exact", +Option 1: caseexact, 2: regex, 4: starts_with, 8: exact, 16: fallback", 'function' => 'titleSearch'); function titleSearch($params) @@ -653,6 +653,7 @@ function titleSearch($params) $case_exact = $option & 1; $regex = $option & 2; + $fallback = $option & 16; if (!$regex) { if ($option & 4) { // STARTS_WITH $regex = true; @@ -675,7 +676,17 @@ function titleSearch($params) $pages = array(); while ($page = $iterator->next()) { $pages[] = short_string($page->getName()); - } + } + // On failure try again broader (substring + case inexact) + if ($fallback and empty($pages)) { + $query = new TextSearchQuery(short_string_decode($ParamPageName->scalarval()), false, + $regex ? 'auto' : 'none'); + $dbh = $request->getDbh(); + $iterator = $dbh->titleSearch($query); + while ($page = $iterator->next()) { + $pages[] = short_string($page->getName()); + } + } return new xmlrpcresp(new xmlrpcval($pages, "array")); } diff --git a/themes/default/templates/search.tmpl b/themes/default/templates/search.tmpl index 6d394f527..e2e09c3d6 100644 --- a/themes/default/templates/search.tmpl +++ b/themes/default/templates/search.tmpl @@ -20,7 +20,7 @@ if (! USE_PATH_INFO) { ?> class="dropdown" id="searchInput" title="" style="width:115px;" acdropdown="true" autocomplete_complete="false" autocomplete_matchsubstring="false" - autocomplete_list="xmlrpc:wiki.titleSearch [S] 4getArg("start_debug") ? " debug" : "" ?>" /> + autocomplete_list="xmlrpc:wiki.titleSearch [S] 20getArg("start_debug") ? " debug" : "" ?>" /> type="text" id="livesearch" title="" onKeypress="liveSearchStart()" -- 2.45.0