compass小例子出问题?大家帮忙啊

编程界明世隐
Java领域优质创作者
博客专家认证
2008-08-01 03:40:15
Book类 其中setter、getter方法就不写出来了

public class Book {

private String bookNo;
private String bookName;
private String author;
private String category;
private String contents;
private Double price;

public Book(){

}

}

alias.cmd.xml文件

<?xml version="1.0"?>
<!DOCTYPE compass-core-meta-data PUBLIC
"-//Compass/Compass Core Meta Data DTD 2.0//EN"
"http://www.compass-project.org/dtd/compass-core-meta-data-2.0.dtd">
<compass-core-meta-data>
<meta-data-group id="mybooks" displayName="Mybooks Meta Data">

<description>Book Meta Data</description>
<uri>http://compass/mybooks</uri>

<alias id="book" displayName="Book">
<description>Book alias</description>
<uri>http://compass/mybooks/Book</uri>
<name>book</name>
</alias>
<meta-data id="bookNo" displayName="BookNo">
<description>Author alias</description>
<uri>http://compass/mybooks/bookNo</uri>
<name>bookNo</name>
</meta-data>
<meta-data id="bookName" displayName="BookName">
<description>BookName alias</description>
<uri>http://compass/mybooks/bookName</uri>
<name>bookName</name>
</meta-data>
<meta-data id="author" displayName="Author">
<description>Text alias</description>
<uri>http://compass/mybooks/author</uri>
<name>author</name>
</meta-data>
<meta-data id="category" displayName="Category">
<description>Category alias</description>
<uri>http://compass/mybooks/category</uri>
<name>category</name>
</meta-data>
<meta-data id="contents" displayName="Contents">
<description>Text alias</description>
<uri>http://compass/mybooks/contents</uri>
<name>contents</name>
</meta-data>
<meta-data id="price" displayName="Price">
<description>Price alias</description>
<uri>http://compass/mybooks/price</uri>
<name>price</name>
</meta-data>
</meta-data-group>

</compass-core-meta-data>


Book.cpm.xml文件


<?xml version="1.0"?>
<!DOCTYPE compass-core-mapping PUBLIC
"-//Compass/Compass Core Mapping DTD 2.0//EN"
"http://www.compass-project.org/dtd/compass-core-mapping-2.0.dtd">
<compass-core-mapping package="org.shirdm.compass.document">
<class name="Book" alias="${mybooks.book}">
<id name="bookNo" />
<property name="bookName">
<meta-data>${mybooks.bookName}</meta-data>
</property>
<property name="author">
<meta-data>${mybooks.author}</meta-data>
</property>
<property name="category">
<meta-data>${mybooks.category}</meta-data>
</property>
<property name="contents">
<meta-data>${mybooks.contents}</meta-data>
</property>
<property name="price">
<meta-data>${mybooks.price}</meta-data>
</property>
</class>

</compass-core-mapping>


compass.cfg.xml文件


<!DOCTYPE compass-core-configuration PUBLIC
"-//Compass/Compass Core Configuration DTD 2.0//EN"
"http://www.compass-project.org/dtd/compass-core-configuration-2.0.dtd">
<compass-core-configuration>
<compass>
<setting name="compass.engine.connection">target/index</setting>
<meta-data resource="org/shirdm/compass/document/alias.cmd.xml" />
<mapping resource="org/shirdm/compass/document/Book.cpm.xml" />
</compass>
</compass-core-configuration>




测试类

