<% ' ' This application is implemented in the VBScript programming language. ' ' The application searches the SIETS storage using HTTP API and returns the ' results in HTML. ' %> Search
<% nDocs = 10 'results per page nPages = 10 'pages listed Offset = Int(Request.QueryString("page")) * nDocs 'pages are numbered from 0, displayed from 1 sQuery = Request.QueryString("query") Set Http = Server.CreateObject("MSXML2.ServerXMLHTTP") Http.Open "POST", "http://127.0.0.1/cgi-bin/siets/api.cgi", False Http.Send "storage=test&command=search&docs=" & nDocs & "&offset=" & Offset & "&relevance=yes&query=" & Server.URLEncode(sQuery) if Http.Status = 200 and not Http.ResponseXML is Nothing then Set Dom = Http.ResponseXML Dom.SetProperty "SelectionNamespaces", "xmlns:s='www.siets.net'" Set Content = Dom.SelectSingleNode("s:reply/s:content") if not Content is Nothing then 'command executed ok n = Int(Content.SelectSingleNode("hits").Text) %>

Found <% if n > 0 then Response.Write n else Response.Write "no" %> document<% if n <> 1 then Response.Write "s" if not Content.SelectSingleNode("real_query") is Nothing then sRealQuery = Content.SelectSingleNode("real_query").Text else sRealQuery = "" %> matching "<%= Server.HTMLEncode(sRealQuery) %>" (<%= Dom.SelectSingleNode("s:reply/s:seconds").Text %> seconds)

<%= vbCrLf %><% if n > 0 then 'something has been found for each Result in Content.SelectNodes("results/document") %>
<% sTitle = Result.SelectSingleNode("title").Text p = InStr(sTitle, ":_:_:") if p > 0 then sTitle = Left(sTitle, p - 1) %>

"><%= Server.HTMLEncode(sTitle) %>

<% %>

<%= Replace(Result.SelectSingleNode("text").Text, "#", " ") %>

<% %><% %>
<%= vbCrLf %><% next 'page listing iFrom = Int(Content.SelectSingleNode("from").Text) nMore = Int(Mid(Content.SelectSingleNode("more").Text, 2)) nSure = Int((nMore + iFrom + 2 * nDocs - 1) / nDocs) if iFrom > 0 or nMore > 0 then %>
<%= vbCrLf %>

Result pages:<%= vbCrLf %><% iPage = Int(iFrom / nDocs) i = Int((iPage - 1) / (nPages - 2)) * (nPages - 2) if i < 0 then i = 0 %>

<%= vbCrLf %>

<%= vbCrLf %>
<%= vbCrLf %><% end if end if else 'error Set Content = Dom.SelectSingleNode("s:reply/s:error") %>

Error <%= Content.SelectSingleNode("code").Text %>: <%= Server.HTMLEncode(Content.SelectSingleNode("text").Text) %>

<%= vbCrLf %><% end if else %>

Search failed!

<%= vbCrLf %><% end if %>