cswolf
Posts: 50 Joined: 11/9/2005 Status: offline
|
RE: need help with filtering search results - 8/27/2008 9:04:12
OK, so I've had a bit of success after I posted my original request for help. It is partially working now, but not completely. I am getting some bizarre results, and so now I wondered if anyone could help me out with figuring this thing out. I will post my code at the end of the message. But first, here are the bizarre results: When doing a default search for both file types together, it works perfectly. When selecting the radio button to show PDF files in the results only, it begins to get weird. The results do only show PDF files (which it is supposed to), but where a WMV would have been in the list is a blank space. So in other words, it is still making the <ul></ul> tags but with nothing in between them. Then, to make things even more bizarre, the next record that should display (which would be a PDF file) is completely missing. After that, it displays everything just fine. When selecting the radio button to show WMV files in the results only, it gets even worse. The results will show blank <ul></ul> tags again, then display some correct results, then more blank <ul></ul> tags, and then the following error message: "ADODB.Recordset error '800a0bcd' Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record. /training/search.asp, line 232" I never get that error if you search for only PDF's in the results. The code is basically the same for all three conditions, so I am dumbfounded as what is happening here. Anyway, here is my code:
<form action="search.asp" method="get">
<input name="query" type="text" %>" />
<input type="submit" value="Search" /><br />
<span class="search_text">Advanced Search:</span><br />
<input name="pdf_wmv" type="radio" value="pdf" />show only PDF's in search results
<input name="pdf_wmv" type="radio" value="wmv" />show only videos in search results
</form>
<%
Dim strQuery ' The text of our query
Dim objQuery ' The index server query object
Dim rstResults ' A recordset of results returned from I.S.
Dim objField ' Field object for loop
' Retreive the query from the querystring
strQuery = Request.QueryString("query")
' If the query isn't blank them proceed
If strQuery <> "" Then
' Create our index server object
Set objQuery = Server.CreateObject("IXSSO.Query")
' Set it's properties
With objQuery
.Catalog = "euniversity" ' Catalog to query
.MaxRecords = 99 ' Max # of records to return
.SortBy = "rank [d]"
.Columns = "filename, path, vpath, size, write, " _
& "characterization, DocTitle, DocAuthor, " _
& "DocKeywords, rank, hitcount"
' Build our Query: Hide admin page and FPSE pages
strQuery = "(" & strQuery & ")" _
& " AND NOT #filename = *admin*" _
& " AND NOT #path *\_vti_*"
' Uncomment to only look for files modified last 5 days
'strQuery = strQuery & " AND @write > -5d"
.Query = strQuery ' Query text
End With
' Get a recordset of our results back from Index Server
Set rstResults = objQuery.CreateRecordset("nonsequential")
' Get rid of our Query object
Set objQuery = Nothing
' Check for no records
If Not rstResults.EOF Then
' Print out # of results
Response.Write "<p><strong>"
Response.Write rstResults.RecordCount
Response.Write "</strong> results found:</p>"
' Loop through results
Do While Not rstResults.EOF
' Loop through Fields
' Pretty is as pretty does... good enough:
%>
<div id="search">
<!--
Here I am going to dynamically check the file extension of the search results to determine which icon (either PDF or WMV) appears in the search list. I am using the File System Object to do this
-->
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
%>
<ul>
<% If Request.QueryString("pdf_wmv") = "" Then %>
<!-- Here the fso looks at the file extension of the 'path' variable from the rstResults recordset -->
<% If fs.GetExtensionName(rstResults.Fields("path")) = "pdf" Then %>
<!-- If the file extension is pdf, then it will display the pdf icon which is defined by the #pdf CSS class -->
<li id="pdf"><strong><a href="<%= PathToVpath(rstResults.Fields("path")) %>"><%= PathToVpath(rstResults.Fields("doctitle")) %></a></strong></li>
<!-- Otherwise, if the file extension is NOT pdf, then it will display the WMV icon which is defined by the #wmv CSS class -->
<% Else %>
<li id="wmv"><strong><a href="<%= PathToVpath(rstResults.Fields("path")) %>"><%= rstResults.Fields("doctitle") %></a></strong></li><br />
<% End If %>
<!-- If the record contains a document author, then display the author's name, size of file, and description -->
<% If rstResults.Fields("docauthor") <> "" Then %>
<div id="search_info">
<em><b>Trainer:</b></em> <%= rstResults.Fields("docauthor") %><br />
<em><b>Size:</b></em> <%= rstResults.Fields("size") %> bytes<br />
<em><b>Description:</b></em> <%= rstResults.Fields("characterization") %><br />
</div>
<!-- If no document author is found, just display the description -->
<% Else %>
<div id="search_info">
<em><b>Description:</b></em> <%= rstResults.Fields("characterization") %><br />
</div>
<% End If %>
<% End If %>
<% If Request.QueryString("pdf_wmv") = "pdf" Then %>
<% If fs.GetExtensionName(rstResults.Fields("path")) = "pdf" Then %>
<!-- If the file extension is pdf, then it will display the pdf icon which is defined by the #pdf CSS class -->
<li id="pdf"><strong><a href="<%= PathToVpath(rstResults.Fields("path")) %>"><%= PathToVpath(rstResults.Fields("doctitle")) %></a></strong></li>
<!-- If the record contains a document author, then display the author's name, size of file, and description -->
<% If rstResults.Fields("docauthor") <> "" Then %>
<div id="search_info">
<em><b>Trainer:</b></em> <%= rstResults.Fields("docauthor") %><br />
<em><b>Size:</b></em> <%= rstResults.Fields("size") %> bytes<br />
<em><b>Description:</b></em> <%= rstResults.Fields("characterization") %><br />
</div>
<!-- If no document author is found, just display the description -->
<% Else %>
<div id="search_info">
<em><b>Description:</b></em> <%= rstResults.Fields("characterization") %><br />
</div>
<% End If %>
<!-- Otherwise, if the file extension is NOT pdf, then it will just move to the next record -->
<% Else
rstResults.MoveNext
End If
%>
<% End If %>
<% If Request.QueryString("pdf_wmv") = "wmv" Then %>
<% If fs.GetExtensionName(rstResults.Fields("path")) = "wmv" Then %>
<!-- If the file extension is wmv, then it will display the wmv icon which is defined by the #wmv CSS class -->
<li id="wmv"><strong><a href="<%= PathToVpath(rstResults.Fields("path")) %>"><%= PathToVpath(rstResults.Fields("doctitle")) %></a></strong></li>
<!-- If the record contains a document author, then display the author's name, size of file, and description -->
<% If rstResults.Fields("docauthor") <> "" Then %>
<div id="search_info">
<em><b>Trainer:</b></em> <%= rstResults.Fields("docauthor") %><br />
<em><b>Size:</b></em> <%= rstResults.Fields("size") %> bytes<br />
<em><b>Description:</b></em> <%= rstResults.Fields("characterization") %><br />
</div>
<!-- If no document author is found, just display the description -->
<% Else %>
<div id="search_info">
<em><b>Description:</b></em> <%= rstResults.Fields("characterization") %><br />
</div>
<% End If %>
<!-- Otherwise, if the file extension is NOT wmv, then it will skip it and moved to the next record -->
<% Else
rstResults.MoveNext
End If
%>
<% End If %>
</ul>
</div>
<%
' This is line 232 where the error is being reported when using the WMV radio button. Move to next result
rstResults.MoveNext
Loop
rstResults.MoveFirst
Response.Write "<pre>"
'Response.Write rstResults.GetString()
Response.Write "</pre>"
Else
' Print out # of results
Response.Write "<p><strong>"
Response.Write rstResults.RecordCount
Response.Write "</strong> results found:</p>"
Response.Write "Sorry. No results found."
End If
' Kill our recordset object
Set rstResults = Nothing
End If
%>
<%
Function PathToVpath(strPath)
Const strWebRoot = "c:\inetpub\wwwroot\"
Dim strTemp
strTemp = strPath
strTemp = Replace(strTemp, strWebRoot, "\")
strTemp = Replace(strTemp, "\", "/")
PathToVpath = strTemp
End Function
%>
|