我不得不在其他人的代碼中解決一個搜索函數返回太多結果的問題,我注意到它使用了MATCH <,其中LIKE更合適。SQL搜索功能問題,LIKE和MATCH
我不是SQL太好,我已經改變了所有的比賽對LIKE的..
這顯然帶來了一個錯誤,我認爲它與針對其即時通訊不知道,但可能是僅做與MATCH一起工作..
這是asp代碼中的聲明。
strSQL = ""
strSQL = "SELECT 'case-studies' AS pagetype, cs.title AS entrytitle, cs.casestudyid AS id, csi.casestudyimageid AS imageid, csi.imagetitle, LIKE (cs.title, cs.content) AGAINST ('" & searchfor & "') AS relevance, LIKE (csi.imagetitle) AGAINST ('" & searchfor & "') AS imagerelevance "
strSQL = strSQL & "FROM casestudies AS cs, casestudiesimages AS csi "
strSQL = strSQL & "WHERE cs.casestudyid = csi.casestudyid AND cs.modestatus = '1' AND ((LIKE(cs.title, cs.content) AGAINST ('" & searchfor & "' IN BOOLEAN MODE)) OR (LIKE(csi.imagetitle) AGAINST ('" & searchfor & "' IN BOOLEAN MODE)) OR (cs.title like '%" & searchfor & "%') OR (cs.content like '%" & searchfor & "%') OR (csi.imagetitle like '%" & searchfor & "%')) "
strSQL = strSQL & "UNION ALL "
strSQL = strSQL & "SELECT 'news' AS pagetype, news.title AS entrytitle, news.newsid AS id, newsimages.newsimageid AS imageid, newsimages.imagetitle, LIKE (news.title, news.content) AGAINST ('" & searchfor & "') AS relevance, LIKE (newsimages.imagetitle) AGAINST ('" & searchfor & "') AS imagerelevance "
strSQL = strSQL & "FROM news, newsimages "
strSQL = strSQL & "WHERE news.newsid = newsimages.newsid AND news.modestatus = '1' AND ((LIKE(news.title, news.content) AGAINST ('" & searchfor & "' IN BOOLEAN MODE)) OR (LIKE(newsimages.imagetitle) AGAINST ('" & searchfor & "' IN BOOLEAN MODE)) OR (news.title like '%" & searchfor & "%') OR (news.content like '%" & searchfor & "%') OR (newsimages.imagetitle like '%" & searchfor & "%')) "
strSQL = strSQL & "GROUP BY id "
strSQL = strSQL & "ORDER BY relevance DESC, imagerelevance DESC "
誰能幫助破譯這個代碼。它需要搜索像像,而不是搜索「他」和獲得「幫助」等
感謝
好的,我明白你的意思了,我所做的只是將MATCH更改爲LIKE,所以我認爲這一切都是錯誤的......問題在於我缺乏SQL知識。你可以連續使用多個LIKE嗎? –
嗨保羅,是的,你可以在你的發言中有多個LIKE。但是你將永遠需要像上面那樣定義它。所以然後你添加AND然後像...一樣的列名,同樣的方式再次:) –