nzinfoCoreseek-Sphinx全文检索实践指南PH.ppt_第1页
nzinfoCoreseek-Sphinx全文检索实践指南PH.ppt_第2页
nzinfoCoreseek-Sphinx全文检索实践指南PH.ppt_第3页
nzinfoCoreseek-Sphinx全文检索实践指南PH.ppt_第4页
nzinfoCoreseek-Sphinx全文检索实践指南PH.ppt_第5页
已阅读5页,还剩37页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Coreseek/Sphinx全文检检索实实践指南 李沫南 2010-12-19 What will be covered? A Introduction of Fulltext Search Brief Compare of Open Source FT Engines Why choose Sphinx Who using Sphinx 全文检索 VS 数据库检索 SELECT * FROM documents WHERE title like %test% CPU 100% 30秒内只能进行一次查询 没有找到记录. 如何解决? 为了提升数据库的性能,在某些字段上建索引 答案:在全文字段上加索引 数据库的全文索引 全文索引字段,数据库的标配功能 MySQL / PostgreqSQL SQL Server / Oracle 问题 : 影响记录的存取性能 非标准的检索语法 切分规则? 排序规则? Too slow while indexing real-world dataset No Magic 倒排索引 比普通数据库检 索快几倍几百倍的性能提升 预读 取、预切分 想想新华字典 倒排索引(反向索引) Term1 Doc1(pos1, pos2, pos.), Doc2, Doc3 正向索引 Doc1 Term1(pos1, pos2, pos .) 全文检索技术的宗教传统 线上的查经 工具 /search.aspx 哥林多前书 13:8 “爱是恒久忍耐、又有恩慈爱是 不嫉妒爱是不自夸不张狂“ 倒排索引历史 主后1230年,根据拉丁文 圣经 编制 主持者 Hugo de Sancto Charo 雨果 参与着 500 多人 主后1550年,第一部英文的词索引 编者 John Marbeck 计算机出现后,计算机辅助编制索引 7080年代,MAT程序族 圣经倒排索引的假设 所有词语 具有一样的重要性 不考虑词语 出现的先后顺序 分章、分节 不考虑排序(按照出现的先后顺序排序) 全文检索的最简化模型 Word Of Bag 把文档作为一个口袋 Term是口袋中的元素 假设元素之间 地位平等 顺序无关 独立分布 Boolean 检索 非此即彼的二元世界观 a AND b,a OR b, a NOT b 全文检索 向量空间模型 把文档视为 一个向量 Document Vector = term1, term2, termN Query Vector = term1, term2 全文检索 概率模型 TF/ IDF 算法 Okapi BM25 (BM = Best Match) Phrase Ranking 向量空间模型的优缺点 优点 考虑到了Term出现的频率 相对更好的相关度排序 缺点 不适合处理超长文件 或者同一集合上,文件长度的尺寸差距很大 检索的Term必须完全匹配 不考虑语用(同义词、近义词) CJK 短语支持. 其他的模型? 开源检索系统的对比分析 开源传万世,因有我参与 常见开源的全文检索系统一览 Lucene / Nutch / SolrAPL Sphinx / CoreseekGPL/商业授权 XapianGPL Lemur (支持Language Model)BSD 非主流 Zettair Terrier 如何评价检索系统? 检索精度(F-Score) 查全率、查准率(相关度) 可以处理的数据规模、系统架构 使用的检索模型(概率向量空间语言) 特性: 字段检索、自定义排序、属性过滤 正向索引?反向索引?分布式支持 接口的丰富程度 业务的其他需要 没有圣杯! Why I choose Sphinx Terabyte Index 良好的文档支持 与LAMP软件栈紧 密集成 唯一可选的C/C+检索系统(2006) Lucene 不适用于复杂检 索(2006) I hate Java Sphinx (Coreseek)特性介绍绍(1) 高速建立索引; 丰富的查询 表达式(AND OR NOT 句子 段落 模糊 字段) 多种结果后处理机制(Group By, Order By, Custom Weighting) 在生产环 境中,千万篇文档,Tb级索引,数千 查询 /秒 Sphinx(Coreseek) 特性介绍绍(2) easy integration with SQL and XML data sources, and SphinxAPI, SphinxQL, or SphinxSE search interfaces; easy scaling with distributed searches. Python data source adapter layer Build-in Chinese Tokenizer Coreseek(Sphinx) VS Lucene Coreseek (Sphinx) 开箱即用的产品 (LAMP) 支持各种数据来源(via Python Source) 内置中文分词(.) 商业支持 Lucene Java 人力成本低 库结构设计,修改容易 第三方工具? 分布式? Sphinx VS Lucene Faster Indexing Faster, more relevant searching SQL style queries We can do Java, but dont require a Java stack. RT-Index VS. In memory Index Sphinx 优势优势 BM25 Ranker phrase base ranking Boosts (sub) phrase matches Perfect match is guaranteed to be ranked #1 内置Grouping、分布式支持 Sphinx 限制 20 G , Per-single Index CRC64 WordID Field Mask, Only 24 Field Supported All attributes in memory! Poor windows support No inner cache support Hard to handle more than 3T data 吹牛时间(酒精考验的Sphinx) B 3KW 文档, 1M+ query/day 2030GB docs, 50M+ query/day 国内的实施 ChinaUnix Blogbus 51CTO 金融街BBS Many site I never seen,due to Open Source ;-) 某档案馆检索(Tb) A Short Break Indexer 的流程 1.读取数据 从数据库中读取 用户主动Push (RTIndex) 2.Tokenizer 西文 (词根、缩写的解读) CJK (切分) 3.建立倒排索引 局部倒排 合并 Check The Index Use Search utility to query a index in cli Use index_tool to dump a index 索引文件格式(简介) .spi: Dictionary (the complete list of wordids) .spa: Attributes (only if docinfo=extern) .spd: Document lists (for each keyword) .spp: Hit lists (for each keyword) .spm: MVA values How Searching works For each local index Build a list of candidates (documents that satisfy the full-text query) Filter (the analogy is WHERE) Rank (compute the documents relevance values) Sort (the analogy is ORDER BY) Group (the analogy is GROUP BY) Merge the results from all the local indexes SQL 数据源:处处理流程 Connected to the database Pre-query* : initial setup Main query : feed data Post-query : cleanup Disconnected Sorting Connect to preform post-index $cl-SetSortMode ( SPH_SORT_EXTENDED, “price desc” ); $res = $cl-Query ( “ipod nano”, “products” ); var_dump ( $res ); ? Demo Result PHP Client Side Matches will always have document ID, weight Matches can also have numeric attributes * No string attributes yet (pull them from MySQL) print_r ( $result“matches”0 ): Array ( id = 123 weight = 101421 attrs = Array ( group_id = 12345678901 added = 1207261463 ) ) DB Vs. Sphinx Who take the job? SQL query parts that can be moved to Sphinx Filtering WHERE vs. SetFilter() or fake keyword Sorting ORDER BY vs. SetSortMode() Grouping GROUP BY vs. SetGroupBy() Up to 100x (!) improvement vs. “nave” approach Rule of thumb move everything you can from MySQL to Sphinx Sphinx Searching pipeline Search, WHERE, rank, ORDER/GROUP “Cheap” boolean searching first Then filters (WHERE clause) Then “expensive” relevance ranking Then sorting (ORDER BY clause) and/or grouping (GROUP BY clause) Group By (1) SetGroupBy SetGroupDistinct Group By SetGroupBy(2) function SetGroupBy ( $attribute, $func, $groupsort=“group desc“ ) $attribute: read which attribute $func: 加工 $attribute SPH_GROUPBY_DAY|WEEK|MONTH|YEAR SPH_GROUPBY_ATTR $groupsort: Sort the grouping order. Group By SetGroupDistinct(3) function SetGroupDistinct ( $attribute ) $cl-SetGroupBy ( “category“, SPH_GROUPBY_ATTR, “count desc“ ); $cl-SetGroupDistinct ( “vendor“ ); SELECT id, weight, all-attributes, COUNT(DISTINCT vendor) AS distinct, COUNT(*) AS count FROM products GROUP BY category ORDER BY count DESC 结果高亮(BuildExcerpts) function BuildExcerpts ( $docs, $

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论