Skip to content

Skip to content

<% On Error Resume Next '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Search Configuration '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' the default directory to search Const DEFAULT_SCOPE = "/2004-05" ' Turn debug mode on for this page only 'Dim debugModeOn 'debugModeOn = True ' 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_ERROR = -2147467259 Const INVALID_SEARCH_STRING_ERROR = -2147221505 ' display a search form with the results? Const DISPLAY_SEARCH_FORM = True Const SITE_FOLDER = "www.budget.gov.au" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' 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 %>

Search

<% ' display search form If DISPLAY_SEARCH_FORM Then displaySearchForm End If If searchIsSubmitted Then ' validate search String ' get search string searchString = Request("searchString") 'writeDebug "Search string = " & searchString isValid = searchStringIsValid (Trim (Request("searchString")), validationMessage) 'writeDebug "Search string valid? " & isValid End If If searchIsSubmitted Then 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 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' add criteria for files returned 'Q.Query = searchString & " " & _ '"AND #filename *.htm" ' "OR #DocTitle " & searchString & _ ' "AND NOT #path *\_* " & _ ' "AND NOT #filename *robots.txt* " Q.Query = searchString & " AND #filename *.htm" '"({weight value=1.0}{prop name=doctitle}{freetext}" & searchString & "{/freetext}{/prop} or " & _ ' "{weight value=0.0009}{prop name=contents}{freetext}" & searchString & "{/freetext}{/prop}) and NOT " & _ ' "{prop name=path}{regex}*\_*{/regex}{/prop}" Q.DefineColumn "dc_description = d1b5d3f0-c0b3-11cf-9a92-00a0c908dbf1 dc.description" Q.SortBy = "rank[d]" ' fields to return Q.Columns = "DocTitle, Create, path, filename, size, write, characterization, rank, dc_description" ' number of records to return Q.MaxRecords = MAX_RECORDS_RETURNED ' modify scope scope = DEFAULT_SCOPE util.AddScopeToQuery Q, Server.MapPath (scope), "deep" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' get Recordset Set searchResults = Q.CreateRecordSet ("nonsequential") 'writeDebug "Error number after creating recordset = " & Err.number 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 page = searchResults.Pagecount Then response.Write ("

Showing Records " & (page * searchResults.Pagesize) - (searchResults.Pagesize - 1) & _ " - " & searchResults.RecordCount & " of " & searchResults.RecordCount & ".

") Else response.Write ("

Showing Records " & (page * searchResults.Pagesize) - (searchResults.Pagesize - 1) & _ " - " & page * searchResults.Pagesize & " of " & searchResults.RecordCount & ".

") End If ' print result navigation Call writeRecordNavigation (searchString, page, searchResults) ' print results k = 0 searchResults.AbsolutePage = page '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' insert HTML prior to results ie., start 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 search string contained only ignored terms. Please enter a more detailed search string.

" Case OPERATOR_ERROR Response.Write "

Please enter search terms on both sides of AND or OR operators.

" Case INVALID_SEARCH_STRING_ERROR Response.Write "

" & validationMessage & "

" Case Else 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 Function translatedPath (ByVal path, ByVal siteRoot) ' returns a virtual path derived from path and siteRoot translatedPath = Replace (path, "\", "/") 'writeDebug "Path = " & translatedPath 'writeDebug "siteRoot = " & siteRoot 'writeDebug InStr (translatedPath, siteRoot) translatedPath = Right (translatedPath, Len (translatedPath) - Len (siteRoot) - InStr (translatedPath, siteRoot) + 1) ' for dev. site 'translatedPath = "/dev.treasury.gov.au" & translatedPath End Function Function translatedTitle (ByVal atitle, ByVal path) ' passes title straight through translatedTitle = Trim (atitle) If translatedTitle = "" Then translatedTitle = "Untitled Document" 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 = 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 Const SEARCH_PATTERN1 = "^[\w-\s""]*$" Const SEARCH_PATTERN2 = "^[^""]*""[^""\s][^""]*[^\s""]""[^""]*$" ' 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 = "Please enter some search terms." 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 objRegExp.pattern = SEARCH_PATTERN1 If Not objRegExp.Test (searchString) Then searchStringIsValid = False validationMessage = "Please enter a search that contains the characters A-Z, 0-9, double quotes, spaces, and hyphens only." Set objRegExp = nothing Exit Function End If If InStr (searchString, """") Then objRegExp.pattern = SEARCH_PATTERN2 If Not objRegExp.Test (searchString) Then searchStringIsValid = False validationMessage = "Please enter search without multiple phrases, phrases with leading or trailing spaces, or double quotes separated by spaces." 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 | Previous <% End If If CInt (pageNumber) > 1 And CInt (pageNumber) < CInt (recordSet.PageCount) Then %> | <% End If If CInt (pageNumber) < CInt (recordSet.PageCount) Then %> Next | Last <% End If %>

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

">

Listed below are the different types of searches you might find useful. These search types may be used individually or in combination.
Phrase Search
Search for complete phrases by enclosing them in quotation marks. Words enclosed in double quotes ("like this") will appear together in all results exactly as you have entered them.
"AND" "OR" Search
The Search facility supports the logical "AND" and "OR" operators. To retrieve content that includes both word A and word B, use an uppercase AND between terms. To retrieve content that includes either word A or word B, use an uppercase OR between terms.
<% 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)
  • <% '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 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)
  • <% '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' End Sub Sub displayHTML (ByRef searchResults) Dim resultPath, 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 resultSummary = translatedSummary (searchResults ("characterization")) 'resultSummary = translatedSummary (searchResults ("dc_description")) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Insert HTML for the body of each result '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' %>
  • <%=resultTitle%>
  • <% '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' End Sub %>

    Skip to top of page