基于Java的Luncene的compass框架说明使用技术文档.docx
《基于Java的Luncene的compass框架说明使用技术文档.docx》由会员分享,可在线阅读,更多相关《基于Java的Luncene的compass框架说明使用技术文档.docx(55页珍藏版)》请在冰豆网上搜索。
基于Java的Luncene的compass框架说明使用技术文档
Compass技术文档
目录
一、原理描述:
二、术语解释:
三、下载地址:
四、使用流程:
…………………………………………………………………………………….
五、基于SSH的compass的实例:
…………………………………………………………………
一、原理描述:
Compass是一流的开放源码JAVA搜索引擎框架,对于你的应用修饰,搜索引擎语义更具有能力。
依靠顶级的Lucene搜索引擎,Compass结合了,像Hibernate和Spring的流行的框架,为你的应用提供了从数据模型和数据源同步改变的搜索力.并且添加了2方面的特征,事物管理和快速更新优化.
Compass的目标是:
把java应用简单集成到搜索引擎中.编码更少,查找数据更便捷.
二、术语解释:
名称
描述
Lucene
ApacheLucene是一个基于Java全文搜索引擎,利用它可以轻易地为Java软件加入全文搜寻功能。
Lucene的最主要工作是替文件的每一个字作索引,索引让搜寻的效率比传统的逐字比较大大提高了,Lucene提供一组解读,过滤,分析文件,编排和使用索引的提供一组解读,过滤,分析文件,编排和使用索引的API,它的强大之处除了高效和简单外,是最重要的是使使用都是可以随时应自己需要自订其功能。
开发者可以把Lucene看成一个支持全文索引的数据库系统的.
Compass
我对Compass的定义是面向域模型的搜索框架,面向域模型意味着必须支持对对象的搜索,对持久化对象的搜索,和对XML文档对象的搜索,同时还必须支持事务的处理,包括对创建,更新,保存,删除进行事务级别的处理.所以,Compass是基于Lucene,高于Lucene的.有个形象的比喻.Compass对于Lucene就像Hibernate对于JDBC,太有才了!
Compass的开发路数完全参照Hibernate.
OSEM
对象搜索引擎影射(ObjectSearchEngineMapping),通过xml配置文件,提供了POJO's(PlainOldJavaObjects)到搜索引擎.
三、下载地址:
软件名称
下载地址
软件描述
Compass框架、jar包
passframework.org/
基于Java的搜索引擎
四、使用流程:
五、基于SSH的compass的实例:
step1
在ssh2的基础上开发 加入jar包(compass-2.1.2.jarcompass-index-patch.jar
lucene-analyzers-2.4.0.jarlucene-core-2.4.0.jarlucene-highlighter-2.4.0.jar paoding-analysis.jar
)
step2
先来看下实体bean的编写
Java代码
1.package com.v512.example.model;
2.import pass.annotations.*;
3./**
4. * Product entity.
5. *
6. * @author MyEclipse Persistence Tools
7. */
8.@Searchable
9.public class Product implements java.io.Serializable {
10.
11. // Fields
12.
13. @SearchableId
14. private String id;
15. @SearchableProperty(name="name",index=Index.ANALYZED,store=Store.YES)
16. private String name;
17. @SearchableProperty(name="price",index=Index.NOT_ANALYZED,store=Store.YES)
18. private Double price;
19. @SearchableProperty(name="brand",index=Index.ANALYZED,store=Store.YES)
20. private String brand;
21. @SearchableProperty(name="description",index=Index.ANALYZED,store=Store.YES)
22. private String description;
23.
24. // Constructors
25.
26. /** default constructor */
27. public Product() {
28. }
29.
30. /** full constructor */
31. public Product(String name, Double price, String brand, String description) {
32. this.name = name;
33. this.price = price;
34. this.brand = brand;
35. this.description = description;
36. }
37.
38. // Property accessors
39.
40. public String getId() {
41. return this.id;
42. }
43.
44. public void setId(String id) {
45. this.id = id;
46. }
47.
48. public String getName() {
49. return this.name;
50. }
51.
52. public void setName(String name) {
53. this.name = name;
54. }
55.
56. public Double getPrice() {
57. return this.price;
58. }
59.
60. public void setPrice(Double price) {
61. this.price = price;
62. }
63.
64. public String getBrand() {
65. return this.brand;
66. }
67.
68. public void setBrand(String brand) {
69. this.brand = brand;
70. }
71.
72. public String getDescription() {
73. return this.description;
74. }
75.
76. public void setDescription(String description) {
77. this.description = description;
78. }
79.
80.}
packagecom.v512.example.model;
importpass.annotations.*;
/**
*Productentity.
*
*@authorMyEclipsePersistenceTools
*/
@Searchable
publicclassProductimplementsjava.io.Serializable{
//Fields
@SearchableId
privateStringid;
@SearchableProperty(name="name",index=Index.ANALYZED,store=Store.YES)
privateStringname;
@SearchableProperty(name="price",index=Index.NOT_ANALYZED,store=Store.YES)
privateDoubleprice;
@SearchableProperty(name="brand",index=Index.ANALYZED,store=Store.YES)
privateStringbrand;
@SearchableProperty(name="description",index=Index.ANALYZED,store=Store.YES)
privateStringdescription;
//Constructors
/**defaultconstructor*/
publicProduct(){
}
/**fullconstructor*/
publicProduct(Stringname,Doubleprice,Stringbrand,Stringdescription){
this.name=name;
this.price=price;
this.brand=brand;
this.description=description;
}
//Propertyaccessors
publicStringgetId(){
returnthis.id;
}
publicvoidsetId(Stringid){
this.id=id;
}
publicStringgetName(){
returnthis.name;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicDoublegetPrice(){
returnthis.price;
}
publicvoidsetPrice(Doubleprice){
this.price=price;
}
publicStringgetBrand(){
r