|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
只要你想学,就没什么优缺点,上面那位大哥已经把网上的评论说了,但我认为想学哪个都一样,不然它就不可能在当今时代数字艺术方面存活到今天搜刮引擎ByScottMitchell
Asawebsitegrows,findingcontentonthesitebecomesincreasinglydifficult.Tocombatthedifficulty
offindingrelevantinformationonalargesite,manydevelopersturntowritingasearchenginefortheir
site.ThisarticlediscusseshowtoimplementsuchasystemusingActiveServerPagesandSQLServer.
Therearetwo"types"ofsearchengines.Bothtakeasearchstringfromtheusertobegin,butwhat,
exactly,theysearchdiffers.Acompletelydynamicsearchengineforacompletelydynamicwebsitewill
hitadatabasetablewhichtiesanarticleURLtothearticlesdescription.Thedatabasecanthencompare
theuserssearchrequesttothedescriptionsoftheavailablearticlesandreturntherelevantURLs.
Anotherapproachistodoanactualtextsearchthrougheachofthefiles.Forexample,saythattheuser
searchedfor"Microsoft."YoursearchenginewouldthenlookthroughallofyourHTMLfilesandreturnthe
URLsofthosewhichhadtheword"Microsoft"somewhereinthedocument.Suchasystemisusedforthisweb
sitessearchengine.Inmyopinion,itismucheasiertowritesuchasystemdescribedinPerl(which
thissystemiswrittenin),thaninActiveServerPages;however,itisquitepossibletowriteatext-
findingsearchsysteminASP.
InthisarticleIplantoimplementtheformersearchengine,thedynamicsearchengine.Forthisexample
IwillmakeatablecalledArticleURL,whichwillhavethefollowingdefinition:
ArticleURL
ArticleURLIDintPK
URLvarchar(255)
Titlevarchar(100)
Descriptionvarchar(255)
Nowthatwevegotourtabledefinition,letslookathowourwebvisitorswillentertheirqueries.
SearchQuerying
Asearchengineisratheruselessunlessqueriescanbemade,andtheresultsarereturned.Letsexamine
howwewillcodethefirstneededpart,theusersearchrequests.AllwewillneedisasimpleHTMLFORM
whichtakesinputfromtheuserandpassesitontoanASPpage.Hereisanexampleofafilewellcall
SearchStart.htm:
<HTML>
<BODY>
<FORMMETHOD=POSTACTION="Search.asp&ID=0">
>Searchfor:<INPUTTYPE=TEXTNAME="txtSearchString"SIZE="50">
<P>
<INPUTTYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
This,ofcourse,isnotaprettyHTMLpage,butitsfunctionalityisthere.Therearemanythingswhich
couldbedonetoenhancethispage.ItisrecommendedthatJavaScriptfunctionsbepresenttomakesure
theuserissearchingsomething(i.e.notjustclickingSubmitwhenthereisnosearchstring).
NowthatwehavetheQuery,weneedtolookatthesecondphaseofanysearchengine:retrievingthedata
andpresentingittotheuser.Hereiswheretherealfunbegins!
RetrievingtheDataandPresentingIt:
OurASPpageSearch.aspmustdoafewsteps.First,itmustparsetheFORMvariabletxtSearchString.Right
now,IamassumingthateachwordinthetxtSearchStringseparatedbyaspacewillbeANDedtogether.You
canalterthis(haveitORed),or,tomakeitmoreprofessional,youcangivetheusertheoptionofwhich
booleantoputinbetweeneachspacedword.
Next,Search.aspwillneedtohitthedatabasetableArticleURLandreturnthedatainauser-friendly
fashion.Also,wewillwanttodisplaytheresultsonly10recordsatatime,sologicwillneedtobe
implementedtohandlethisaswell.Letslookatsomecode.
<%
ConnecttoDatabase
DimConn
SetConn=Server.CreateObject("ADODB.Connection")
Conn.OpenApplication("MyConnectString")
Settheseuptoyourpreference
DefaultBoolean="AND"
RecordsPerPage=10
Getourformvariable
DimstrSearch
strSearch=Request.form("txtSearchString")
GetourcurrentID.ThisletsusknowwhereweareDimID
ID=Request.QueryString("ID")
SetupourSQLStatement
DimstrSQL,tmpSQL
strSQL="SELECT*FROMArticleURLWHERE"
tmpSQL="(DescriptionLIKE"
OK,weneedtoparseourstringhere
DimPos
Pos=1
WhilePos>0
Pos=InStr(1,strSearch,"")
IfPos=0Then
Wehavehittheend
tmpSQL=tmpSQL&a</p>Access是一种桌面数据库,只适合数据量少的应用,在处理少量数据和单机访问的数据库时是很好的,效率也很高。但是它的同时访问客户端不能多于4个。access数据库有一定的极限,如果数据达到100M左右,很容易造成服务器iis假死,或者消耗掉服务器的内存导致服务器崩溃。 |
|