用Java+MySQL+PHP輕鬆構建跨平台的搜尋引擎

來源:互聯網
上載者:User

此搜尋引擎適於在一個中等規模的區域網路中使用,由於找到的網頁存在資料庫中,不僅可以索靜態Html頁面,可以搜尋PHP、ASP等動態網頁面。對於一個擁有5萬個網頁的系統(使用PII-400作為伺服器),搜尋回應時間在2-10秒左右,完全可以滿足要求,由於Java、mysql、PHP都是跨平台的軟體,所以此搜尋引擎不僅可以工作在Windows伺服器上,而且也可以工作在Linux等其他系統中。

一、建立搜尋引擎需要的資料庫和資料表。

首先建立資料庫:

c:\mysql\bin\> mysqladmin -uroot -pmypasswd create Spider

然後建立資料庫中的表結構

c:\mysql\bin\> mysql -uroot -pmypasswd Spider < Spider.mysql

其中Spider.mysql為一個文字檔,其內容如下:

CREATE TABLE link (
Id int(10) unsigned NOT NULL auto_increment,
Url varchar(120) NOT NULL,
Class tinyint(3) unsigned NOT NULL default 0 ,
IsSearchLink tinyint(3) unsigned default 0,
PRIMARY KEY (Url),
UNIQUE Id (Id),
KEY Url (Url),
KEY Class (Class)
);

# 本區域網路的初始首頁地址,搜尋蜘蛛從此網址開始搜尋所有其他網頁

INSERT INTO link VALUES( '1', 'HTTP://102.211.69.1/', '0', '0');

# 資料表 webpagelocal 用來存放下載的所有的網頁

CREATE TABLE webpagelocal (
Id int(10) unsigned NOT NULL auto_increment,
Url varchar(120) NOT NULL,
Content text NOT NULL,
PRIMARY KEY (Url),
UNIQUE Id (Id),
KEY Url (Url)
);

# 資料表 webpagefindfast

# 用MakeFast.php從表webpagelocal中提取512位元組的檢索資訊存放其中

CREATE TABLE webpagefindfast (
Id int(10) unsigned NOT NULL,
Url varchar(120) NOT NULL,
Title varchar(64),
Content blob,
PRIMARY KEY (Url),
KEY Url (Url),
KEY Title (Title)
);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.