Australian Government, 2006–07 Budget

<% '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Search Configuration '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Const SITE_FOLDER = "www.budget.gov.au" 'Const DEFAULT_PAGE_SIZE = 10 'Const MAX_PAGE_SIZE = 999 ' the default directory to search Const DEFAULT_SCOPE = "/2006-07/" ' Turn debug mode on for this page only Dim debugModeOn debugModeOn = false ' the maximum number of records to return in a search Const MAX_RECORDS_RETURNED = 300 ' Error constants Const OBJECT_REQUIRED_ERROR = 424 Const IGNORED_SEARCH_STRING_ERROR = -2147215867 Const OPERATOR_SEARCH_ERROR = -2147467259 Const INVALID_SEARCH_STRING_ERROR = -2147221505 ' display a search form with the results? Const DISPLAY_SEARCH_FORM = True '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' search Public sub search %>

Search results

<% On Error Resume Next ' the number of results page to display Dim page ' the text to search for Dim searchString ' was the search submitted? Dim searchIsSubmitted ' index server objects Dim Q, util ' the returns recordset Dim searchResults ' the scope of the search Dim scope Dim k ' properties of the current result Dim resultExtension Dim isValid, validationMessage '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' searchIsSubmitted = Request("submit") <> "" 'writeDebug "Submitted? " & searchIsSubmitted ' display search form If DISPLAY_SEARCH_FORM Then displaySearchForm End If If searchIsSubmitted Then ' validate search String ' get search string searchString = Request("search-string") writeDebug "Search string = " & searchString isValid = searchStringIsValid (Trim (Request("search-string")), validationMessage) writeDebug "Search string valid? " & isValid End If If searchIsSubmitted Then writeDebug "Search is submitted" If isValid Then ' get page number page = CInt (Request("page")) If page <= 0 Then page = 1 End If 'writeDebug "Page = " & page ' create query objects Set Q = Server.CreateObject ("ixsso.Query") Set util = Server.CreateObject ("ixsso.Util") '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' set query Parameters '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' initQueryObject Q, util ' add criteria for files returned Q.Query = "({prop name=DocTitle}" & searchString & "{/prop} " & _ "| {prop name=contents}" & searchString & "{/prop} " & _ "| {prop name=DC.Description}" & searchString & "{/prop} " & _ "| {prop name=DC.Subject}" & searchString & "{/prop} " & _ "| {prop name=DocKeywords}" & searchString & "{/prop}) " & _ "& {prop name=filename}{regex} *.htm {/regex}{/prop} " 'debugModeOn = True writeDebug Q.Query debugModeOn = False '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' get Recordset Set searchResults = Q.CreateRecordSet ("nonsequential") 'writeDebug "Error number after creating recordset = " & Err.number 'Response.Write "

Record count = " & searchResults.Recordcount & "

" If searchResults.Recordcount = 0 Then 'Response.Write "

Using backup query

" initQueryObject Q, util Q.Query = "(" & searchString & ") " & _ "AND #filename *.htm " & _ "AND NOT #path *\_* " & _ "AND NOT #filename *search.asp* " & _ "AND NOT #filename *robots.txt* " & _ "AND NOT #filename *copyright.asp* " & _ "AND NOT #filename *privacy.asp* " & _ "AND NOT #filename *disclaimer.asp* " & _ "AND #path *" & Server.MapPath (DEFAULT_SCOPE) & "\*" Set searchResults = Q.CreateRecordSet ("nonsequential") end if If Err.number = 0 Then If searchResults.Recordcount > 0 Then ' show number of results writeDebug "Absolute page = " & searchResults.AbsolutePage writeDebug "Page = " & page writeDebug "Page size = " & searchResults.PageSize if searchResults.Pagecount = 1 then response.Write ("

Showing all " & searchResults.RecordCount & " documents matching " & searchString & ".

") elseIf page = searchResults.Pagecount Then response.Write ("

Showing " & (page * searchResults.Pagesize) - (searchResults.Pagesize - 1) & _ " - " & searchResults.RecordCount & " of " & searchResults.RecordCount & " documents matching " & searchString & ".

") Else response.Write ("

Showing " & (page * searchResults.Pagesize) - (searchResults.Pagesize - 1) & _ " - " & page * searchResults.Pagesize & " of " & searchResults.RecordCount & " documents matching " & searchString & ".

") End If if searchResults.PageCount > 1 then Response.Write "

Tips to improve your searching.

