ASP做站內簡單搜尋

來源:互聯網
上載者:User
最近在做公司網站,為了讓客戶更容易地尋找公司的產品以及新聞等資訊,要實現站內簡單搜尋.如果簡單地採用SQL的LIKE '%Keyword%'方法效率實在不高.比如公司主打產品IPBOARD,如果你輸入"IP BOARD"就找不到了.想了個辦法解決.構造SQL語句核心代碼如下:

 Dim act,Key,i,sql
act=trim(request.QueryString("action"))
if act="search" then
 Key=trim(request.Form("Keyword"))
 if requestCstringSafe(Key)="" then Dimerr "搜尋字串中含有非法字元,或者為空白","back"
 Key=replace(Key," "," ")
 Key=split(Key," ")
 '查詢JL_Subject表,構造SQL語句
 sql="select * from JL_Subject where "
 
 sql=sql&"(Keyword Like '%"&Key(0)&"%' "  '搜尋Keyword欄位
 for i=Lbound(Key)+1 to Ubound(Key)
  if Key(i)<>"" and UCase(Key(i))<>"OR" and UCase(Key(i))<>"AND" then    if UCase(Key(i-1))="OR" then
    sql=sql&" or Keyword Like '%"&Key(i)&"%'"
   else
    sql=sql&" and Keyword Like '%"&Key(i)&"%'"
   end if
  end if
 next
 
 sql=sql&") or (Title Like '%"&Key(0)&"%' "
 for i=Lbound(Key)+1 to Ubound(Key)
  if Key(i)<>"" and UCase(Key(i))<>"OR" and UCase(Key(i))<>"AND" then 
   if UCase(Key(i-1))="OR" then
    sql=sql&" or Title Like '%"&Key(i)&"%'"
   else
    sql=sql&" and Title Like '%"&Key(i)&"%'"
   end if
  end if
 next
 
 sql=sql&")"
 
 response.Write(sql)
end if OK,看看這樣的SQL語句句應該沒問題了吧...呵呵... 其實做站內搜尋還有個投機取巧的辦法:利用google或者百度的site:domainroot文法進行指定站搜尋,將站內的搜尋提交到google或者百度的伺服器上(這樣做的前提是你的頁面必須事先被百度跟google收錄了,要不然是搜取不到D...嘿嘿...)當然,如果你懂小偷技術原理的話,你還可以將提交返回的頁面修改成你的風格,這樣不仔細看的話還真不知道你是提交到google或者百度返回的結果.呵呵...

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.