Skip to main content.
home | support | download

Back to List Archive

Re: swishex setup

From: <cmpeders(at)not-real.co.seminole.fl.us>
Date: Tue Feb 18 2003 - 16:32:54 GMT
Well, I have a one page search ASP functioning on the intranet I work on.
Here is the code for it. There is several things going on in the page. I am
executing the search using the ASPEXEC component and I pass the parameters
that I wanted to use. The parameters determined how the search was
performed and how  the results would come back to me. Then I parsed the
results into a manner that I could use them. I am also handling paging on
here so that only 20 records show on a page and that links for the rest of
the results will display. Finally, I am inserting the term into a database
so that I can track what search terms people are looking for. I have a
report that I run to show me what people are trying to find each month.
Hopefully this helps. I also have my HTML page formatting in there that you
would obviously have to replace with yours.

Chris Pedersen

<% @ ENABLESESSIONSTATE = FALSE  LANGUAGE = VBScript  %>
<% Option Explicit
Response.Buffer = TRUE
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Here is a rundown of the different include files that are being called a
standard page
'overlib.inc - this contains the code for the overlib dropdown menus
'menubar.inc - this contains the code for the top menu bar
'menubar2.inc - this contains the code for the bottom menu bar
'site design by Chris Pedersen 2002
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim strSearchWords, intStart, intPage, intPageNum, intTemp
strSearchWords = Request.QueryString("words")
intPage = 20 'This is the number of results to show on a page
If Request.QueryString("start") <> "" Then 'This handles what result number
to start at - this assists in paging
      intStart = Request.QueryString("start")
Else
      intStart = 1
End If
Sub Paging(start,num,theend)
      'This sub will handle paging as far as setting up the links for the
result pages
      Dim pages, g, newstart, nextstart
      Response.Write "<b>Result Pages: &nbsp;</b>"
      pages = theend\num 'find the number of whole pages
      If theend Mod num <> 0 Then 'find out if there is a partial page
            pages = (pages+1)
      End If
      newstart = 1 'initialize the starting point for the links
      For g = 1 to pages 'iterate through to create the links
            If (g-1) <> (intStart\num) Then
                  Response.Write "<a href=""search.asp?words=" &
strSearchWords & "&start=" & newstart & """>" & g & "</a> &nbsp;&nbsp;"
            Else
                  Response.Write g & " &nbsp;&nbsp;"
                  nextstart = newstart + num
            End If
            newstart = newstart + num
      Next
      If nextstart <> newstart Then
            Response.Write "<a href=""search.asp?words=" & strSearchWords &
"&start=" & nextstart & """>NEXT</a> &nbsp;&nbsp;"
      End If
End Sub
%>
<html>

<head>
<link href="screen.css" rel="stylesheet" type="text/css" title="screen"
media="screen" >
<link href="print.css" rel="stylesheet" type="text/css" title="print" media
="print" >
<!--#INCLUDE FILE="includes/overlib.inc"-->

<title>Search the Intranet</title>
</head>

<body background="images/back_checkerboard.gif" topmargin="7" leftmargin
="7">

  <table border="2" cellpadding="0" cellspacing="0" style="border-collapse:
collapse" bordercolor="#0000FF" width="700" id="AutoNumber1" bgcolor="
#FFFFFF">
    <tr>
      <td width="100%">
      <table border="0" cellpadding="0" cellspacing="0" style
="border-collapse: collapse" bordercolor="#111111" width="100%" id
="AutoNumber2">
        <tr>
          <td width="100%">
          <div align="center">
            <center>
            <table border="0" cellpadding="0" cellspacing="0" style
="border-collapse: collapse" bordercolor="#111111" width="700" id
="AutoNumber23" height="52">
              <tr>
                <td width="440" height="52">
                <img border="0" src="images/h_general.gif" alt
="http://intranet.co.seminole.fl.us" width="438" height="50"></td>
                <td width="260" height="52">
                  <script language="JavaScript" src="includes/search.js">
                          <!-- search script 1  This is a javascript