public class MyCompassTest {

private static Compass compass;
static { // 解析Compass配置文件,加载Book实体类
CompassConfiguration config = new CompassConfiguration();
config.configure("/org/shirdm/compass/compass.cfg.xml");
config.addClass(Book.class);
compass = config.buildCompass();
}

private Book addBookA() { // 构造一个Book实例,实际上是构造了一个Document,并向其中添加Field
Book book = new Book();
book.setBookNo("ISBN 987-5-624-16000-8/TP");
book.setBookName("Compass框架技术");
book.setAuthor("飞云居士");
book.setCategory("Java");
String contents = "Compass是封装了Lucene的一个功能强大的框架。"
+ "Compass简单易学,这使得开发者可以像使用Hibernate一样轻松地开发自己的搜索引擎。"
+ "即使对Lucene并不是很熟悉,使用Compass框架开发使你变得游刃有余。";
book.setContents(contents);
book.setPrice(new Double(23.00));
return book;
}

private Book addBookB() {
Book book = new Book();
book.setBookNo("ISBN 388-2-244-16000-9/TP");
book.setBookName("鬼吹灯");
book.setAuthor("本物天下霸唱");
book.setCategory("考古小说类");
String contents = "几位“摸金校尉”(盗墓贼)通过风水秘术在发掘古墓时的诡异经历。"
+ "主人公胡八一祖传的风水秘书残卷,上山下乡时误入大山深处的辽代古墓,"
+ "参军时在昆仑山大冰川发现的九层妖楼,东北中蒙边境的关东军秘密地下...";
book.setContents(contents);
book.setPrice(new Double(58.50));
return book;
}

private void createIndex(Book book) { // 建立索引,与Hibernate很相似
CompassSession session = compass.openSession();
CompassTransaction tx = session.beginTransaction();
session.save(book);
tx.commit();
session.close();
}

private void search(String keyword) { // 根据关键字keyword检索
CompassSession session = compass.openSession();
CompassTransaction tx = session.beginTransaction();
CompassHits hits = session.find(keyword);
System.out.println("检索关键字 " + keyword + " 的检索结果如下:");
System.out.println("********************************************");
for (int i = 0; i < hits.getLength(); i++) {
Book book = (Book) hits.data(i);
System.out.println("书的编号为: " + book.getBookNo());
System.out.println("书的名称为: " + book.getBookName());
System.out.println("书的作者为: " + book.getAuthor());
System.out.println("书的类别为: " + book.getCategory());
System.out.println("书的内容为: " + book.getContents());
System.out.println("书的定价为: " + book.getPrice());
System.out.println("********************************************");
}
System.out.println("共检索出结果 " + hits.length() + " 个。");
hits.close();
tx.commit();
session.close();
compass.close();
}

public static void main(String[] args) {
MyCompassTest myCompass = new MyCompassTest();
myCompass.createIndex(myCompass.addBookA());
myCompass.createIndex(myCompass.addBookB());
myCompass.search("鬼吹灯");
}

}




一测试,报错了


2008-8-1 15:31:05 org.compass.core.config.CompassConfiguration configure
信息: Configuring from resource [/org/shirdm/compass/compass.cfg.xml]
2008-8-1 15:31:05 org.compass.core.config.CompassConfiguration addResource
信息: Mapping resource [org/shirdm/compass/document/alias.cmd.xml] in class loader
2008-8-1 15:31:05 org.compass.core.config.CompassConfiguration addResource
信息: Mapping resource [org/shirdm/compass/document/Book.cpm.xml] in class loader
2008-8-1 15:31:05 org.compass.core.config.builder.DTDConfigurationBuilder processCompass
信息: Configured Compass [default]
java.lang.ExceptionInInitializerError
Caused by: org.compass.core.mapping.MappingException: Compass does not allow multiple aliases for alias [book]
at org.compass.core.mapping.CompassMapping.addMapping(CompassMapping.java:122)
at org.compass.core.config.binding.XmlMappingBinding.doAddConfiguration(XmlMappingBinding.java:140)
at org.compass.core.config.binding.AbstractXmlMappingBinding.doAddInputStream(AbstractXmlMappingBinding.java:42)
at org.compass.core.config.binding.AbstractInputStreamMappingBinding.internalAddInputStream(AbstractInputStreamMappingBinding.java:192)
at org.compass.core.config.binding.AbstractInputStreamMappingBinding.addClass(AbstractInputStreamMappingBinding.java:161)
at org.compass.core.config.CompassMappingBinding.addClass(CompassMappingBinding.java:163)
at org.compass.core.config.CompassConfiguration.addClass(CompassConfiguration.java:446)
at org.shirdm.compass.main.MyCompassTest.<clinit>(MyCompassTest.java:34)
Exception in thread "main"