" end if ' print results k = 0 searchResults.AbsolutePage = page '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' insert HTML prior to results ie., start table tags '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %>
<% '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' While Not searchResults.EOF And k < searchResults.PageSize And Err.number = 0 k = k + 1 resultExtension = LCase (Right (searchResults ("path"), Len (searchResults ("path")) - InStrRev (searchResults ("path"), "."))) If resultExtension = "rtf" Then displayRTF (searchResults) ElseIf resultExtension = "asp" Or resultExtension = "html" or resultExtension = "htm" Then displayHTML (searchResults) 'Response.Write "
Rank: " & searchResults("rank") & "
" ElseIf resultExtension = "pdf" Then displayPDF (searchResults) End If searchResults.MoveNext Wend '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' insert HTML after results ie., end table tags '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %>
<% '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' print result navigation Call writeRecordNavigation (searchString, page, searchResults) Else ' display 0 results message Response.Write "

No documents found matching " & searchString & ".

" End If End If Else Err.raise INVALID_SEARCH_STRING_ERROR, "Form validator", "Search string is invalid" End If End If ' catch any unhandled errors If Err.number <> 0 Then 'writeDebug "Error number = " & Err.number Select Case Err.number Case IGNORED_SEARCH_STRING_ERROR Response.Write "

The keywords you entered are all very common terms and are not useful for searching. Please enter a more detailed search.

" Case OPERATOR_SEARCH_ERROR Response.Write "

It looks like you have tried to enter a boolean search, but the format is not correct. Please enter keywords on both sides of ‘and’ or ‘or’ operators.

" Case INVALID_SEARCH_STRING_ERROR Response.Write "

" & validationMessage & "

" Case Else Response.Write "

A software error has occurred." & validationMessage & "

" 'Response.Write "

Error number " & Err.number & " occurred: " & Err.Description & "

" 'Response.Write "

Please report this error with the above details to the webmaster.

