基于Luncene的compass框架详解java.doc

上传人:星星 文档编号:1039001 上传时间:2024-03-28 格式:DOC 页数:29 大小:386.90KB
下载 相关 举报
基于Luncene的compass框架详解java.doc_第1页
第1页 / 共29页
基于Luncene的compass框架详解java.doc_第2页
第2页 / 共29页
基于Luncene的compass框架详解java.doc_第3页
第3页 / 共29页
基于Luncene的compass框架详解java.doc_第4页
第4页 / 共29页
基于Luncene的compass框架详解java.doc_第5页
第5页 / 共29页
点击查看更多>>
资源描述

1、目录一、原理描述:二、术语解释:三、下载地址:四、使用流程: .五、基于SSH的compass的实例: 一、原理描述:Compass是一流的开放源码JAVA搜索引擎框架,对于你的应用修饰,搜索引擎语义更具有能力。依靠顶级的Lucene搜索引擎,Compass 结合了,像 Hibernate和 Spring的流行的框架,为你的应用提供了从数据模型和数据源同步改变的搜索力.并且添加了2方面的特征,事物管理和快速更新优化. Compass的目标是:把java应用简单集成到搜索引擎中.编码更少,查找数据更便捷 .二、术语解释:名称描述Lucene Apache Lucene是一个基于Java全文搜索引

2、擎,利用它可以轻易地为Java软件加入全文搜寻功能。Lucene的最主要工作是替文件的每一个字作索引,索引让搜寻的效率比传统的逐字比较大大提高了,Lucene提供一组解读,过滤,分析文件,编排和使用索引的提供一组解读,过滤,分析文件,编排和使用索引的API,它的强大之处除了高效和简单外,是最重要的是使使用都是可以随时应自己需要自订其功能。开发者可以把Lucene看成一个支持全文索引的数据库系统的.Compass我对Compass的定义是面向域模型的搜索框架, 面向域模型意味着必须支持对对象的搜索,对持久化对象的搜索,和对XML文档对象的搜索,同时还必须支持事务的处理,包括对创建,更新,保存,删

3、除进行事务级别的处理. 所以, Compass是基于Lucene, 高于Lucene的. 有个形象的比喻. Compass对于Lucene就像Hibernate对于JDBC,太有才了!Compass的开发路数完全参照Hibernate.OSEM对象搜索引擎影射(Object Search Engine Mapping),通过xml配置文件,提供了POJOs (Plain Old Java Objects)到搜索引擎.三、下载地址:软件名称下载地址软件描述Compass框架、jar包passframework.org/基于Java的搜索引擎四、使用流程:网络机器人程序www文档网络机器人程序建立

4、索引从数据库中搜索信息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. importpass.ann

5、otations.*; 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; 1

6、7. 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. privateStringdescriptio

7、n; 23. 24. /Constructors 25. 26. /*defaultconstructor*/27. publicProduct() 28. 29. 30. /*fullconstructor*/31. publicProduct(Stringname,Doubleprice,Stringbrand,Stringdescription) 32. this.name=name; 33. this.price=price; 34. this.brand=brand; 35. this.description=description; 36. 37. 38. /Propertyacc

8、essors 39. 40. publicStringgetId() 41. returnthis.id; 42. 43. 44. publicvoidsetId(Stringid) 45. this.id=id; 46. 47. 48. publicStringgetName() 49. returnthis.name; 50. 51. 52. publicvoidsetName(Stringname) 53. this.name=name; 54. 55. 56. publicDoublegetPrice() 57. returnthis.price; 58. 59. 60. public

9、voidsetPrice(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.

10、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=Ind

11、ex.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

12、)private String description;/ Constructors/* default constructor */public Product() /* full constructor */public Product(String name, Double price, String brand, String description) this.name = name;this.price = price;this.brand = brand;this.description = description;/ Property accessorspublic Strin

13、g getId() return this.id;public void setId(String id) this.id = id;public String getName() return this.name;public void setName(String name) this.name = name;public Double getPrice() return this.price;public void setPrice(Double price) this.price = price;public String getBrand() return this.brand;pu

14、blic 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. !DOCTYPEhibernate-mappingPUBLIC-/Hibernate/HibernateMappingDTD3.0/EN3. 4. 7.

15、8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. !DOCTYPE hibernate-mapping PUBLIC -/Hibernate/Hibernate Mapping DTD 3.0/EN 要使用Compass必须加入一个applicationContext-compass.xml文件,文件名可以自行定义 这个就不用说了 废话 step4applicationContext-compass.xml: Java代码 1. 2. 3. 7. 8. 9. 11. 12. 13. 14. 15.

16、 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.

17、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.SpringSyncTransactionFa

18、ctory 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);publ

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 其他资料

版权声明:以上文章中所选用的图片及文字来源于网络以及用户投稿,由于未联系到知识产权人或未发现有关知识产权的登记,如有知识产权人并不愿意我们使用,如有侵权请立即联系:2622162128@qq.com ,我们立即下架或删除。

Copyright© 2022-2024 www.wodocx.com ,All Rights Reserved |陕ICP备19002583号-1 

陕公网安备 61072602000132号     违法和不良信息举报:0916-4228922