%
'
' This application is implemented in the VBScript programming language.
'
' The application searches the SIETS storage using HTTP API and returns the
' results in HTML.
'
%>
<%
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)
%><%= 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, "#", " ") %>
<%
%>
<%= Server.HTMLEncode(Result.SelectSingleNode("id").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 %><%
sLink = " 0 then
%>- <%= sLink & (iPage - 1) %>"><<< Previous
<%= vbCrLf %><%
end if
j = i
do while j < i + nPages and j < nSure
%>- <%
if j = iPage then
%><%= j + 1 %><%
else
%><%= sLink & j %>"><%= j + 1 %><%
end if
%>
<%= vbCrLf %><%
j = j + 1
loop
if nMore > 0 then
%>- <%= sLink & (iPage + 1) %>">Next >>>
<%= vbCrLf %><%
end if
%>
<%= 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
%>