QUOTE (Jonas @ Oct 21 2007, 07:06 PM)

I see no reason why it can't stay open. What if someone in the future against all odds find the
Search Form, find an AJAX thread, and it's locked, but they have some interesting input/good points?
Advanced Usage Help: "Some Words" Find posts with the phrase 'some words of wisdom', 'some words' but not 'some
noise words'
My bolding.
I should like that search form, with AJAX functionality on my own sites.
CODE
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
dim resultCount as integer = 0
dim strA as string
Dim myConnection as New SqlConnection("server=myServerName;pwd=myPassword;database=myDB")
Function dhReplaceAll( _
ByVal strText as string, _
ByVal strFind as string, _
ByVal strReplace as string, _
ByVal intFirst as integer, _
ByVal intCount as integer, _
ByVal fCaseSensitive as boolean)
Dim intLenFind,intLenReplace,intPos,intStart,intI,intFound,intLast,intMode
' If anything's wrong in the various parameters,
' just exit. Unorthodox method, but it works here.
If Len(strText) = 0 Then Exit Function
If Len(strFind) = 0 Then Exit Function
If intFirst = 0 Then Exit Function
If intCount = 0 Then Exit Function
' The parameters must be reasonable if we're here.
' Handle the three optional parameters.
If intFirst < 0 Then
' -1 == start at the last match.
' -2 == start at the next to the last match, etc.
' intFound = dhCountIn(strText, strFind, False)
intFirst = intFound + intFirst + 1
If intFirst < 1 Then intFirst = 1
End If
If intCount > -1 Then
intLast = intFirst + intCount
End If
If fCaseSensitive Then
intMode = vbBinaryCompare '0
Else
intMode = vbTextCompare '1
End If
' Store away the length of the find and replace
' text, to speed things up later on.
intLenFind = Len(strFind)
intLenReplace = Len(strReplace)
intPos = 1
intI = 1
Do
intPos = InStr(intPos, strText, strFind, intMode)
If intPos > 0 Then
' Did you find a match? If so, check the other
' issues (starting replacement, and number
' of replacements)
If (intI >= intFirst) And _
((intCount = -1) Or (intI < intLast)) Then
' If the current item is greater than or equal
' the first item the caller has requested to be replaced,
' and...
' If either you don't care about the number of
' replacements, or this one is less than the
' final one you want to make, then do it.
' Perform the replacement.
strText = Left(strText, intPos - 1) & _
strReplace & Mid(strText, intPos + intLenFind)
' Skip over the new text.
intPos = intPos + intLenReplace
Else
' Just skip over the search string.
intPos = intPos + intLenFind
End If
intI = intI + 1
If (intCount <> -1 And intI >= intLast) Then
Exit Do
End If
End If
Loop Until intPos = 0
dhReplaceAll = strText
End Function
Function TrimAll(Str)
'remove all non ASCI chrs and reduce internal whitespace to single
Dim i, strTemp, strOut, strCh
strTemp = Str
For i = 1 To Len(strTemp)
strCh = Mid(strTemp,i,1) 'look at each character in turn
'if the chr is a space and the previous added chr was a space ignore it
'otherwise add it on
If Not (strCh = " " and Right(strOut,1) = " ") _
And ((Asc(strCh) >= 64 And Asc(strCh) <= 122) _
Or (Asc(strCh) >= 48 And Asc(strCh) <= 57) Or Asc(strCh) = 32 Or strCh = ".") Then
strOut = strOut & strCh
End If
Next
TrimAll = strOut
End Function
Function RemoveIllegals(ByVal strTemp As String) As String
Dim IntI
'remove words that you don't want to search on from strTemp
strTemp = " " & strTemp & " " 'pad out first
'now remove illegal characters INSIDE words
strTemp = dhReplaceAll(strTemp, ",", "", 1, -1, False) 'replace commas
strTemp = dhReplaceAll(strTemp, "'", "", 1, -1, False) 'remove apostrophe
strTemp = dhReplaceAll(strTemp, ".", "", 1, -1, False) 'fullstops
strTemp = dhReplaceAll(strTemp, "+", "", 1, -1, False) 'plus
strTemp = dhReplaceAll(strTemp, "%20", "", 1, -1, False)
strTemp = dhReplaceAll(strTemp, ">", "", 1, -1, False)
strTemp = dhReplaceAll(strTemp, "<", "", 1, -1, False)
strTemp = dhReplaceAll(strTemp, "%257C", "", 1, -1, False)
strTemp = TrimAll(strTemp) 'remove multiple whitespace
'strTemp = Trim(strTemp)
strTemp = dhReplaceAll(strTemp, "-", " ", 1, -1, False) 'dash
strTemp = dhReplaceAll(strTemp, Chr(34), "", 1, -1, False) 'quotation marks
'WORDS to exclude
dim Illegal() as string = {"0","1","2","3","4","5","6","7","8","9","$","a","about","after", _
"all","also","an","and","another","any","are","as","at","b","be", _
"because","been","before","being","between","both","but","by","c", _
"came","can","come","could","d","did","do","does","e","each","else", _
"f","for","from","g","get","got","h","had","has","have","he","her","here", _
"him","himself","his","how","i","if","in","into","is","it","its","j","just", _
"k","l","like","m","make","many","me","might","more","most","much","must","my", _
"n","never","now","o","of","on","only","or","other","our","out","over","p","q", _
"r","re","s","said","same","see","should","since","so","some","still","such","t", _
"take","Test","than","that","the","their","them","then","there","these","they", _
"this","those","through","to","too","u","under","up","use","v","very","w","want", _
"was","way","we","well","were","what","when","where","which","while","who","will", _
"with","would","x","y","you","your","z","'","--",VbCrlf,";","\","/", _
"%", "*", "#"}
'remove illegal words
For IntI = LBound(Illegal) To UBound(Illegal)
If InStr(strTemp, " " & Illegal(IntI) & " ") Then
'Response.Write(Illegal(IntI) & "<br>")
strTemp = dhReplaceAll(strTemp, " " & Illegal(IntI) & " ", " ", 1, -1, False)
End If
Next 'IntI
RemoveIllegals = strTemp
End Function
Sub Page_Load(Src As Object, E As EventArgs)
searchPanel.visible = true
resultsPanel.visible = false
panelnoresults.visible = false
dim lstxtsearch as string
lstxtsearch = trim(request.Form("txtSearch"))
if lstxtsearch = "" Then
'do nothing page has been accessed directly
Else
txtQuery.Text = lstxtsearch
' make the page search
strA = txtQuery.Text
strA = RemoveIllegals(strA)
strA = strA.Trim(strA)
dim keyword as String = "INSERT INTO keywords VALUES ('" & strA & "')"
dim insertTempCommand as New SqlCommand(keyword, myConnection)
Dim insertedTemp as integer
try
myConnection.Open()
insertedTemp = insertTempCommand.ExecuteNonQuery()
catch ex as Exception
myConnection.Close()
end try
myConnection.Close()
dim searchInflectSQL as string = "SELECT kwsearch.title, kwsearch.description, kwsearch.url, kwsearch.kwsearch_id, kwsearch.verified, KEY_TBL.RANK FROM kwsearch INNER JOIN FREETEXTTABLE(kwsearch, title, '" & strA & "') AS KEY_TBL ON kwsearch.kwsearch_id = KEY_TBL.[KEY] WHERE kwsearch.verified = 1 ORDER BY KEY_TBL.[RANK] DESC"
resultsPanel.visible = true
dim showResults as boolean = true
'txtResult.Text = searchInflectSQL
Dim myCommandInflect as New SqlCommand(searchInflectSQL, myConnection)
Dim myDAInflect as New SqlDataAdapter()
myDAInflect.SelectCommand = myCommandInflect
Dim myDSInflect as New DataSet()
try
myDAInflect.Fill(myDSInflect, "results")
if myDSInflect.Tables("results").Rows.Count > 0 then
resultCount = resultCount + myDSInflect.Tables("results").Rows.Count
'resultCount = myDS.Tables("results").Rows.Count
showResults = true
Else
resultsPanel.visible = true
panelnoresults.visible = true
end if
catch ex as Exception
end try
try
repeaterInflectResults.DataSource = myDSInflect
repeaterInflectResults.DataBind()
catch Ex as Exception
end try
if showResults then
resultsPanel.visible = true
searchPanel.visible = true
end if
End if
End Sub
sub search_click(Src As Object, E As EventArgs)
strA = txtQuery.Text
strA = RemoveIllegals(strA)
strA = strA.Trim(strA)
dim searchInflectSQL as string = "SELECT kwsearch.title, kwsearch.description, kwsearch.url, kwsearch.kwsearch_id, kwsearch.verified, KEY_TBL.RANK FROM kwsearch INNER JOIN FREETEXTTABLE(kwsearch, title, '" & strA & "') AS KEY_TBL ON kwsearch.kwsearch_id = KEY_TBL.[KEY] WHERE kwsearch.verified = 1 ORDER BY KEY_TBL.[RANK] DESC"
resultsPanel.visible = true
dim showResults as boolean = true
'txtResult.Text = searchInflectSQL
Dim myCommandInflect as New SqlCommand(searchInflectSQL, myConnection)
Dim myDAInflect as New SqlDataAdapter()
myDAInflect.SelectCommand = myCommandInflect
Dim myDSInflect as New DataSet()
try
myDAInflect.Fill(myDSInflect, "results")
if myDSInflect.Tables("results").Rows.Count > 0 then
resultCount = resultCount + myDSInflect.Tables("results").Rows.Count
'resultCount = myDS.Tables("results").Rows.Count
showResults = true
Else
resultsPanel.visible = true
panelnoresults.visible = true
end if
catch ex as Exception
end try
try
repeaterInflectResults.DataSource = myDSInflect
repeaterInflectResults.DataBind()
catch Ex as Exception
end try
if showResults then
resultsPanel.visible = true
searchPanel.visible = true
end if
dim keyword as String = "INSERT INTO keywords VALUES ('" & strA & "')"
dim insertTempCommand as New SqlCommand(keyword, myConnection)
Dim insertedTemp as integer
try
myConnection.Open()
insertedTemp = insertTempCommand.ExecuteNonQuery()
catch ex as Exception
myConnection.Close()
end try
myConnection.Close()
end sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="global.css" rel="stylesheet" type="text/css" media="screen">
<link href="print.css" rel="stylesheet" type="text/css" media="print">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>5 Star Search Engine</title>
<link rel="shortcut icon" href="images/5staricon.ico" >
</head>
<body>
<div id="container">
<div id="banner">
<div id="search" align="right">
<form action="http://www.5-star.co.uk/search.aspx" method="post" style="margin: 0; padding: 0;"><input ID="txtSubmit" style="font-size:9px" type="submit" Value="Search" name="txtSubmit"> <input type="text" ID="txtSearch" style="font-size:9px" name="txtSearch" size="14"></form>
</div>
</div>
<div id="breadcrumbs">
<div>
<span class="viewing">Currently Viewing:</span> <a href="default.aspx">home</a> / <a href="search.aspx">search</a>
</div>
</div>
<div id="content">
<br>
<asp:panel ID="searchPanel" Visible="false" runat="server">
<form runat="server" action="" method="post" style="margin: 0; padding: 0;">
<h1>5 Star Search Engine</h1>
<h2>Enter keyword:</h2>
<asp:TextBox Columns="20" Font-Name="verdana" id="txtQuery" runat="server"></asp:TextBox> <asp:Button ID="search2" runat="server" Text="Search" OnClick="search_click" />
<br><br><img src="images/mNavigationBullet.gif"> <a href="searchtips.aspx" class="newLinksSmall">Search tips</a>
</form>
</asp:panel>
<asp:panel ID="resultsPanel" Visible="false" runat="server">
<h2>Keyword Search Engine Results: <%=resultCount%> Matches Found</h2>
<p>Your search for '<%=strA%>' found the following <%=resultCount%> documents (of over 125 documents searched)
<br>
Displaying all results with best matches displayed first:</p>
<asp:Repeater runat="server" id="repeaterInflectResults">
<HeaderTemplate>
<div class="section">
</HeaderTemplate>
<ItemTemplate>
<div class="sectionblocka">
<p><img src="images/mNavigationBullet.gif"> <a href="<%# DataBinder.Eval(Container.DataItem, "url")%>" class="newLinksSmall"><strong><%# DataBinder.Eval(Container.DataItem, "description")%></strong></a>
<br>http://www.5-star.co.uk/<%# DataBinder.Eval(Container.DataItem, "url")%></p>
</div>
</ItemTemplate>
<AlternatingItemTemplate>
<div class="sectionblocka">
<p> <img src="images/mNavigationBullet.gif"> <a href="<%# DataBinder.Eval(Container.DataItem, "url")%>" class="newLinksSmall"><strong><%# DataBinder.Eval(Container.DataItem, "description")%></strong></a>
<br>http://www.5-star.co.uk/<%# DataBinder.Eval(Container.DataItem, "url")%></p>
</div>
</AlternatingItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
</asp:panel>
<asp:panel ID="panelnoresults" Visible="false" runat="server">
<p>No documents have been found for your search criteria - please amend your search criteria, visit the search tips page, or request a 5 Star callback</p>
<img src="images/mNavigationBullet.gif"> <a href="searchtips.aspx" class="newLinksSmall">Search tips</a><br>
<img src="images/mNavigationBullet.gif"> <a href="contactForm.aspx" class="newLinksSmall">Request a 5 Star callback regarding your query</a>
</asp:panel>
</div>
</div>
</body>
</html>
Anybody that can translate that site search code to PHP with
Google suggest functionality? I think Google combines iFrame and XMLHTTPRequest technology.