飘飘悠悠 发表于 2015-1-16 23:22:33

ASP网站制作之用ASP创建一个复杂的搜刮引擎

只要你想学,就没什么优缺点,上面那位大哥已经把网上的评论说了,但我认为想学哪个都一样,不然它就不可能在当今时代数字艺术方面存活到今天搜刮引擎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假死,或者消耗掉服务器的内存导致服务器崩溃。

再现理想 发表于 2015-1-20 09:43:44

哪些内置对象是可以跳过的,或者哪些属性和方法是用不到的?

精灵巫婆 发表于 2015-1-26 23:51:53

ASP的语言不仅仅只是命令格式差不多,而是包含在<%%>之内的命令完全就是VB语法。虽然ASP也是做为单独的一个技术来提出的,但他就是完全继承了VB所有的功能。

莫相离 发表于 2015-2-3 23:30:40

弱类型造成潜在的出错可能:尽管弱数据类型的编程语言使用起来回方便一些,但相对于它所造成的出错几率是远远得不偿失的。

透明 发表于 2015-2-9 06:29:31

Application:这个存储服务端的数据,如果不清除,会直到web应用程序结束才清除(例如重启站点)

海妖 发表于 2015-2-27 03:42:16

以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。

小女巫 发表于 2015-3-8 19:24:07

下载一个源代码,然后再下载一个VBScript帮助,在源代码中遇到不认识的函数或是其他什么程序,都可以查帮助进行解决,这样学习效率很高。

因胸联盟 发表于 2015-3-16 12:35:01

那么,ASP.Net有哪些改进呢?

灵魂腐蚀 发表于 2015-3-22 22:59:00

哪些内置对象是可以跳过的,或者哪些属性和方法是用不到的?
页: [1]
查看完整版本: ASP网站制作之用ASP创建一个复杂的搜刮引擎