zoukankan      html  css  js  c++  java
  • Lucene 搜索引擎( ing..)

    对于搜索,按被搜索的资源类型,分为两种:可以转为文本的、多媒体类型。

    Lucene所做的是全文检索(Full-Text Retrieval),是指以文本作为检索对象,找出含有指定词汇的文本。全面、准确和快速是衡量全文检索系统的关键指标。

    关于全文检索,我们要知道:1,只处理文本。2,不处理语义。3,搜索时英文不区分大小写。4,结果列表有相关度排序。

    在信息检索工具中,全文检索是最具通用性和实用性的。

    搜索的原理基本一致.
    Whether it be a tool for searching the entire internet, a corporate intranet or a small website, the principal is the same.
    It might go something like " Find all the availabel data sources and move then into an archive, stroe the data in some soft of searchable

    format, and make a client to search this database... "
    Put more formallly the three steps are Crawling , Indexing, and Searching.

    *Crawling.  ( -> Make data heap )
      - is the process of finding all availavle data sources and storing it in some archives.

    *Indexing:  (-> Make structured data )
      - is the process in order to make the content more accessible , the data need to be stored in a structured format.

    *Searching : ( -> Get Result by Search a term )
      - is the process to do a query and get the result.

    Without a doubt the most challanging part of a search engine is the indexing.

    Indexing . (索引)
    Lucene索引过程分成三个主要的操作阶段:(1)将数据转换为文本.--> (2) 分析文本-->(3)分析过的文本保存到索引库中。

    索引中五大核心类:
    (1) IndexWriter类
      - 创建一个新的索引并且把文档加入到已有的索引中。(仅对索引进行写操作)

    (2) Directory类
      - 描述了索引存放的位置.
      - 是抽象类,有2个具体的子类. FSDirectory(文件系统的目录中创建索引文件), RAMDriectory.(内存中保存数据)
     
    (3) Analyzer类
      - 文本在被索引之前,需要进过分析器(Analyzer)的处理。
      - 应用程序在IndexWriter的构造函数中指定程序所需要使用的分析器。
      - 负责从被索引的文本文件中提取语汇单元(tokens),剔除无用信息。
      - 是抽象类,Lucene中提供他的几个具体实现类。

    (4) Document类
      - 代表一些域的(Fiield) 的集合。
      - 可以吧Document对象当成一个虚拟的文档(web页面,Email消息,文本文件),然后从中取回大量的数据。

    (5) Field 类,
      - 每个Document对象包括一个或多个域(Field).每个域对应于一段数据
      - Lucene提供四种不同的域: Keyword域,UnInexed域,UnStored域,Text域。

    Searching ( 搜索)
    搜索中的四大核心类.
    (1)IndexSearcher类.
       - 搜索之前由IndexWriter类所创建的索引.
       - 最简单的search方法是将一个Query对象作为参数,返回一个Hits对象.
          IndexSearcher is = new IndexSearcher(FSDirectory.getDirectory("/tmp/index",false));
          //查找 contents Field中包含单词"lucene"的所有文档。TermQuery 是从抽象父类Query继承而来。
         Query q = new TermQuery(new Term("contents","lucene")); 
                                                                                        
         Hits hits = is.search(q);

    (2)Term类.
        - 用于搜索的基本单元。包含了一对字符串元素. 和 Field中的name , value 相对应。

    (3) Query类
        - 抽象类,具体的子类有TermQuery, BoolearnQuery, PhraseQuery, PrefixQuery 等.
        - 其中TermQuery是最基本的查询类型。

    (4) Hits 类.
         - 是存放有序搜索结果之争的简单容器。

    参考: Lucene in Action , 并对Lucene/Nutch 的开发者 Doug Cutting 致以崇高的敬意。
    参考: Lucene Website Crawler and Indexer (作者: stlane ) 并参考其博客。

  • 相关阅读:
    微信支付:redirect-uri参数错误 的解决办法
    PHP计划任务之关闭浏览器后仍然继续执行的函数
    windows7安装phpnow Apache非管理员权限不能操作Windows NT服务的解决方法
    php 本周开始时间和结束时间;本月开始时间结束时间;上月开始时间结束时间
    图片预览
    生成随机验证码(记得下载字体文件啊)
    git ,github实际操作指南
    git,github初识命令
    博客园项目(BBS)
    django之分页器
  • 原文地址:https://www.cnblogs.com/fdyang/p/2858726.html
Copyright © 2011-2022 走看看