弄了好久了
都没错啊
不知道哪里错了
各位大虾帮忙啊,谢过先了

...全文
590 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wozuiaideliufang 2010-01-06
严重: Servlet.service() for servlet action threw exception
org.compass.core.config.ConfigurationException: No mapping match class [com.jb.cdjj.model.Student]
at org.compass.core.config.CompassConfiguration.addClass(CompassConfiguration.java:534)
at com.jb.cdjj.action.StudentAction.Compassfig(StudentAction.java:112)
at com.jb.cdjj.action.StudentAction.SeachAll(StudentAction.java:166)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)


哥哥些那我的这个是什么错呢?

给你们看看后台代码

private void Compassfig() {
// 解析Compass配置文件,加载Book实体类
CompassConfiguration config = new CompassConfiguration();
config.configure("/com/jb/cdjj/compass/cfg/compass.cfg.xml").addClass(Student.class);
compass = config.buildCompass();
}

这是我的后台代码

*cfg.xml

<!DOCTYPE compass-core-configuration PUBLIC
"-//Compass/Compass Core Configuration DTD 2.0//EN"
"http://www.compass-project.org/dtd/compass-core-configuration-2.2.dtd">
<compass-core-configuration>
<compass>
<setting name="compass.engine.connection">target/index</setting>
<meta-data resource="com/jb/cdjj/compass/cfg/compass.cmd.xml" />
<mapping resource="com/jb/cdjj/compass/cfg/compass.cpm.xml" />

</compass>
</compass-core-configuration>

这是什么错呢,高手指点。。。。。
  • 打赏
  • 举报
回复
wozuiaideliufang 2010-01-06
严重: Servlet.service() for servlet action threw exception
org.compass.core.config.ConfigurationException: No mapping match class [com.jb.cdjj.model.Student]
at org.compass.core.config.CompassConfiguration.addClass(CompassConfiguration.java:534)
at com.jb.cdjj.action.StudentAction.Compassfig(StudentAction.java:112)
at com.jb.cdjj.action.StudentAction.SeachAll(StudentAction.java:166)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  • 打赏
  • 举报
回复
speadrace 2008-10-20
觉得您可以到sudu1.com去看视频教程哦,我也是我同事推荐的,里面的教程compass教程讲的非常好,我也是这两天才学入门的,你的问题,如果有兴趣,大家一起学习compass。

附:如果问题还没解决,请把源代码和你的版本都写详细一些,也可以给我发邮件哦,我只能帮你看看
  • 打赏
  • 举报
回复
speadrace 2008-10-20
我看到的视频中有讲解到这部分,不过没有程序,直接看代码不好调试。

请看sudu1.com中compass视频教程

另外,compass2.0的版本本身有这个bug哦

请用compass2.1的做测试哦

  • 打赏
  • 举报
回复
jimmyzzxhlh 2008-08-08
你的配置文件很奇怪
上面有compass/myBooks,还有org.shirdm.compass.document这样的package
我不知道你前面那个链接是怎么来的。。
  • 打赏
  • 举报
回复
相关推荐
发帖
搜索引擎技术

2759

社区成员

搜索引擎的服务器通过网络搜索软件或网络登录等方式,将Internet上大量网站的页面信息收集到本地,经过加工处理建立信息数据库和索引数据库。
社区管理员
  • 搜索引擎技术社区
加入社区
帖子事件
创建了帖子
2008-08-01 03:40
社区公告
暂无公告