基于Java的Luncene的compass框架說明使用技術(shù)文檔_第1頁
基于Java的Luncene的compass框架說明使用技術(shù)文檔_第2頁
基于Java的Luncene的compass框架說明使用技術(shù)文檔_第3頁
基于Java的Luncene的compass框架說明使用技術(shù)文檔_第4頁
基于Java的Luncene的compass框架說明使用技術(shù)文檔_第5頁
已閱讀5頁,還剩12頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、Compass技術(shù)文檔目錄、原理描述:二、術(shù)語解釋:三、下載地址:四、使用流程:五、基于SSH的compass的實(shí)例:一、原理描述:Compass是一流的開放源碼JAVA搜索引擎框架,對于你的應(yīng)用修飾,搜索引擎語義更具有能力。依靠頂級的Lucene搜索引擎,Compass結(jié)合了,像Hibernate和Spring的流行的框架,為你的應(yīng)用提供了從數(shù)據(jù)模型和數(shù)據(jù)源同步改變的搜索力.并且添加了2方面的特征,事物管理和快速更新優(yōu)化.Compass的目標(biāo)是:把java應(yīng)用簡單集成到搜索引擎中.編碼更少,查找數(shù)據(jù)更便捷.、術(shù)語解釋:名稱描述LuceneApacheLucene是l個(gè)基于Java全文搜索引擎

2、,利用它口以輕易地為Java軟件加入全文搜尋功能。Lucene的最主要工作是替文件的句個(gè)子作索引,索引讓搜尋的效率比傳統(tǒng)的逐字比較大大提高了,Lucene提供一組解讀,過濾,分析文件,編排和使用索引的提供一組解讀,過濾,分析文件,編排和使用索引的API,它的強(qiáng)大之處除了高效和簡單外,是最重要的是使使用都是可以隨時(shí)應(yīng)自己需要自訂其功能。開發(fā)者可以把Lucene看成一個(gè)支持全文索引的數(shù)據(jù)庫系統(tǒng)的Compass我對Compass的te義是向向域模型的搜索框架,向向域模型忌味著必須支持對對象的搜索,對持久化對象的搜索,和對XML文檔對象的搜索,同時(shí)還必須支持事務(wù)的處理,包括對創(chuàng)建,更新,保存,刪除進(jìn)行

3、事務(wù)級別的處理.所以,Compass是基于Lucene,高于Lucene的.有個(gè)形象的比喻.Compass對于Lucene就彳Hibernate對于JDBC,太有才了!Compass的開發(fā)路數(shù)完全參照Hibernate.OSEM對象搜索引擎影射(ObjectSearchEngineMapping),通過xml配置文件,提供了POJOs(PlainOldJavaObjects)到搜索引擎.三、下載地址:軟件名稱下載地址軟件描述Compass框架、jar包/基于Java的搜索引擎四、使用流程:五、基于SSH的compasS勺實(shí)例:stepl在ssh2的基礎(chǔ)上開發(fā)力

4、口入jar包(compass-2.1.2.jarcompass-index-patch.jarlucene-analyzers-2.4.0.jarlucene-core-2.4.0.jarlucene-highlighter-2.4.0.jarpaoding-analysis.jar)step2先來看下實(shí)體bean的編寫Java代碼1. packagecom.v512.example.model;2. pass.annotations.*;3. /*4. *Productentity.5. *6. *authorMyEclipsePersistenceTools7. */8. Searchab

5、le9. publicclassProductimplementsjava.io.Serializable10.11. /Fields12.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.

6、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. /Constructors25.26. /*defaultconstructor*/27. publicProduct()28. 29.30. /*fullconstructor*/31. pu

7、blicProduct(Stringname,Doubleprice,Stringbrand,Stringdescription)32. =name;33. this.price=price;34. this.brand=brand;35. this.description=description;36. 37.38. /Propertyaccessors39.40. publicStringgetId()41. returnthis.id;42. 43.44. publicvoidsetId(Stringid)45. this.id=id;46. 47.48. public

8、StringgetName()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(Strin

9、gbrand)69. this.brand=brand;70. 71.72. publicStringgetDescription()73. returnthis.description;74. 75.76. publicvoidsetDescription(Stringdescription)77. this.description=description;78. 79.80. step3屬性文件Product.hbm.xmlJava代碼_1. 2. !DOCTYPEhibernate-mappingPUBLIC-/Hibernate/HibernateMappingDTD3.0/EN3.

10、“http:4. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 要使用Compass、須加入一個(gè)applicationContext-compass.xml文件,文件名可以自行定義這個(gè)就不用說了廢話step4applicationContext-compass.xml:Java代碼_1. 2.3. 7.8. 9. 11. 12.13.14. 15. 16. 17. 18. classpath:com/v512/example/model19. 20. 21. 22. 23. /lucen

