休眠搜索错误
有人可以帮忙吗,我正在尝试使用休眠搜索的简单示例,但出现以下错误:
Exception in thread "main" org.hibernate.HibernateException: could not init listeners
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:205)
at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1396)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
at FirstExample.main(FirstExample.java:32)
Caused by: java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
at org.hibernate.search.util.HibernateSearchResourceLoader.getLines(HibernateSearchResourceLoader.java:52)
at org.apache.solr.analysis.StopFilterFactory.inform(StopFilterFactory.java:53)
at org.hibernate.search.impl.SolrAnalyzerBuilder.buildAnalyzer(SolrAnalyzerBuilder.java:79)
at org.hibernate.search.impl.InitContext.buildAnalyzer(InitContext.java:185)
at org.hibernate.search.impl.InitContext.initLazyAnalyzers(InitContext.java:155)
at org.hibernate.search.impl.SearchFactoryImpl.initDocumentBuilders(SearchFactoryImpl.java:541)
at org.hibernate.search.impl.SearchFactoryImpl.<init>(SearchFactoryImpl.java:171)
at org.hibernate.search.event.ContextHolder.getOrBuildSearchFactory(ContextHolder.java:60)
at org.hibernate.search.event.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:122)
at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
... 3 more
我的项目类:
@Indexed
@AnalyzerDef(name="customanalyzer",
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = ISOLatin1AccentFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = StopFilterFactory.class, params = {
@Parameter(name="words", value= "org/hibernate/search/test/analyzer/solr/stoplist.properties" ),
@Parameter(name="ignoreCase", value="true")
})
})
public class Item
{
@DocumentId
private Integer id;
@Field @Analyzer(definition = "customanalyzer")
private String title;
@Field @Analyzer(definition = "customanalyzer")
private String description;
@Field(index=Index.UN_TOKENIZED, store=Store.YES)
private String ean;
private String imageURL;
//public getters and setters
}
程序代码:
Session session = null;
Transaction tx = null;
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
FullTextSession ftem = org.hibernate.search.Search.getFullTextSession(session);
ftem.beginTransaction();
List <Item> AllItem=session.createQuery("From Item").list();
for (Item item : AllItem) {
ftem.index(item);
}
ftem.getTransaction().commit();
String searchQuery = "title:Batman";
QueryParser parser = new QueryParser(
"title",
ftem.getSearchFactory().getAnalyzer("customanalyzer")
);
org.apache.lucene.search.Query luceneQuery;
try {
luceneQuery = parser.parse(searchQuery);
}
catch (ParseException e) {
throw new RuntimeException("Unable to parse query: " + searchQuery, e);
}
org.hibernate.Query query = ftem.createFullTextQuery(
luceneQuery,
Item.class);
query.setFirstResult(20).setMaxResults(20);
List results = query.list();
Can someone help, i'm trying a simple example with hibernate search but getting the following error:
Exception in thread "main" org.hibernate.HibernateException: could not init listeners
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:205)
at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1396)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
at FirstExample.main(FirstExample.java:32)
Caused by: java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
at org.hibernate.search.util.HibernateSearchResourceLoader.getLines(HibernateSearchResourceLoader.java:52)
at org.apache.solr.analysis.StopFilterFactory.inform(StopFilterFactory.java:53)
at org.hibernate.search.impl.SolrAnalyzerBuilder.buildAnalyzer(SolrAnalyzerBuilder.java:79)
at org.hibernate.search.impl.InitContext.buildAnalyzer(InitContext.java:185)
at org.hibernate.search.impl.InitContext.initLazyAnalyzers(InitContext.java:155)
at org.hibernate.search.impl.SearchFactoryImpl.initDocumentBuilders(SearchFactoryImpl.java:541)
at org.hibernate.search.impl.SearchFactoryImpl.<init>(SearchFactoryImpl.java:171)
at org.hibernate.search.event.ContextHolder.getOrBuildSearchFactory(ContextHolder.java:60)
at org.hibernate.search.event.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:122)
at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
... 3 more
My Item Class:
@Indexed
@AnalyzerDef(name="customanalyzer",
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = ISOLatin1AccentFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = StopFilterFactory.class, params = {
@Parameter(name="words", value= "org/hibernate/search/test/analyzer/solr/stoplist.properties" ),
@Parameter(name="ignoreCase", value="true")
})
})
public class Item
{
@DocumentId
private Integer id;
@Field @Analyzer(definition = "customanalyzer")
private String title;
@Field @Analyzer(definition = "customanalyzer")
private String description;
@Field(index=Index.UN_TOKENIZED, store=Store.YES)
private String ean;
private String imageURL;
//public getters and setters
}
Program code:
Session session = null;
Transaction tx = null;
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
FullTextSession ftem = org.hibernate.search.Search.getFullTextSession(session);
ftem.beginTransaction();
List <Item> AllItem=session.createQuery("From Item").list();
for (Item item : AllItem) {
ftem.index(item);
}
ftem.getTransaction().commit();
String searchQuery = "title:Batman";
QueryParser parser = new QueryParser(
"title",
ftem.getSearchFactory().getAnalyzer("customanalyzer")
);
org.apache.lucene.search.Query luceneQuery;
try {
luceneQuery = parser.parse(searchQuery);
}
catch (ParseException e) {
throw new RuntimeException("Unable to parse query: " + searchQuery, e);
}
org.hibernate.Query query = ftem.createFullTextQuery(
luceneQuery,
Item.class);
query.setFirstResult(20).setMaxResults(20);
List results = query.list();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来 Hibernate Search 在类路径中找不到 org/hibernate/search/test/analyzer/solr/stoplist.properties 。确保它在那里。
It looks like Hibernate Search can't find
org/hibernate/search/test/analyzer/solr/stoplist.properties
in the classpath. Make sure it's there.