Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to do search function using ASP

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
this is what i have did...the problem is...it is succesful
if i m using personal web server but if i am using
internet server manager i cant


<!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 3.0//EN&quot; &quot;html.dtd&quot;>
<HTML>
<HEAD>

<SCRIPT LANGUAGE=&quot;VBScript&quot; RUNAT=&quot;Server&quot;>
<!--
option explicit
-->
</SCRIPT>

<TITLE>Index Server Search Form</TITLE>

<META NAME=&quot;DESCRIPTION&quot; CONTENT=&quot; ASP query form for
Microsoft Index Server&quot;>
<META NAME=&quot;KEYWORDS&quot; CONTENT=&quot;query, content, hit, asp&quot;>
<META NAME=&quot;MS.LOCALE&quot; CONTENT=&quot;EN-US&quot;>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html;
charset=Windows-1252&quot;>

<%
NewQuery = FALSE
UseSavedQuery = FALSE
QueryForm = Request.ServerVariables( &quot;PATH_INFO&quot; )
SearchString = &quot;&quot;
if Request.ServerVariables(&quot;REQUEST_METHOD&quot;) = &quot;POST&quot; then
SearchString = Request.Form(&quot;SearchString&quot;)
pg = Request.Form(&quot;pg&quot;)

if pg <> &quot;&quot; then
NextPageNumber = pg
NewQuery = FALSE
UseSavedQuery = TRUE
else
NewQuery = SearchString <> &quot;&quot;
end if
end if

%>
</HEAD>
<p>

<TABLE width=&quot;657&quot;>
<TR bgcolor=&quot;#336699&quot; bordercolor=&quot;#333333&quot;>
<TD ALIGN=LEFT width=&quot;649&quot; height=&quot;31&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;-1&quot;><b><font color=&quot;#FFFFFF&quot;>Search
for: </font></b></font></TD>
</TR>
<TR bgcolor=&quot;#336699&quot; bordercolor=&quot;#333333&quot;>
<TD width=&quot;649&quot; height=&quot;8&quot;>
<FORM ACTION='<%= QueryForm%>' METHOD=POST>
<TABLE width=&quot;664&quot;>
<TR>
<TD width=&quot;310&quot;>
<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;SearchString&quot; SIZE=&quot;50&quot;
MAXLENGTH=&quot;100&quot; VALUE='<%=SearchString%>'>
</TD>
<TD width=&quot;170&quot;> <select name=&quot;listdown&quot; size=&quot;1&quot;>
<option value=&quot;1&quot;>Entire Site</option>
<option value=&quot;2&quot;>Home</option>
<option value=&quot;3&quot;>Announcement</option>
<option value=&quot;4&quot;>Bussiness</option>
<option value=&quot;5&quot;>Realtime</option>
<option value=&quot;6&quot;>Talk</option>
<option value=&quot;7&quot;>News</option>
<option value=&quot;8&quot;>Join</option>
<option value=&quot;9&quot;>Members</option>
<option value=&quot;10&quot;>Help</option>
</select>

</TD>
<TD width=&quot;168&quot;>
<%
if SearchString <> &quot;&quot; then
if NewQuery then
set Session(&quot;Query&quot;) = nothing
set Session(&quot;Recordset&quot;) = nothing
NextRecordNumber = 1

Dim Q

set Q = Server.CreateObject(&quot;ixsso.Query&quot;)
set util = Server.CreateObject(&quot;ixsso.util&quot;)
Q.SetQueryFromURL(Request.QueryString)
Q.Query = SearchString
Q.SortBy = &quot;rank[d]&quot;
Q.Columns = &quot;DocTitle, vpath, path, filename, size, write, characterization&quot;

