Controlling an .Asp Search

This section shows how to control .asp searches. 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. The section marked in bold contains many of the elements in 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")
Defines the .asp query object, and defines the util object. The rest of the commands in this group can then refer to these objects.

Q.Query = SearchString
Sets the scope to search all virtual directories on the server.

Q.SortBy = "rank[d]"
Sorts the results of searches in descending order.

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, Index Server searches documents in the directory Myfiles and all its subdirectories ("deep").

© 1997 by Microsoft Corporation. All rights reserved.