" End Select End If end sub Function translatedPath (ByVal path, ByVal siteRoot) ' returns a virtual path derived from path and siteRoot writedebug path translatedPath = Replace (path, "\", "/") if InStr(1, translatedPath, siteRoot) <> -1 Then translatedPath = Right (translatedPath, Len (translatedPath) - Len (siteRoot) - InStr (translatedPath, siteRoot) + 1) ' else 'translatedPath = end if 'writeDebug translatedpath End Function Function translatedTitle (ByVal atitle, ByVal path) ' passes title straight through translatedTitle = Trim (atitle) ' writeDebug translatedTitle ' writeDebug "Length of title = " & Len(atitle) If translatedTitle = "" or IsNull (translatedTitle) Then translatedTitle = "Untitled Document" else translatedTitle = Server.HTMLEncode (translatedTitle) End If End Function Function translatedSummary (ByVal summary) ' removes last word of summary so that any partial words are ' removed. translatedSummary = summary If translatedSummary <> "" Then translatedSummary = Server.HTMLENcode (Left (translatedSummary, InStrRev(translatedSummary, " ") - 1)) & " …" End If End Function Function translatedSize (ByVal bytes) ' at 1/2MB show size in MB rather than KB Const CONVERSION_LIMIT = 524288 If bytes >= CONVERSION_LIMIT Then ' convert to MB translatedSize = CStr (FormatNumber (bytes / 1048576, 2)) & "MB" Else ' convert to KB translatedSize = CStr (FormatNumber (bytes / 1024, 0)) & "KB" End If End Function Function searchStringIsValid (ByVal searchString, ByRef validationMessage) Dim objRegExp ' doesn't include single quotes 'Const VALID_CHARACTERS = "^[\w-\s""]*$" ' includes double and single quotes Const VALID_CHARACTERS = "^[\w-\s""']*$" ' check for double quotes. This one prevents spaces immediately ' inside the double quotes 'Const QUOTED_PHRASE = "^[^""]*""[^""\s][^""]*[^\s""]""[^""]*$" ' This one allows spaces immediately inside the double quotes Const QUOTED_PHRASE = "^[^""']*[""'][^""]+[""'][^""']*$" ' check for double quotes Dim searchPatterns Const MAX_LENGTH = 100 ' assume search string is valid searchStringIsValid = True If Len (searchString) = 0 Then searchStringIsValid = False validationMessage = "It looks like you have accidentally submitted the search form without entering any keywords. Please add keywords." Exit Function End If ' check length If Len (searchString) > MAX_LENGTH Then searchStringIsValid = False validationMessage = "Please enter a shorter search. The search must be shorter than " & CStr (MAX_LENGTH) & " characters." Exit Function End If ' check field data Set objRegExp = New RegExp objRegExp.ignoreCase = True ' Check only allowed characters are used objRegExp.pattern = VALID_CHARACTERS If Not objRegExp.Test (searchString) Then searchStringIsValid = False validationMessage = "Some characters are not allowed in the keywords. Please review the keywords to ensure that they contain only the characters A-Z, 0-9, double quotes, spaces, and hyphens only." Set objRegExp = nothing Exit Function End If ' Check quotes are used correctly If InStr (searchString, """") Then objRegExp.pattern = QUOTED_PHRASE If Not objRegExp.Test (searchString) Then searchStringIsValid = False validationMessage = "It looks like you have tried to search for a phrase but the format of the keywords is incorrect. Please review the keywords to ensure they contain:" & vbCrLf & _ "
    " & _ "
  • only one quoted phrase;
  • " & _ "
  • a pair of quotes, a beginning and an end quotes.
  • " & _ "
  • there are terms between the quotes;
  • " & _ "
" Set objRegExp = nothing Exit Function End If End If End Function Sub writeRecordNavigation (ByVal searchString, ByVal pageNumber, ByRef recordSet) ' prints HTML for the navigating the results of the search ' Response.Write (Recordset.pagecount & "
") ' Response.Write (pagenumber & "
") Dim searchFileName searchFileName = Request.ServerVariables ("SCRIPT_NAME") searchString = Server.URLEncode (searchString) If Recordset.pagecount > 1 Then %>

<% If CInt (pageNumber) > 1 Then %> First page | Previous page <% End If If CInt (pageNumber) > 1 And CInt (pageNumber) < CInt (recordSet.PageCount) Then %> | <% End If If CInt (pageNumber) < CInt (recordSet.PageCount) Then %> Next page <% End If %>

<% End If End Sub Sub displaySearchForm () %>
">

" />

<% End Sub Sub displayRTF (ByRef searchResults) Dim resultPath, resultTitle, resultSummary, resultSize ' get document path resultPath = translatedPath (searchResults ("path"), SITE_FOLDER) ' get document title resultTitle = translatedTitle (searchResults ("DocTitle"), resultPath) ' get summary resultSummary = translatedSummary (searchResults ("characterization")) ' get size resultSize = translatedSize (CDbl (searchResults ("size"))) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Insert HTML for the body of each result '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %>
<%=resultTitle%> (<%=resultSize%> RTF)
<%=resultSummary%>
<% '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' End Sub Sub displayPDF (ByRef searchResults) Dim resultPath, resultTitle, resultSummary, resultSize ' get document path resultPath = translatedPath (searchResults ("path"), SITE_FOLDER) ' get document title resultTitle = translatedTitle (searchResults ("DocTitle"), resultPath) ' get summary resultSummary = translatedSummary (searchResults ("characterization")) ' get size resultSize = translatedSize (CDbl (searchResults ("size"))) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Insert HTML for the body of each result '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %>
<%=resultTitle%> (<%=resultSize%> PDF)
<%=resultSummary%>
<% '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' End Sub Sub displayHTML (ByRef searchResults) Dim resultPath, resultCategory, resultTitle, resultSummary ' get document path resultPath = translatedPath (searchResults ("path"), SITE_FOLDER) ' get document title resultTitle = translatedTitle (searchResults ("DocTitle"), resultPath) 'resultTitle = Left (searchResults ("filename"), InStr(searchResults ("filename"), ".") - 1) ' get summary 'response.write "summary = " & searchResults ("characterization") & "
" resultSummary = "" resultSummary = translatedSummary (searchResults("characterization")) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Insert HTML for the body of each result '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'if InStr (resultTitle, "—") > 0 then ' resultCategory = GetPageCategory (resultTitle) ' resultTitle = Mid (resultTitle, InStrRev (resultTitle, "—") + 8) 'end if %>
<%=resultTitle %>
<%=resultSummary%>
<% 'if resultCategory <> "" then %> <% 'end if %> <% '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' End Sub Function GetPageCategory (ByVal title) ' As String 'writeDebug InStrRev (title, "—") GetPageCategory = Trim (Left (title, InStrRev (title, "—") - 1)) end Function Public Sub writeDebug (ByVal message) If debugModeOn Then Response.Write "

" & _ message & "

" & vbCrLf End If End Sub Public Sub initQueryObject (ByRef q, ByRef util) With q .Reset .SortBy = "rank[d], hitcount[d]" ' Filename is just an extra param for fixing out-of-scope bug ' Add AGLS metadata elements to query .DefineColumn """DC.Description""(DBTYPE_WSTR | DBTYPE_BYREF) = d1b5d3f0-c0b3-11cf-9a92-00a0c908dbf1 dc.description" .DefineColumn """DC.Subject""(DBTYPE_WSTR | DBTYPE_BYREF) = d1b5d3f0-c0b3-11cf-9a92-00a0c908dbf1 dc.subject" ' fields to return .Columns = "DocTitle, Create, path, filename, size, write, characterization, rank" ' number of records to return .MaxRecords = MAX_RECORDS_RETURNED ' modify scope scope = DEFAULT_SCOPE util.AddScopeToQuery Q, Server.MapPath (scope), "deep" 'writeDebug Server.MapPath(scope) end With End Sub %>

Miscellaneous