General Actions:
Log-in
Wiki:
L3D's Wiki
▼
:
Document Index
»
Space:
XWiki
▼
:
Document Index
»
Page:
WebSearchCode
Search
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Welcome to your wiki
»
Search
»
WebSearchCode
Wiki source code of
WebSearchCode
Last modified by
Administrator
on 2007/07/15 02:48
Content
·
Comments
(0)
·
Attachments
(0)
·
History
·
Information
Hide line numbers
1: ## ================================================== 2: ## Common code for WebSearch and WebSearchRss 3: ## ================================================== 4: ## Inputs: $text, $space 5: ## Output: $list 6: ## Note: Do not put any empty line or this will break 7: ## the generated RSS feed 8: ## ================================================== 9: #set($datedlist = $util.arrayList) 10: #if(!$text or $text == "") 11: ## No search 12: #else 13: #set($text = $text.replaceAll("'", "''").replaceAll("%", "\\%")) 14: #set($nbitems = 50) 15: ## ----------------------------------------------------------- 16: ## Non-admins should not see results from XWiki, Admin and 17: ## Panels spaces. Also exclude the WebPreferences doc. 18: ## ----------------------------------------------------------- 19: #if ($xwiki.hasAdminRights()) 20: #set ($excludedWebs = "") 21: #else 22: #set ($excludedWebs = "doc.space<>'XWiki' and doc.space<>'Admin' and doc.space<>'Panels' and doc.name<>'WebPreferences' and") 23: #end 24: ## ----------------------------------------------------------- 25: ## Display only a given space if $request.space is defined 26: ## ----------------------------------------------------------- 27: #if($space and $space == "All") 28: #set ($webClause = "$excludedWebs") 29: #else 30: #set ($webClause = "doc.space='$space' and $excludedWebs") 31: #end 32: #macro(addelement $item $list) 33: #if($xwiki.hasAccessLevel("view", $context.user, "${context.database}:${item}")) 34: #set($itemdoc = $xwiki.getDocument($item)) 35: #set($sdate = $xwiki.formatDate($itemdoc.date, "yyyyMMddHHmmss")) 36: #set($sitem = "${sdate}${item}") 37: #if(!$list.contains($sitem)) 38: #set($discard = $list.add($sitem)) 39: #end 40: #end 41: #end 42: ## ----------------------------------------------------------- 43: ## Search in the page names 44: ## ----------------------------------------------------------- 45: #set ($sql = "where $webClause upper(doc.fullName) like upper('%$!text%') order by doc.date desc") 46: #foreach ($item in $xwiki.searchDocuments($sql , $nbitems, 0)) 47: #addelement($item $datedlist) 48: #end 49: ## ----------------------------------------------------------- 50: ## Search in page content 51: ## ----------------------------------------------------------- 52: #set ($sql = "where $webClause upper(doc.content) like upper('%$!text%') order by doc.date desc") 53: #foreach ($item in $xwiki.searchDocuments($sql , $nbitems, 0)) 54: #addelement($item $datedlist) 55: #end 56: ## ----------------------------------------------------------- 57: ## Search in text fields (simple String properties) 58: ## ----------------------------------------------------------- 59: #set($sql= ", BaseObject as obj, StringProperty as prop where $webClause obj.name=doc.fullName and prop.id.id = obj.id and upper(prop.value) like upper('%$!text%')") 60: #foreach ($item in $xwiki.searchDocuments($sql , $nbitems, 0)) 61: #addelement($item $datedlist) 62: #end 63: ## ----------------------------------------------------------- 64: ## Search in big text fields (textarea properties) 65: ## ----------------------------------------------------------- 66: #set($sql= ", BaseObject as obj, LargeStringProperty as prop where $webClause obj.name=doc.fullName and prop.id.id = obj.id and upper(prop.value) like upper('%$!text%')") 67: #foreach ($item in $xwiki.searchDocuments($sql , $nbitems, 0)) 68: #addelement($item $datedlist) 69: #end 70: #end 71: #set($list = $util.arrayList) 72: #foreach($item in $util.sort($datedlist)) 73: #set($ok = $list.add(0, $item.substring(14))) 74: #end
Quick Links
L3D Calendar
Wiki Dashboard
Document Index
Blog
Sandbox