if request(&quot;listdown&quot;) = &quot;1&quot; then
util.AddScopeToQuery Q,&quot;D:\inetpub\
elseif request(&quot;listdown&quot;) = &quot;2&quot; then
util.AddScopeToQuery Q,&quot;D:\inetpub\
elseif request(&quot;listdown&quot;) = &quot;3&quot; then
util.AddScopeToQuery Q,&quot;D:\inetpub\
elseif request(&quot;listdown&quot;) = &quot;4&quot; then
util.AddScopeToQuery Q,&quot;D:\inetpub\
elseif request(&quot;listdown&quot;) = &quot;5&quot; then
util.AddScopeToQuery Q,&quot;D:\inetpub\
elseif request(&quot;listdown&quot;) = &quot;6&quot; then
util.AddScopeToQuery Q,&quot;D:\inetpub\
elseif request(&quot;listdown&quot;) = &quot;7&quot; then
util.AddScopeToQuery Q,&quot;D:\inetpub\
elseif request(&quot;listdown&quot;) = &quot;8&quot; then
util.AddScopeToQuery Q,&quot;D:\inetpub\
elseif request(&quot;listdown&quot;) = &quot;9&quot; then
util.AddScopeToQuery Q,&quot;D:\inetpub\
else set Q = Server.CreateObject(&quot;ixsso.Query&quot;)
util.AddScopeToQuery Q,&quot;D:\inetpub\
end if

set RS = Q.CreateRecordSet(&quot;nonsequential&quot;)

RS.PageSize = 10
ActiveQuery = TRUE

elseif UseSavedQuery then
if IsObject( Session(&quot;Query&quot;) ) And IsObject( Session(&quot;RecordSet&quot;) ) then
set Q = Session(&quot;Query&quot;)
set RS = Session(&quot;RecordSet&quot;)

if RS.RecordCount <> -1 and NextPageNumber <> -1 then
RS.AbsolutePage = NextPageNumber
NextRecordNumber = RS.AbsolutePosition
end if

ActiveQuery = TRUE
else
Response.Write &quot;ERROR - No saved query&quot;
end if
end if
%>
<input type=&quot;SUBMIT&quot; name=&quot;Submit&quot; value=&quot;Search&quot;>
</TABLE>
</FORM>
</TD>
</TR>
</TABLE>

<%
if ActiveQuery then
if not RS.EOF then
%>
<p>
<p>

<%
LastRecordOnPage = NextRecordNumber + RS.PageSize - 1
CurrentPage = RS.AbsolutePage
if RS.RecordCount <> -1 AND RS.RecordCount < LastRecordOnPage then
LastRecordOnPage = RS.RecordCount
end if

Response.Write &quot;Documents &quot; & NextRecordNumber & &quot; to &quot; & LastRecordOnPage
if RS.RecordCount <> -1 then
Response.Write &quot; of &quot; & RS.RecordCount
end if
Response.Write &quot; matching the query &quot; & chr(34) & &quot;<I>&quot;
Response.Write SearchString & &quot;</I>&quot; & chr(34) & &quot;<P>&quot;
%>
<dl>

<!-- BEGIN first row of query results table -->
<% Do While Not RS.EOF and NextRecordNumber <= LastRecordOnPage %>

<%
' This is the detail portion for Title, Abstract, URL, Size, and
' Modification Date.
' If there is a title, display it, otherwise display the virtual path.
%>
<p>
<dt><%= NextRecordNumber%>
<%if VarType(RS(&quot;DocTitle&quot;)) = 1 or RS(&quot;DocTitle&quot;) = &quot;&quot; then%>
<b><a href=&quot;<%=RS(&quot;vpath&quot;)%>&quot;><%= Server.HTMLEncode( RS(&quot;filename&quot;) )%></a></b>
<%else%>
<b><a href=&quot;<%=RS(&quot;vpath&quot;)%>&quot;><%= Server.HTMLEncode(RS(&quot;DocTitle&quot;))%></a></b>
<%end if%>
<dd>
<%if VarType(RS(&quot;characterization&quot;)) = 8 and RS(&quot;characterization&quot;) <> &quot;&quot; then%>
<b><i>Abstract: </I></b><%= Server.HTMLEncode(RS(&quot;characterization&quot;))%>
<br>
<%end if%>
<cite>
<a href=&quot;<%=RS(&quot;vpath&quot;)%>&quot;> <font size=-1> - <%if RS(&quot;size&quot;) = &quot;&quot; then%>(size and time unknown)<%else%>size <%=RS(&quot;size&quot;)%> bytes - <%=RS(&quot;write&quot;)%> GMT<%end if%></font>
</cite>

