E tu parli poi di soluzioni creative ?![]()
codice:<% QueryString = Request.QueryString( "QueryString" ) QueryWords = Split( QueryString ) strIndent = "" ' Reindirizzo in caso di ricerca fallita If QueryString = "" Then Response.Redirect( "default.asp" ) End If Session.timeout = 2 If IsObject(Session("sitesearch_conn")) Then Set conn = Session("sitesearch_conn") Else Set conn = Server.CreateObject("ADODB.Connection") conn.open "sitesearch","","" Set Session("sitesearch_conn") = conn End If ' Setup SQL sql = "SELECT * FROM [CampoRicerca] WHERE" ' Cerco nel campo descrizione sql = sql & " ( [Description] LIKE '%" & QueryWords( 0 ) & "%'" ' Prima For i = LBound( QueryWords ) + 1 to UBound( QueryWords ) If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then If uCase( QueryWords( i-1 ) ) = "OR" Then sql = sql & " OR [Description] LIKE '%" & QueryWords( i ) & "%'" Else sql = sql & " AND [Description] LIKE '%" & QueryWords( i ) & "%'" End If End If Next ' Cerco nel campo keywords sql = sql & " ) OR ( [Keywords] LIKE '%" & QueryWords( 0 ) & "%'" For i = LBound( QueryWords ) + 1 to UBound( QueryWords ) If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then If uCase( QueryWords( i-1 ) ) = "OR" Then sql = sql & " OR [Keywords] LIKE '%" & QueryWords( i ) & "%'" Else sql = sql & " AND [Keywords] LIKE '%" & QueryWords( i ) & "%'" End If End If Next ' Cerco nel campo titolo sql = sql & " ) OR ( [Title] LIKE '%" & QueryWords( 0 ) & "%'" For i = LBound( QueryWords ) + 1 to UBound( QueryWords ) If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then If uCase( QueryWords( i-1 ) ) = "OR" Then sql = sql & " OR [Title] LIKE '%" & QueryWords( i ) & "%'" Else sql = sql & " AND [Title] LIKE '%" & QueryWords( i ) & "%'" End If End If Next ' Cerco nel campo summary sql = sql & " ) OR ( [Summary] LIKE '%" & QueryWords( 0 ) & "%'" For i = LBound( QueryWords ) + 1 to UBound( QueryWords ) If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then If uCase( QueryWords( i-1 ) ) = "OR" Then sql = sql & " OR [Summary] LIKE '%" & QueryWords( i ) & "%'" Else sql = sql & " AND [Summary] LIKE '%" & QueryWords( i ) & "%'" End If End If Next sql = sql & " )" ' Inizializzo il recordset ed eseguo la query Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sql, conn, 3, 3 ' Stampo la stringa Response.Write " QueryString: " & QueryString ' Stampo le parole Response.Write " Query Words: " For i = LBound( QueryWords ) to UBound( QueryWords ) Response.Write " " & strIndent & i & ": " & QueryWords( i ) Next ' Stampo la stringa sql Response.Write " SQL String : " & sql ' Stampo i risultati Response.Write " Results: <UL>" On Error Resume Next rs.MoveFirst Do While Not rs.eof Response.Write " " & "" & rs.Fields("Title") & " - " Response.Write rs.Fields("Description") & " " Response.Write "<FONT SIZE=2>URL: " & rs.Fields("URL") & "</FONT>" Response.Write "<HR SIZE=1 WIDTH=200 ALIGN=LEFT>" rs.MoveNext Loop Response.Write "[/list]" %>


Rispondi quotando