freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

基于lucene的全文搜索引擎設(shè)計(編輯修改稿)

2025-01-09 01:01 本頁面
 

【文章內(nèi)容簡介】 URIs have been discovered) ( 2)正在被處理的 URI( URIs are being processed (fetched)) ( 3)已經(jīng)處理的 URI( URIs have been processed) TeoThread(處理線程 ): Heritrix 是多線程的,每一個 URI 被一個 ToeThread 處理。 Processor(處理器 ): 11 圖 8 處理器的整個結(jié)構(gòu)圖 許多 Processor 組成一個處理鏈( processor chains)中 ,每一個處理鏈對 URI 進行一系列的處理。 (1)Prefetch processing chain(預(yù)處理鏈 ):主要根據(jù) robot 協(xié)議, DNS 以及下載范圍控制信息判斷當前 URI 是否應(yīng)當處理。 (2)Fetch processing chain(抓取處理鏈):從遠程服務(wù)器獲取數(shù)據(jù) (3) Extractor processing chain(抽取處理鏈):從網(wǎng)頁中抽取新的 URI (4)Write/index processing chain(寫處理鏈):負責把數(shù)據(jù)寫入本地磁盤 (5)Postprocessing chain(后置處理鏈):由 CrawlStateUpdater , LinksScoper ,F(xiàn)rontierScheduler 構(gòu)成。 網(wǎng)頁分析與提取模塊 在提取網(wǎng)頁數(shù)據(jù)的時候,是使用 Java 庫 —— HtmlParser 來提 取網(wǎng)頁信息的。 HtmlParser采用了經(jīng)典的 Composite 模式,通過 RemarkNode、 TextNode、 TagNode、 AbstractNode和 Tag 來描述 HTML 頁面各元素。 12 圖 9 htmlparser 對 html頁面處理的數(shù)據(jù)結(jié)構(gòu) 索引建立模塊 使用 Lucene 建立索引,主要使用到 Document, Field, IndexWriter 等幾個類和接口。 Document 在 Lucene 中代表一種邏輯文件。 Lucene 本身無法對物理文件建立索引,而只能識別并處理 Document 類型的文 件。在某些時候可以將每個 Document 與一個物理文件進行對應(yīng),用一個 Document 來代替一個文件,然而更多時候, Document 和物理文件沒有關(guān)系,它是作為一種數(shù)據(jù)源的集合,向 Lucene 提供原始的要索引的內(nèi)容。 Lucene從 Document 取出相關(guān)的數(shù)據(jù)源,并根據(jù)屬性配置進行相應(yīng)的處理 。 圖 10 Document 與多個文件的數(shù)據(jù)源 在 Lucene 中,數(shù)據(jù)源是由一個被稱為 Field 的類來表示的。通常情況下可以直接通過Document 文件名 文件名 文件名 文件名 物理文件 物理文件 物理文件 物理文件 13 Field 的構(gòu)造函數(shù)來創(chuàng) 建一個 Field 類型的對象。這個 Field 類型主要是用來標識當前的數(shù)據(jù)源的各種屬性,存儲來自數(shù)據(jù)源的數(shù)據(jù)內(nèi)容。 Lucene 在對每個 Field 進行處理時,會充分考慮到數(shù)據(jù)源的各種屬性,以此做出不同的處理。 圖 11 Document 與 Field 的關(guān)系 在用戶構(gòu)建完 Document 并為其加入合適的 Field 后,就需要 Lucene 來為其建立索引了。在 Lucene 中, IndexWriter 主要作用是對索引進行創(chuàng)建,加入 Document,合并各種索引斷,以及 控制與索引相關(guān)的各方面,它是 Lucene 的索引的主要操作者。 初 始 化 一 個 分 析 器 對 象 , 作為 參 數(shù) 傳 入 W r i t e r傳 入 建 立 索 引 的 路 徑 , 即 用戶 希 望 建 索 引 建 立 的 位 置為 該 目 錄 上 寫 鎖用 戶 希 望 把 索 引 目 錄 下 原 來 的 內(nèi) 容 刪 去 嗎 ?創(chuàng) 建 新 的 s e g m e n t s 文 件 , 并 寫入 版 本 號 , 修 改 次 數(shù) 等 信 息讀 取 原 來 的 s e g m e n t s 文 件 , 讀出 版 本 號 , 段 信 息 等W r i t e r 對 象 初 始 化 完 畢YN 圖 12 IndexWriter 的初始化過程 Lucene Document Field Field Field 14 Web 搜索模塊 Lucene 里面與搜索相關(guān)的 API 多數(shù)都被包含在 包中。其中,最重要的是 IndexSearcher 類。 IndexSearcher 在執(zhí)行其任何操作前,必須獲得一個索引目錄。 搜索代碼如下: //初始化一個 IndexSearcher IndexSearcher searcher = new IndexSearcher( //構(gòu)建一個 Term對象 Term term = new Term(bookname,女 )。 //構(gòu)建一個 Query對象 Query query = new TermQuery(term)。 //檢索 Hits hits = (query)。 //顯示查詢結(jié)果 for(int i = 0。i()。i++){ ((i))。 } 在上面的代碼中還涉及到兩個類: Query 類和 Hits 類。 Query 便是一個查找請求。此處使用 TermQuery 類對其進行初始化,它表示查找“ bookname”域中,包含“女”這個關(guān)鍵字的文檔。 Hits 表示查找結(jié)果。通過它可以訪問檢索到的 Document。 當用戶進去搜索主頁,并進行搜索的時候,時序圖如下: 15 圖 13 搜索時序圖 ProductsDao:實體 Products 的數(shù)據(jù)庫操作接口,負責將數(shù)據(jù)信息寫入,修改,刪除,查找。 SearchDao:索引的操作接口 ,負責根據(jù)關(guān)鍵字從索引中搜索出對象 Product 的 Id。 SearchService:整個 Web 服務(wù)的接口,負責調(diào)用 ProductDao 和 SearchDao。 4 詳細設(shè)計 Web 爬蟲的配置和擴展 作為一個優(yōu)秀的網(wǎng)頁抓取軟件, Heritrix 的優(yōu)點在于可以 自定義 Heritrix 的抓取任務(wù)和擴展它的功能使之能夠適合我們要展開的抓取任務(wù)。 所以我們要通過擴展FrontierScheduler 來抓取特定的內(nèi)容。 FrontierScheduler 是一個 PostProcessor,它的作用是將在 Extractor 中所分析得出的鏈接加入到 Frontier 中,以待繼續(xù)處理。 擴展FrontierScheduler 需要繼承 這個類,并且重寫 schedule 這個方法。 public class FrontierSchedulerForYouMoblie extends FrontierScheduler { private static final long serialVersionUID = 8835919182532315927L。 @SuppressWarnings(unused) 16 private static Logger LOGGER = Logger .getLogger(())。 // 構(gòu)造函數(shù) public FrontierSchedulerForYouMoblie(String name) { super(name)。 } protected void schedule(CandidateURI caUri) { // 取得 URL的字符串 String url = ()。 try { // URL選擇策略 if (() != 1 || () != 1 || () != 1 || (dns:) != 1) { getController().getFrontier().schedule(caUri)。 } else { return。 } } catch (Exception e) { ()。 } finally { } } } 以上代碼就是我們擴展的 FrontierScheduler 使得 Heritrix 只能抓取站點 。對于以外的內(nèi)容是不會被抓取下來的。 當 擴展完畢的時候,還要在 Heritrix 的模塊配置文件 添加聲明自定義配置 |FrontierSchedulerForYouMoblie 網(wǎng)頁的分析與數(shù)據(jù)提取 對于本檢索系統(tǒng),主要是將手機產(chǎn)品信息做為數(shù)據(jù)信息提供給使用者搜索,并返回相關(guān)產(chǎn)品信息 。所以當我們要對抓取下來的網(wǎng)頁進行分析提取數(shù)據(jù)的時候主要是手機的相關(guān)信息。比如:手機的圖片,手機的參數(shù)還有就是產(chǎn)品的連接。根據(jù)頁面信息設(shè)計了兩個類用于從頁面中提取我們需要的信息。 17 圖 14 網(wǎng)頁信息提取類圖 如上圖所示, Extractor 是一個抽象類, 里面有一個抽象方法 extract。對于不同的網(wǎng)頁結(jié)構(gòu)我們需要提取不同的數(shù)據(jù),就需要不同的實現(xiàn)方式。所以類 ExtractYouMobile繼承 Extractor 并實現(xiàn)抽象方法,實現(xiàn)對網(wǎng)頁信息的提取。 18 開 始結(jié) 束定 義 標 題 節(jié)點 過 濾 器使 用 解 析 器 迭代 遍 歷 節(jié) 點是 否 找 到 相 應(yīng) 節(jié) 點N將 節(jié) 點 內(nèi) 容 寫入 文 件Y 圖 15 標題節(jié)點內(nèi)容提取流程 圖 public void extract() { BufferedWriter bw = null。 //定義三個過濾器 NodeFilter title_filter = new AndFilter(new TagNameFilter(div), new HasAttributeFilter(class, mo_tit))。 NodeFilter attribute_filter = new AndFilter(new TagNameFilter(p), new HasChildFilter(new AndFilter(new TagNameFilter(span), new HasAttributeFilter(class, gn_sp1 blue1))))。 NodeFilter img_filter = new AndFilter(new TagNameFilter(span), new HasChildFilter(new TagNameFilter(img)))。 // 提取標題信息 try { // Parser 根據(jù)過濾器返回所有滿足過濾條件的節(jié)點 // 迭代逐漸查找 NodeList nodeList = ().parse(title_filter)。 NodeIterator it = ()。 StringBuffer title = new StringBuffer()。 while (()) { Node node = (Node) ()。 String[] names = ().split( )。 for (int i = 0。 i 。 i++) (names[i]).append()。 (new Date().getTime())。 // 創(chuàng)建要生成的文件 bw = new BufferedWriter(new FileWriter(new File(this .getOutputPath() 19 + title + .txt)))。 // 獲取當前提取頁的完整 URL 地址 int startPos = ().indexOf(mirror) + 6。 String url_seg = ().substring(startPos)。 url_seg = (\\\\, /)。 String url = :/ + url_seg。 // 寫入當前提取頁的完整 URL 地址 (url + NEWLINE)。//產(chǎn)品地址 (names[0] + NEWLINE)。//品牌 (names[1] + NEWLINE)。//型號 } // 重置 Parser ().reset()。 Parser attNameParser = null。 Parser attValueParser = null。 //定義兩個過濾器,屬性過濾器和值過濾器 NodeFilter attributeName_filter = new AndFilter(new TagNameFilter( span), new
點擊復(fù)制文檔內(nèi)容
研究報告相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1