<%
RS.MoveNext
NextRecordNumber = NextRecordNumber+1
Loop
%>

</dl>


<P><BR>

<%
else ' NOT RS.EOF
if NextRecordNumber = 1 then
Response.Write &quot;No documents matched the query<P>&quot;
else
Response.Write &quot;No more documents in the query<P>&quot;
end if

end if ' NOT RS.EOF
%>


<!--
If the query was not executed because it needed to enumerate to
resolve the query instead of using the index, but AllowEnumeration
was FALSE, let the user know
-->

<%if Q.QueryIncomplete then%>
<P>
<I><B>The query is too expensive to complete.</B></I><BR>
<%end if%>

<!--
If the query took too long to execute (for example, if too much work
was required to resolve the query), let the user know
-->

<%if Q.QueryTimedOut then%>
<P>
<I><B>The query took too long to complete.</B></I><BR>
<%end if%>


<TABLE>

<!--
This is the &quot;previous&quot; button.
This retrieves the previous page of documents for the query.
-->

<%SaveQuery = FALSE%>
<%if CurrentPage > 1 and RS.RecordCount <> -1 then %>
<td align=left>
<form action=&quot;<%= QueryForm%>&quot; method=&quot;POST&quot;>
<INPUT TYPE=&quot;HIDDEN&quot; NAME=&quot;SearchString&quot; VALUE=&quot;<%=SearchString%>&quot;>
<INPUT TYPE=&quot;HIDDEN&quot; name=&quot;pg&quot; VALUE=&quot;<%=CurrentPage-1%>&quot; >
<input type=&quot;submit&quot; value=&quot;Previous <%=RS.PageSize%> documents&quot;>
</form>

</td>
<%SaveQuery = TRUE%>
<%end if%>

<!--
This is the &quot;next&quot; button.
This button retrieves the next page of documents for the query.
If the RS.RecordCount is available, the number of
documents on the next page will be displayed.
-->

<%if Not RS.EOF then%>
<td align=right>
<form action=&quot;<%= QueryForm%>&quot; method=&quot;POST&quot;>
<INPUT TYPE=&quot;HIDDEN&quot; NAME=&quot;SearchString&quot; VALUE=&quot;<%=SearchString%>&quot;>
<INPUT TYPE=&quot;HIDDEN&quot; name=&quot;pg&quot; VALUE=&quot;<%=CurrentPage+1%>&quot; >

<% NextString = &quot;Next &quot;
if RS.RecordCount <> -1 then
NextSet = (RS.RecordCount - NextRecordNumber) + 1
if NextSet > RS.PageSize then
NextSet = RS.PageSize
end if
NextString = NextString & NextSet & &quot; documents&quot;
else
NextString = NextString & &quot; page of documents&quot;
end if
%>
<input type=&quot;submit&quot; value=&quot;<%=NextString%>&quot;>
</form>
</td>
<%SaveQuery = TRUE%>
<%end if%>

</TABLE>


<!-- Display the page number -->

Page <%=CurrentPage%>
<%if RS.PageCount <> -1 then
Response.Write &quot; of &quot; & RS.PageCount
end if %>