include file in case the search script needs to be directed to a different
engine-->
                          </script>
                <table border="1" cellpadding="4" cellspacing="0" style
="border-collapse: collapse" bordercolor="#0054A8" width="257" id
="AutoNumber17" bgcolor="#DDE8F4">
                <tr>
                  <td width="253">
                  <p align="center">&nbsp;<input type="text" name="words"
size="20">&nbsp;
                  <input type="submit" value="SEARCH" name="B1"></td>
                </tr>
              </table>


                              </td>
                                 </form>
              </tr>
            </table>
            </center>
          </div>
          </td>
        </tr>
        <tr>
          <td width="100%">
          <table border="1" cellpadding="3" cellspacing="0" style
="border-collapse: collapse" bordercolor="#BBBB00" width="100%" id
="AutoNumber3">
            <tr>
              <td width="100%" bgcolor="#E8E800">
<!--#INCLUDE FILE="includes/menubar.inc"-->&nbsp;</td>
            </tr>
          </table>
          </td>
        </tr>
        <tr>
          <td width="100%">
          <table border="0" cellpadding="5" cellspacing="0" style
="border-collapse: collapse" bordercolor="#111111" width="100%" id
="AutoNumber5">
            <tr>
              <td width="100%"><p align="center"><br>
              <img border="0" src="images/sh_search.gif" alt="Search the
Intranet" width="427" height="34">
                      <p> <span class="font12pt"><img src
="images/search_clip.gif" width="96" height="100" hspace="6" vspace="0"
align="left"><br>
                    <font size="3">This is searching <b>ONLY</b> the
intranet.
                    You will want to visit the <a href
="http://www.co.seminole.fl.us">internet</a>
                    site if looking for information that would be presented
on
                    there.</font></span><br>
                    <br>
                    <span class="font12pt">Enter the topic that you are
looking
                    for more information on:</span><br>
                    <span class="font12pt"> </span><br>
                    <!--webbot BOT="GeneratedScript" PREVIEW=" " startspan
-->
                    <script Language="JavaScript" Type="text/javascript"><!