11、e/indexes24. 25.26. 27. 28. 29. com.v512.example.model.Product30. 31. 32. 34.35. 36. 37. 38. 39. pass.spring.transaction.SpringSyncTransactionFactory40. 41. net.paoding.analysis.analyzer.PaodingAnalyzer42. 43. 44. 45. 46. 47.48.49. 51. 52. hibernateDevice53. 54. propertyname=sessionFactoryref=sessio

12、nFactory/55. 56. true57. 58. 59. 60. 62. 63. 64. 65. 67. 68. 69. 70. 71. 72.73.74. 76. 77. 78.79. 80. 83. 84. 85. 86. 0. 中間都有注解就不多解釋了下面來編寫dao及dao的實(shí)現(xiàn)以及severce層step5Java代碼.1. packagecom.v512.example.dao;2.3. importjava.util.List;4.5. importcom.v512.example.model.Product;6.7. publicinterfaceP

13、roductDao8. publicvoidcreate(Productp);9. publicProductgetProduct(Stringid);10. publicListgetProducts();11. publicvoidupdate(Productproduct);12. publicvoidremove(Stringid);13.14. Java代碼一1. packagecom.v512.example.dao.hibernate;2.3. importjava.util.List;4.5. importcom.v512.example.dao.ProductDao;6. i

14、mportcom.v512.example.model.Product;7. importorg.springframework.orm.hibernate3.support.HibernateDaoSupport;8. publicclassProductDaoHibernateextendsHibernateDaoSupportimplementsProductDao9.10. publicvoidcreate(Productp)11. getHibernateTemplate().save(p);12.13. 14.15. publicProductgetProduct(Stringid

15、)16. return(Product)getHibernateTemplate().get(Product.clas5, 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.

16、getHibernateTemplate().saveOrUpdate(product);30.31. 32.33. serveceJava代碼一1. packagecom.v512.example.service;2.3. importjava.util.List;4.5. importcom.v512.example.model.Product;6.7. publicinterfaceProductManager8. publicvoidinsertProduct(Productp);9. publicProductfindProdcut(Stringid);10. publicLists

17、earchProducts(StringqueryString);11.12.13. servece的實(shí)現(xiàn)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

18、.dao.ProductDao;12. importcom.v512.example.model.Product;13. importcom.v512.example.service.ProductManager;14. pass.core.Compass;15. publicclassProductManagerImplimplementsProductManager16. privateProductDaoproductDao;17. privateCompassTemplatecompassTemplate;1.22. publicvoidsetCompassTemp

19、late(CompassTemplatecompassTemplate)23. passTemplate=compassTemplate;24. 25.26. publicvoidsetProductDao(ProductDaoproductDao)27. ductDao=productDao;28. 29.30. publicProductfindProdcut(Stringid)31. returnproductDao.getProduct(id);32. 33.34. publicvoidinsertProduct(Productp)35. productDao.crea

20、te(p);36. 37.38. publicListsearchProducts(StringqueryString)39. Compasscompass=compassTemplate.getCompass();40. CompassSessionsession=compass.openSession();41. Listlist=newArrayList();42. /這里不需要開啟事務(wù)了,因?yàn)樵谡{(diào)用這個(gè)方法之前就已經(jīng)開啟了事務(wù)43. CompassHitshits=session.queryBuilder().queryString(name:+queryString).toQuery

21、().hits();44. System.out.println(queryString:+queryString);45. System.out.println(hits:+hits.getLength();46.47.for(inti=0;ihits.length();i+)Producthit=(Product)hits.data(i);48. list.add(hit);49. 50.51. returnlist;52. 6. publicCompassTemplategetCompassTemplate()57. returncompassTemplate;58.

22、 59.60. 所有的都做完了現(xiàn)在編寫jsp頁面step6insertProduct.jspJava代碼一1. 3. 4. 5. 6. 7. 8. 9.10. 添加信息11. 12. 13. 14. 15.16. 17. 18. 19. 添加商品名稱20. 21. 22. 23.24.25. 26. 27. 商品名稱28. 29. 30.31. 32. 商品品牌33. 34. 35.36. 37. 商品價(jià)格38. 39. 40.41. 42. 商品描述43. 44. 45. 46. 47.  48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59

23、. 60. step7編寫actionJava代碼_1. packagecom.v512.example.action;2.3. importjava.util.List;4.5. importcom.opensymphony.xwork2.ActionSupport;6. importcom.v512.example.model.Product;7. importcom.v512.example.service.ProductManager;8. importorg.apache.struts2.ServletActionContext;9.10. publicclassProductActionextendsActionSupport11.12. privatestaticfinallongserialVersionUID=3795048906805728732L;13. privateProductManagerproductManager;14. privateProductproduct;15. privat

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論