使用索引服务器

2008-04-09 04:02:14来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

使用索引服务器的对象

  你可以象使用其它数据库一样使用索引服务器,也就是Index Server,它是IIS4中包含的内容索引引擎。你可以对它进行ADO调用并搜索你的站点,它为你提供了一个很好的web 搜索引擎。

  它非常容易使用。你只需要声明对象,然后对引擎进行调用,然后引用你所请求的属性、栏和值。

  那么,怎样做以上这些工作呢?

  设置提示用户进行输入的表单页面,这个页面将被传递到索引服务器引擎。设置查询引擎的页面并显示结果测试。

  下面来看看swynk.com 在左栏搜索工具中使用的代码。

创建表单

  这个表单非常简单。这是你的基本HTML表单,增加了一些隐含域,这些域将帮助驱动某些搜索引擎特性。


$#@60;form method="get" action="/sitesearch/sitesearch.asp" id=form1 name=form1$#@62;
$#@60;!-- search text --$#@62;
$#@60;table width="100%"$#@62;
$#@60;tr width="100%" bgcolor="Black"$#@62;
$#@60;td width="100%"$#@62;
$#@60;font color="White"$#@62;
$#@60;b$#@62;Search$#@60;/b$#@62;
$#@60;/font$#@62;
$#@60;/td$#@62;
$#@60;/tr$#@62;
$#@60;/table$#@62;
$#@60;input type="text" name="qu" size="20"$#@62;$#@60;br$#@62;

$#@60;!-- max hits --$#@62;
$#@60;input type="hidden" name="mh" value=50$#@62;
$#@60;!-- sort by hits --$#@62;
$#@60;input type="hidden" name="sd" value="Hitcount"$#@62;
$#@60;!-- allow enumeration --$#@62;
$#@60;input type="hidden" name="ae" value="1"$#@62;
$#@60;!-- catalog --$#@62;
$#@60;input type="hidden" name="ct" value="c:\inetpub\www07120\index\"$#@62;
$#@60;input type="submit" value="Find It!" name="Search"$#@62; $#@60;a href="/sitesearch/searchhelp.asp"$#@62;$#@60;font size=-1$#@62;Help$#@60;/a$#@62;$#@60;/font$#@62;
$#@60;/form$#@62;


  如果你将设置的表单与你在这个页面左边看到的搜索相比较,你就能发现域是从那里引入的,“找到了”按钮在哪里显示。以下是域的简要解释:

◆ mh是你想要返回的点击数的最大值。例如,你可能愿意将这个值设为200。将这个值设置得太高会给服务器带来不必要的负担。如果这个值太低就不能返回足够多的有意义的结果。要确定你的站点的最佳值需要花费一些脑筋(这种情况听起来有点象SQL中的"Set rowcount=", 不是吗)。

◆ sd是你想用做分类值的栏的名。在这种情况下,我们是在调出点击值栏--首先我们显示在搜索中点击最多的页面,然后按照降序排列结果设置(D代表降序)--同SQL中的"Order By..."一样,就是打开结果设置的列举。

◆ ct指向在哪里找到了将要使用的目录或索引数据库。这里有一点技巧。当你为某一给定站点打开索引服务器时,你就要指出索引数据库在什么位置。你必须要将这个值指向这个位置,否则索引服务器就会返回一个结果NO。(这是FROM数据库)

  随后,当然是调用将要取走这些值并查询服务器的ASP页面。注意,这是在使用表单处理中的GET类型-稍后将对此多做介绍,但是,只要你在使用我们的样本页面,就必须要用到它。

创建ASP页面

  在ASP页面上一切都变得非常酷。你用表单中的值来驱动对索引服务器进行查询的对象。

整个过程是这样的:

◆ 打开记录集。
◆ 用标准ADO 方法,一步步地走过记录集。

$#@60;%
"Create a Query object, initialize it using
"SetQueryFromURL, and dump the object state

"set the query object
Set objQuery = Server.CreateObject("ixsso.Query")

"get the query properties set from the
"incoming URL (from the form GET operation)
objQuery.SetQueryFromURL(Request.QueryString)

"tell the object what columns to include
objquery.columns="filename,HitCount,vpath,DocTitle,characterization"

"open the recordset, causing the query to be
"executed
set rsQuery = objquery.createrecordset("nonsequential")

"now, if rsquery.eof is not TRUE, then we have results
"to show. If it IS TRUE, no results were found.

"get the page out for the user...
%$#@62;

$#@60;html$#@62;
$#@60;head$#@62;
$#@60;/head$#@62;

$#@60;h1$#@62;Search Results$#@60;/h1$#@62;
A maximum of 200 results will be returned, 20 hits per page will be shown. $#@60;br$#@62;$#@60;br$#@62;
$#@60;%
if not rsquery.eof then
Response.Write rsquery.recordcount & " hit(s) were found. "
if rsquery.recordcount $#@62; 30 then
Response.Write "You may want to refine your query."
end if
Response.Write "$#@60;br$#@62;"
end if
%$#@62;

$#@60;%
if not rsquery.eof then
while not rsquery.eof and rowcount $#@62; 0
if rsquery("doctitle") $#@60;$#@62; "" then
Response.Write "$#@60;p$#@62;$#@60;b$#@62;$#@60;a href="" & rsquery("vpath") & ""$#@62;" & rsquery("doctitle") & "$#@60;/a$#@62;$#@60;/b$#@62;$#@60;br$#@62;"
response.write "$#@60;font size=-1$#@62;" & rsquery("characterization") & "...$#@60;/font$#@62;$#@60;Br$#@62;"
Response.Write "$#@60;font size=- 2$#@62;" & rsquery("hitcount") & " hit(s)$#@60;/font$#@62;$#@60;/p$#@62;"

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:怎样培养软件工程的思维与方法

下一篇:中间件的优点及其应用

热门词条
热门标签