<%
' If either of the previous or back buttons were displayed, save the query
' and the recordset in session variables.
if SaveQuery then
set Session(&quot;Query&quot;) = Q
set Session(&quot;RecordSet&quot;) = RS
else
RS.close
Set RS = Nothing
Set Q = Nothing
set Session(&quot;Query&quot;) = Nothing
set Session(&quot;RecordSet&quot;) = Nothing
end if
%>

<% end if
elseif not NewQuery then
Response.Write &quot;&quot;
else
Response.Write &quot;Please enter a word or phrase to search for.&quot;
end if

%>
 
What error message are u getting ?
Or is it just returning nothing ?

run the inetpub/iissamples/issamples/query.asp
to test index server on your NT server

Maybe you need to grant permissions to the
anonymous user ? iusr_computername to the
inetpub/ folder

Regards, Paul
 
When I deleted the &quot;util.AddScopeToQuery&quot; lines and wrote
Q.Catalog = &quot;Catalogname&quot; (I picked out a name of a Catalog of mines) it had results. So your coding seems to be okay, only the determination of the location of
Catalogs should be tuned...

By the way. I have a problem too, I am also trying to make the Index Server work for me, and I can not get the values stored in the &quot;vpath&quot; variable. Do you have any tips for that?

Ayac
 
Hi,

I just created a simple search page used for finding records.It can search by Last Nmae,
First Name, Year of graduation or one of three other text fields.This is the part of the
code that handles the text search, which was generated by DreamWeaver UltraDev:

<%@LANGUAGE=&quot;VBSCRIPT&quot;%> <%

Dim RsPublicResult__FirstName
RsPublicResult__FirstName = &quot;%&quot;
if(Request.Form(&quot;FirstName&quot;) <> &quot;&quot;) then RsPublicResult__FirstName = Request.Form(&quot;FirstName&quot;)
Dim RsPublicResult__LastName
RsPublicResult__LastName = &quot;%&quot;
if(Request.Form(&quot;LastName&quot;) <> &quot;&quot;) then RsPublicResult__LastName = Request.Form(&quot;LastName&quot;)

%> <%
set RsPublicResult = Server.CreateObject(&quot;ADODB.Recordset&quot;)
RsPublicResult.ActiveConnection = &quot;dsn=alumni;&quot;
RsPublicResult.Source = &quot;SELECT * FROM alumni WHERE Fname like '&quot; + Replace(RsPublicResult__FirstName, &quot;'&quot;, &quot;''&quot;) + &quot;%' AND Lname like '&quot; + Replace(RsPublicResult__LastName, &quot;'&quot;, &quot;''&quot;) + &quot;%'&quot;
if RsPublicResult.Source= &quot;&quot; then Response.Write &quot;No Records Found&quot;
RsPublicResult.CursorType = 0
RsPublicResult.CursorLocation = 2
RsPublicResult.LockType = 3
RsPublicResult.Open
RsPublicResult_numRows = 0
%><%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
RsPublicResult_numRows = RsPublicResult_numRows + Repeat1__numRows

%>


While ((Repeat1__numRows <> 0) AND (NOT RsPublicResult.EOF))
%>
<tr>
<td>
<div align=&quot;center&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;><%=(RsPublicResult.Fields.Item(&quot;Fname&quot;).Value)%></font></div>
</td>
<td>
<div align=&quot;center&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;><%=(RsPublicResult.Fields.Item(&quot;Lname&quot;).Value)%></font></div>
</td>
<td>
<div align=&quot;center&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;><%=(RsPublicResult.Fields.Item(&quot;GradYear&quot;).Value)%></font></div>
</td>
<td>
<div align=&quot;center&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;><%=(RsPublicResult.Fields.Item(&quot;Email&quot;).Value)%></font></div>
</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
RsPublicResult.MoveNext()
Wend
%>
Without changing the syntax much, does anyone know how this can be made to give a user
friendly message..whenever an invalid name is queried i should be able to give my user
..user friendly message like &quot;No records are found &quot;..instead of a blank screen......

looking forward for your cooperation.

sincerely,

palreddy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top