用ASP建立一个简单的搜索引擎

搜索引擎

By Scott Mitchell

As a web site grows, finding content on the site becomes increasingly difficult. To combat the difficulty
of finding relevant information on a large site, many developers turn to writing a search engine for their
site. This article discusses how to implement such a system using Active Server Pages and SQL Server.

There are two "types" of search engines. Both take a search string from the user to begin, but what,
exactly, they search differs. A completely dynamic search engine for a completely dynamic web site will
hit a database table which ties an article URL to the articles description. The database can then compare
the user's search request to the descriptions of the available articles and return the relevant URLs.

Another approach is to do an actual text search through each of the files. For example, say that the user
searched for "Microsoft." Your search engine would then look through all of your HTML files and return the
URLs of those which had the word "Microsoft" somewhere in the document. Such a system is used for this web
site's search engine. In my opinion, it is much easier to write such a system described in Perl (which
this system is written in), than in Active Server Pages; however, it is quite possible to write a text-
finding search system in ASP.

In this article I plan to implement the former search engine, the dynamic search engine. For this example
I will make a table called ArticleURL, which will have the following definition:

ArticleURL
ArticleURLID int PK
URL varchar(255)
Title varchar(100)
Description varchar(255)

Now that we've got our table definition, let's look at how our web visitors will enter their queries.

Search Querying
A search engine is rather useless unless queries can be made, and the results are returned. Let's examine
how we will code the first needed part, the user search requests. All we will need is a simple HTML FORM
which takes input from the user and passes it on to an ASP page. Here is an example of a file we'll call
SearchStart.htm:

<HTML>
<BODY>

<FORM METHOD=POST ACTION="Search.asp&ID=0">
> Search for: <INPUT TYPE=TEXT NAME="txtSearchString" SIZE="50">
<P>
<INPUT TYPE=SUBMIT>
</FORM>

</BODY>
</HTML>
This, of course, is not a pretty HTML page, but its functionality is there. There are many things which
could be done to enhance this page. It is recommended that JavaScript functions be present to make sure
the user is searching something (i.e. not just clicking Submit when there is no search string).

Now that we have the Query, we need to look at the second phase of any search engine: retrieving the data
and presenting it to the user. Here is where the real fun begins!

Retrieving the Data and Presenting It:
Our ASP page Search.asp must do a few steps. First, it must parse the FORM variable txtSearchString. Right
now, I am assuming that each word in the txtSearchString separated by a space will be ANDed together. You
can alter this (have it ORed), or, to make it more professional, you can give the user the option of which
boolean to put inbetween each spaced word.

Next, Search.asp will need to hit the database table ArticleURL and return the data in a user-friendly
fashion. Also, we will want to display the results only 10 records at a time, so logic will need to be
implemented to handle this as well. Let's look at some code.

<%

'Connect to Database
Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open Application("MyConnectString")

'Set these up to your preference
DefaultBoolean = "AND"
RecordsPerPage = 10

'Get our form variable
Dim strSearch
strSearch = Request.form("txtSearchString")

'Get our current ID. This let's us know where we are Dim ID
ID = Request.QueryString("ID")

'Set up our SQL Statement
Dim strSQL, tmpSQL
strSQL = "SELECT * FROM ArticleURL WHERE "
tmpSQL = "(Description LIKE "

'OK, we need to parse our string here
Dim Pos
Pos = 1
While Pos > 0
Pos = InStr(1, strSearch," ")
If Pos = 0 Then
'We have hit the end
tmpSQL = tmpSQL &a

时间: 2024-07-28 15:57:27

用ASP建立一个简单的搜索引擎的相关文章

用ASP建立一个简单的聊天室

聊天室|聊天室     经过一个阶段的asp学习,下面我们结合所学过的内容建立一个最简单的聊天室,虽然很简单,但是大家可以通过他来掌握一个聊天室建立的基本过程,并且可以不断的完善其功能. 下面介绍其主要步骤: 1,添加Global.asa文件里面的代码.这部分代码主要处理Application_onStart事件,在此事件中,定义了一个有15个元素的数据,并把它赋给了一个Application对象的属性.Global.asa文件的内容如下. <SCRIPT LANGUAGE="VBScri

ASP建立一个简单的聊天室_应用技巧

经过一个阶段的asp学习,下面我们结合所学过的内容建立一个最简单的聊天室,虽然很简单,但是大家可以通过它来掌握一个聊天室建立的基本过程,并且可以不断的完善其功能.下面介绍其主要步骤: 1,添加Global.asa文件里面的代码.这部分代码主要处理Application_onStart事件,在此事件中,定义了一个有15个元素的数据,并把它赋给了一个Application对象的属性.Global.asa文件的内容如下. <SCRIPT LANGUAGE="VBScript" RUNA

