Controlling an Active Server Pages Search
Note
Indexing Service is no longer supported as of Windows XP and is unavailable for use as of Windows 8. Instead, use Windows Search for client side search and Microsoft Search Server Express for server side search.
This section shows how to control searches with an ASP page. The code displayed here is equivalent in function to an .idq file.
<BR>
<%
if SearchString <> "" then
if NewQuery then
set Session("Query") = nothing
set Session("Recordset") = nothing
NextRecordNumber = 1
set Q = Server.CreateObject("ixsso.Query")
set util = Server.CreateObject("ixsso.util")
Q.Query = SearchString
Q.SortBy = "rank[d]"
Q.Columns = "DocTitle, vpath, path, filename, size, write, characterization"
util.AddScopeToQuery Q, "/Myfiles", "deep"
set RS = Q.CreateRecordSet("nonsequential")
RS.PageSize = 10
ActiveQuery = TRUE
elseif UseSavedQuery then
if IsObject( Session("Query") ) And IsObject( Session("RecordSet") ) then
set Q = Session("Query")
set RS = Session("RecordSet")
if RS.RecordCount <> -1 and NextPageNumber <> -1 then
RS.AbsolutePage = NextPageNumber
NextRecordNumber = RS.AbsolutePosition
end if
ActiveQuery = TRUE
else
Response.Write "ERROR - No saved query"
end if
end if
%>
This section is executed only if the SearchString variable has been set (that is, only if you have typed a query into the form and clicked the New Query button). This section contains many of the same elements as the sample .idq file in Controlling the Search (.Idq File). Notice the differences in syntax.
-
set Q = Server.CreateObject("ixsso.Query") and set util = Server.CreateObject("ixsso.util")
-
These lines define the server-side Query and Utility objects. The rest of the commands in this group can then refer to these objects.
-
Q.Query = SearchString
-
Sets the query string (restriction) used to search all virtual directories on the server.
-
Q.SortBy = "rank[d]"
-
Sorts the results of searches in rank-descending order (highest rank first).
-
Q.Columns = "DocTitle, vpath, path, filename, size, write, characterization"
-
Indicates the kind of information returned in the results.
-
util.AddScopeToQuery Q, "/Myfiles", "deep"
-
Restricts the scope to the listed virtual directories. In this example, Indexing Service searches documents in the directory Myfiles, as well as all its subdirectories ("deep").