




已阅读5页,还剩22页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Compass案例文档目录一、原理描述:二、术语解释:三、下载地址:四、使用流程: .五、基于SSH的compass的实例: 一、原理描述:Compass是一流的开放源码JAVA搜索引擎框架,对于你的应用修饰,搜索引擎语义更具有能力。依靠顶级的Lucene搜索引擎,Compass 结合了,像 Hibernate和 Spring的流行的框架,为你的应用提供了从数据模型和数据源同步改变的搜索力.并且添加了2方面的特征,事物管理和快速更新优化. Compass的目标是:把java应用简单集成到搜索引擎中.编码更少,查找数据更便捷 .二、术语解释:名称描述Lucene Apache Lucene是一个基于Java全文搜索引擎,利用它可以轻易地为Java软件加入全文搜寻功能。Lucene的最主要工作是替文件的每一个字作索引,索引让搜寻的效率比传统的逐字比较大大提高了,Lucene提供一组解读,过滤,分析文件,编排和使用索引的提供一组解读,过滤,分析文件,编排和使用索引的API,它的强大之处除了高效和简单外,是最重要的是使使用都是可以随时应自己需要自订其功能。开发者可以把Lucene看成一个支持全文索引的数据库系统的.Compass我对Compass的定义是面向域模型的搜索框架, 面向域模型意味着必须支持对对象的搜索,对持久化对象的搜索,和对XML文档对象的搜索,同时还必须支持事务的处理,包括对创建,更新,保存,删除进行事务级别的处理. 所以, Compass是基于Lucene, 高于Lucene的. 有个形象的比喻. Compass对于Lucene就像Hibernate对于JDBC,太有才了!Compass的开发路数完全参照Hibernate.OSEM对象搜索引擎影射(Object Search Engine Mapping),通过xml配置文件,提供了POJOs (Plain Old Java Objects)到搜索引擎.三、下载地址:软件名称下载地址软件描述Compass框架、jar包/基于Java的搜索引擎四、使用流程:网络机器人程序www文档网络机器人程序建立索引从数据库中搜索信息Tomcat服务器JSP 索引数据库浏览器浏览器五、基于SSH的compass的实例:step1 在ssh2的基础上开发 加入jar包(compass-2.1.2.jar compass-index-patch.jar lucene-analyzers-2.4.0.jar lucene-core-2.4.0.jar lucene-highlighter-2.4.0.jar paoding-analysis.jar ) step2 先来看下实体bean的编写 Java代码 1. packagecom.v512.example.model; 2. pass.annotations.*; 3. /* 4. *Productentity. 5. * 6. *authorMyEclipsePersistenceTools 7. */8. Searchable9. publicclassProductimplementsjava.io.Serializable 10. 11. /Fields 12. 13. SearchableId14. privateStringid; 15. SearchableProperty(name=name,index=Index.ANALYZED,store=Store.YES) 16. privateStringname; 17. SearchableProperty(name=price,index=Index.NOT_ANALYZED,store=Store.YES) 18. privateDoubleprice; 19. SearchableProperty(name=brand,index=Index.ANALYZED,store=Store.YES) 20. privateStringbrand; 21. SearchableProperty(name=description,index=Index.ANALYZED,store=Store.YES) 22. privateStringdescription; 23. 24. /Constructors 25. 26. /*defaultconstructor*/27. publicProduct() 28. 29. 30. /*fullconstructor*/31. publicProduct(Stringname,Doubleprice,Stringbrand,Stringdescription) 32. =name; 33. this.price=price; 34. this.brand=brand; 35. this.description=description; 36. 37. 38. /Propertyaccessors 39. 40. publicStringgetId() 41. returnthis.id; 42. 43. 44. publicvoidsetId(Stringid) 45. this.id=id; 46. 47. 48. publicStringgetName() 49. ; 50. 51. 52. publicvoidsetName(Stringname) 53. =name; 54. 55. 56. publicDoublegetPrice() 57. returnthis.price; 58. 59. 60. publicvoidsetPrice(Doubleprice) 61. this.price=price; 62. 63. 64. publicStringgetBrand() 65. returnthis.brand; 66. 67. 68. publicvoidsetBrand(Stringbrand) 69. this.brand=brand; 70. 71. 72. publicStringgetDescription() 73. returnthis.description; 74. 75. 76. publicvoidsetDescription(Stringdescription) 77. this.description=description; 78. 79. 80. package com.v512.example.model;import pass.annotations.*;/* * Product entity. * * author MyEclipse Persistence Tools */Searchablepublic class Product implements java.io.Serializable / FieldsSearchableIdprivate String id;SearchableProperty(name=name,index=Index.ANALYZED,store=Store.YES)private String name;SearchableProperty(name=price,index=Index.NOT_ANALYZED,store=Store.YES)private Double price;SearchableProperty(name=brand,index=Index.ANALYZED,store=Store.YES)private String brand;SearchableProperty(name=description,index=Index.ANALYZED,store=Store.YES)private String description;/ Constructors/* default constructor */public Product() /* full constructor */public Product(String name, Double price, String brand, String description) = name;this.price = price;this.brand = brand;this.description = description;/ Property accessorspublic String getId() return this.id;public void setId(String id) this.id = id;public String getName() return ;public void setName(String name) = name;public Double getPrice() return this.price;public void setPrice(Double price) this.price = price;public String getBrand() return this.brand;public void setBrand(String brand) this.brand = brand;public String getDescription() return this.description;public void setDescription(String description) this.description = description;step3属性文件Product.hbm.xml Java代码 1. 2. 4. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 要使用Compass必须加入一个applicationContext-compass.xml文件,文件名可以自行定义 这个就不用说了 废话 step4applicationContext-compass.xml: Java代码 1. 2. 3. 7. 8. 9. 11. 12. 13. 14. 15. 16. 17. 18. classpath:com/v512/example/model 19. 20. 21. 22. 23. /lucene/indexes 24. 25. 26. 27. 28. 29. com.v512.example.model.Product 30. 31. 32. 34. 35. 36. 37. 38. 39. pass.spring.transaction.SpringSyncTransactionFactory 40. 41. net.paoding.analysis.analyzer.PaodingAnalyzer 42. 43. 44. 45. 46. 47. 48. 49. 51. 52. hibernateDevice 53. 54. 55. 56. true 57. 58. 59. 60. 62. 63. 64. 65. 67. 68. 69. 70. 71. 72. 73. 74. 76. 77. 78. 79. 80. 83. 84. 85. 86. 87. 88. 89. 90. classpath:com/v512/example/model /lucene/indexes com.v512.example.model.Product pass.spring.transaction.SpringSyncTransactionFactory net.paoding.analysis.analyzer.PaodingAnalyzer hibernateDevicetrue中间都有注解 就不多解释了 下面来编写dao及dao的实现以及severce层 step5 Java代码 1. packagecom.v512.example.dao; 2. 3. importjava.util.List; 4. 5. importcom.v512.example.model.Product; 6. 7. publicinterfaceProductDao 8. publicvoidcreate(Productp); 9. publicProductgetProduct(Stringid); 10. publicListgetProducts(); 11. publicvoidupdate(Productproduct); 12. publicvoidremove(Stringid); 13. 14. package com.v512.example.dao;import java.util.List;import com.v512.example.model.Product;public interface ProductDao public void create(Product p);public Product getProduct(String id);public List getProducts();public void update(Product product);public void remove(String id);Java代码 1. packagecom.v512.example.dao.hibernate; 2. 3. importjava.util.List; 4. 5. importcom.v512.example.dao.ProductDao; 6. importcom.v512.example.model.Product; 7. importorg.springframework.orm.hibernate3.support.HibernateDaoSupport; 8. publicclassProductDaoHibernateextendsHibernateDaoSupportimplementsProductDao 9. 10. publicvoidcreate(Productp) 11. getHibernateTemplate().save(p); 12. 13. 14. 15. publicProductgetProduct(Stringid) 16. return(Product)getHibernateTemplate().get(Product.class,id); 17. 18. 19. publicListgetProducts() 20. returngetHibernateTemplate().find(fromProductorderbyiddesc); 21. 22. 23. publicvoidremove(Stringid) 24. getHibernateTemplate().delete(getProduct(id); 25. 26. 27. 28. publicvoidupdate(Productproduct) 29. getHibernateTemplate().saveOrUpdate(product); 30. 31. 32. 33. package com.v512.example.dao.hibernate;import java.util.List;import com.v512.example.dao.ProductDao;import com.v512.example.model.Product;import org.springframework.orm.hibernate3.support.HibernateDaoSupport;public class ProductDaoHibernate extends HibernateDaoSupport implements ProductDao public void create(Product p) getHibernateTemplate().save(p);public Product getProduct(String id) return (Product)getHibernateTemplate().get(Product.class, id);public List getProducts() return getHibernateTemplate().find(from Product order by id desc);public void remove(String id) getHibernateTemplate().delete(getProduct(id);public void update(Product product) getHibernateTemplate().saveOrUpdate(product);servece Java代码 1. packagecom.v512.example.service; 2. 3. importjava.util.List; 4. 5. importcom.v512.example.model.Product; 6. 7. publicinterfaceProductManager 8. publicvoidinsertProduct(Productp); 9. publicProductfindProdcut(Stringid); 10. publicListsearchProducts(StringqueryString); 11. 12. 13. package com.v512.example.service;import java.util.List;import com.v512.example.model.Product;public interface ProductManager public void insertProduct(Product p);public Product findProdcut(String id);public List searchProducts(String queryString);servece的实现 Java代码 1. packagecom.v512.example.service.impl; 2. 3. importjava.util.ArrayList; 4. importjava.util.List; 5. 6. pass.core.CompassHits; 7. pass.core.CompassSession; 8. pass.core.CompassTemplate; 9. pass.core.CompassTransaction; 10. 11. importcom.v512.example.dao.ProductDao; 12. importcom.v512.example.model.Product; 13. importcom.v512.example.service.ProductManager; 14. pass.core.Compass; 15. publicclassProductManagerImplimplementsProductManager 16. privateProductDaoproductDao; 17. privateCompassTemplatecompassTemplate; 18. 19. 20. 21. 22. publicvoidsetCompassTemplate(CompassTemplatecompassTemplate) 23. passTemplate=compassTemplate; 24. 25. 26. publicvoidsetProductDao(Pr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025版铁塔基站租赁与广告位合作合同范本
- 2025版桥架安装与防雷接地工程承包合同样本
- 2025年建筑材料供货与绿色建筑认证服务合同
- 2025年二手房买卖合同:针对老旧房屋改造的特别约定条款
- 2025年度高效节水农业种植技术服务合同范本
- 2025年跨境矿山资源承包与国际贸易合同
- 2025版文化旅游区建筑承包合同范本
- 2025年数字经济法律咨询项目评标保密与委托合同
- 2025版石料矿山安全生产责任协议
- 2025年度旅游行程变更免责协议及游客须知
- XXX有限公司报销审核制度
- WS/T 427-2013临床营养风险筛查
- GA/T 1047-2013道路交通信息监测记录设备设置规范
- GJB9001C内审员培训讲学课件
- 五牌一图(完整版)
- 幼儿园绘本故事:《十二生肖》 课件
- DDI定向井难度系数
- 激光跟踪仪使用手册
- 新媒体运营知识考核试题与答案
- 金属材料的主要性能ppt课件(完整版)
- 丽声北极星自然拼读绘本第二级 Fat Cat 课件
评论
0/150
提交评论