如何使用SQLyogEnt来建立一个简单的数据库

如果你选择PHP进行网站建设,那你必须懂得php建立数据库,那用mysql数据就是必须的了.刚接触php的朋友也许对这个mysql数据库很陌生,但如果有一款非常好用的数据库管理工具,那是用起来就方便多了,笔者几天就向大家介绍一款mysql的管理工具SQLyogEnt,笔者是用的 SQLyogEnt是英文版,目前好像没有中文版,由于功能强大,所以SQLyogEnt很受PHP用户的喜爱,接下就用实例来讲解下如何使用 SQLyogEnt来建立一个简单的数据库. 今天我建立的数据库名叫"mydb&quo

Ultradev实例教程:2.1 建立一个简单的access数据库

access|教程|数据|数据库 第二章:设置数据库 第一节.建立一个简单的access数据库 这一节我们将学习有关数据库创建的内容,用过Access创建数据库的朋友可以略过不看. 打开Microsoft Access,选择 文件 -〉新建数据库,然后选择一个位置保存你的数据库文件,这里我们按它默认的db1.mdb命名保存. 保存数据库后我们看到的是下面的界面,双击使用设计器创建表,开始创建一个数据表.我们这里的应用你只需照着步骤一步步做下去,即使你以前从没接触过数据库也没有问题,如果你想做深层

使用Java开源工具建立一个灵活的搜索引擎

为应用程序添加搜索能力经常是一个常见的需求.本文介绍了一个框架,开发者可以使用它以最小的付出实现搜索引擎功能,理想情况下只需要一个配置文件.该框架基于若干开源的库和工具,如 Apache Lucene,Spring 框架,cpdetector 等.它支持多种资源.其中两个典型的例子是数据库资源和文件系统资源.Indexer 对配置的资源进行索引并传输到中央服务器,之后这些索引可以通过 API 进行搜索.Spring 风格的配置文件允许清晰灵活的自定义和调整.核心 API 也提供了可扩展的接口.

函数计算-建立一个简单的数学计算函数场景

Serverless作为一种微服务是一种概念,Serverless允许你提供代码或可执行程序提交给云厂商的解析服务(如阿里云的FunctionComputer等),由解析服务来为你执行它们,而你无需自己管理服务器.配置环境.Web环境等.这就是所谓的执行即服务execution-as-a-service,这样的一种概念听起来非常吸引人,实际上也可以算是一场革命,引用一张经典图轨迹图,让大家看看整个IT运维运行的发展轨迹,如下图: 图解:犹如我们从爬行动物猩猩一样,最初靠两只手和两只脚慢慢的挪动,

用Dreamweaver MX建立一个简单的图书查询系统

dreamweaver|查询系统 最近公司为了充分利用图书资源,方便员工查询,决定在公司内部网上建立一个图书查询系统.考虑到公司图书不多,只有1千多册,且专业书居多的特点,我决定做两个查询条件:一个是根据图书类别来查询,用户只要选择相应的类别就可以显示出该类别的所有图书,这主要是面对对公司图书不熟悉的人:第二个是根据图书名称来查询,用户只要输入图书名,就可以快速的搜索到符合条件的所有图书. 方案已定,接下来就是用什么软件做及如何做的问题了.在这里,我选用了网页的形式,这样同事们只要打开浏览器,输

用Dreamweaver MX建立一个简单的图书查询系统(2)

dreamweaver|查询系统 三.制作按类别查询显示的页面 1.新建一动态网页,取名xianshi.asp. 2.建立记录集.选择Application面板中的Bindings标签,按加号按钮,选择Recordset(Query),弹出Recordset对话框,里面的设置如图13,名字为Recordset2,数据库表选择tushu,因为网页显示的图书信息是根据前面查询条件来显示的,因此就需要设置一个限制条件来选择符合条件的图书,那么这个条件是通过什么来实现传递和接受的呢?这就需要用到URL

用Dreamweaver MX建立一个简单的图书查询系统(1)

dreamweaver|查询系统 最近公司为了充分利用图书资源,方便员工查询,决定在公司内部网上建立一个图书查询系统.考虑到公司图书不多,只有1千多册,且专业书居多的特点,我决定做两个查询条件:一个是根据图书类别来查询, 用户只要选择相应的类别就可以显示出该类别的所有图书,这主要是面对对公司图书不熟悉的人:第二个是根据图书名称来查询,用户只要输入图书名,就可以快速的搜索到符合条件的所有图书.  方案已定,接下来就是用什么软件做及如何做的问题了.在这里,我选用了网页的形式,这样同事们只要打开浏览器