--
function FrontPage_Form1_Validator(theForm)
{

  if (theForm.words.value == "")
  {
    alert("Please enter a value for the \"search words\" field.");
    theForm.words.focus();
    return (false);
  }

  if (theForm.words.value.length < 1)
  {
    alert("Please enter at least 1 characters in the \"search words\"
field.");
    theForm.words.focus();
    return (false);
  }

  if (theForm.words.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"search words\"
field.");
    theForm.words.focus();
    return (false);
  }
  return (true);
}
//--></script>
                    <!--webbot BOT="GeneratedScript" endspan -->
                  <form method="GET" action="<%= Request.ServerVariables
("SCRIPT_NAME")%>" onsubmit="return FrontPage_Form1_Validator(this)"
language="JavaScript" name="FrontPage_Form1">
                    <p align="center">
                      <!--webbot bot="Validation" s-display-name="search
words" b-value-required="TRUE" i-minimum-length="1" i-maximum-length="50"
-->
                      <input type="text" name="words" size="50" tabindex
="1" maxlength="50">
                      <input type="submit" value="SEARCH" name="B1"
tabindex="10">
                    </p>
                    <p>
</form>
<%
If strSearchWords <> "" Then
  Dim strParam, Executor, strResult, arrResults, intHeader, strHeader, i,
arrResults2, strTemp,z, arrHeader
  strParam = "-w """ & strSearchWords & """ -b " & intStart & " -m " &
intPage & " -x ""\<BR\><swishrank>|<swishtitle>|<swishdocpath>
|<swishlastmodified fmt='%m/%d/%Y'>"" -f ""D:\SWISH-E\intranet.index"""
  Set Executor = Server.CreateObject("ASPExec.Execute")
  Executor.Application = "D:\SWISH-E\swish-e"
  Executor.Parameters = strParam
  Executor.ShowWindow = True
  strResult = Executor.ExecuteDosApp 'runs the search and returns the
results as text
      intHeader = InStr(strResult,"<BR>") 'finds where the first break is
      strHeader = Left(strResult,intHeader) 'grabs the header
      arrHeader = Split(strHeader,"#") 'splits the header into specific
fields to be used
      Response.Write "<table width=""690"" cellpadding=""2"">"
If intHeader = "0" Then 'This will handle if the search did not find any
matches
      Response.Write "<tr><td><b><font class=""font12pt"">There were no
matches. Please try searching again</font></b></td></tr>"
Else
      Response.Write "<tr><td colspan=""2"" bgcolor=""#8EC043"">"
      intTemp = InStr(arrHeader(3),"hits: ")
      intPageNum = Mid(arrHeader(3),intTemp+6)
      Response.Write "<b><font class=""font12pt"">SEARCH FOR: '" &
strSearchWords & "'</font></b><br>"
      Response.Write "Total Matches: " & intPageNum & "<br></td></tr>"
      Response.Write "<tr><td colspan=""2"" bgcolor=""#B5D684"">"
      Call Paging(intStart,intPage,intPageNum) 'Will provide the paging
links if there is more than one page
      Response.Write "</td></tr>"
      strResult = Mid(strResult,intHeader) 'removes the header from the
search results
      arrResults = Split(strResult,"<BR>") 'splits the results into an
array
      For i = 1 to UBound(arrResults) 'loops through the one dimensional
array
            strTemp = arrResults(i)
            arrResults2 = Split(strTemp,"|") 'splits the single result into
specific fields to be used
            Response.Write "<tr><td width=""10"" valign=""top"">" &
i+(intStart-1) & ". </td><td width=""640"" valign=""top""><a href=""" &
arrResults2(2) & """>" & arrResults2(1) & "</a><BR> (Match Rank: " &
arrResults2(0) & ") - <i>Last Modified: " & arrResults2(3) &
"</i></td></tr>"
      Next
      Response.Write "<tr><td colspan=""2"" bgcolor=""#B5D684"">"
      Call Paging(intStart,intPage,intPageNum) 'Will provide the paging
links if there is more than one page
      Response.Write "</td></tr>"
End If
      Response.Write "</table>"
End If

%>


<p>
</td>
            </tr>
<%
If Request.QueryString("start") = "" AND strSearchWords <> "" Then 'will
only update stats if it is the first page of the search results
'This code will add the search term to the tbl_searchstats to keep track of
search terms for reporting purposes
      Dim objConn, objRS, strSQL, strMonth, strYear
      strMonth = DatePart("m",Now())
      strYear = DatePart("yyyy",Now())
      Set objConn = Server.CreateObject( "ADODB.Connection" )
      objConn.Open
"Provider=SQLOLEDB;SERVER=ServerNameHere;UID=UserIDHere;PWD=PasswordHere;DATABASE=DatabaseHere"
      Set objRS = Server.CreateObject("ADODB.Recordset")
      strSQL = "SELECT * FROM tbl_searchstats WHERE term='" &
strSearchWords & "' AND DATEPART(month,searchdate) = " & strMonth & " AND
DATEPART(year,searchdate) = " & strYear
      objRS.Open strSQL,objConn

      If objRS.EOF Then 'If no record was found it will create & initialize
the counter in the database
            strSQL = "INSERT INTO tbl_searchstats
(term,frequency,searchdate) VALUES ('" & Trim(strSearchWords) & "', '1', '"
& Date() & "')"
            objConn.Execute strSQL
      Else 'Will try to increment the counter
                  Dim newCount
                  newCount = Int(objRS("frequency")) + 1
                  strSQL = "UPDATE tbl_searchstats SET frequency = '" &
newCount & "'WHERE term='" & strSearchWords & "' AND
DATEPART(month,searchdate) = " & strMonth & " AND DATEPART(year,searchdate)
= " & strYear
                  objConn.Execute strSQL
      End If
      objRS.Close
      objConn.Close
      Set objRS = nothing
      Set objConn = nothing
End If
'End of database insert code
%>
          </table>
          </td>
        </tr>
        <tr>
          <td width="100%">
          <table border="1" cellpadding="3" cellspacing="0" style
="border-collapse: collapse" bordercolor="#BBBB00" width="100%" id
="AutoNumber4">
            <tr>
              <td width="100%" bgcolor="#E8E800"><!--#INCLUDE FILE
="includes/menubar2.inc"-->
              &nbsp;</td>
            </tr>
          </table>
          </td>
        </tr>
        <tr>
          <td width="100%">&nbsp;</td>
        </tr>
      </table>
      </td>
    </tr>
  </table>

</body>

</html>




                                                                                                                                                 
                      "Thomas McDonald"                                                                                                          
                      <tom.mcdonald@westernsouthe        To:       <cmpeders@co.seminole.fl.us>, "Multiple recipients of list"                   
                      rnlife.com>                         <swish-e@sunsite.berkeley.edu>                                                         
                                                         cc:                                                                                     
                      02/18/2003 11:02 AM                Subject:  RE: [SWISH-E] Re: swishex setup                                               
                      Please respond to                                                                                                          
                      tom.mcdonald                                                                                                               
                                                                                                                                                 
                                                                                                                                                 




This is directed at Chris Pedersen

Chris, do you have any good code that you can share for parsing the swish-e
result when using aspexec?

-----Original Message-----
From: swish-e@sunsite.berkeley.edu
[mailto:swish-e@sunsite.berkeley.edu]On Behalf Of
cmpeders@co.seminole.fl.us
Sent: Tuesday, February 18, 2003 8:20 AM
To: Multiple recipients of list
Subject: [SWISH-E] Re: swishex setup



I tried the SWISHEX component with little success also. I ended up using a
free ASPEXEC component that lets me run executables from an ASP. I have it
run the swish search with whatever terms the user inputs. Then you have to
parse and format the results to display the way you want them to.

Just something to consider.

Chris Pedersen





                      "Thomas McDonald"
                      <tom.mcdonald@westernsouthe        To:       Multiple
recipients of list <swish-e@sunsite.berkeley.edu>
                      rnlife.com>                        cc:
                      Sent by:                           Subject:
[SWISH-E]
Re: swishex setup
                      swish-e@sunsite.berkeley.ed
                      u


                      02/18/2003 08:05 AM
                      Please respond to
                      tom.mcdonald






Do you think it would just be better to make my own "Swishex" type solution
by doing all the CGI stuff myself and then writing some xsl to format.  If
so, do you know any good tutorials on how to do this (I have never
connected
to a cgi via an iis/vbscript/asp page?  Should I avoid this headache and
just use the older Swish-e library?

-----Original Message-----
From: swish-e@sunsite.berkeley.edu
[mailto:swish-e@sunsite.berkeley.edu]On Behalf Of Bill Moseley
Sent: Friday, February 14, 2003 6:28 PM
To: Multiple recipients of list
Subject: [SWISH-E] Re: swishex setup


On Fri, 14 Feb 2003, Thomas McDonald wrote:

> I was able to successfully set up the Swishex demo.  I then copied in my
own
> index files to replace the ones distributed with swishex and I started to
> get the "server threw and exception" error.  Any ideas on what went
wrong?
> I know my index files are good because I can search them from the command
> prompt.

My guess is the COM component is linked to an imcompatible swish-e
library for your index.

Make sure you index with the exact version of swish-e that swishex was
linked against.

http://www.octopod.net/technews/Articles/SwishEXComponent.html says it's
based on Swish-E 2.0.5.  2.0.5 is old and much slower than the current
version.


--
Bill Moseley moseley@hank.org
Received on Tue Feb 18 16:34:32 2003