私は、プロジェクトでテキストベースの検索のためにApache luceneをテストしています。残念ながら、私はライブラリの欠落に問題があります。私はlucene-queriesを追加しようとしましたが、それは助けになりませんでした。私は間違って何をしていますか?Lucene-6.4.2:クラスが見つかりません。DefaultSimilarity、クエリを追加しようとしました。
のErrorLog:
Caused by: java.lang.NoClassDefFoundError: org/apache/lucene/search/similarities/DefaultSimilarity
at org.hibernate.search.spi.SearchIntegratorBuilder.createCleanFactoryState(SearchIntegratorBuilder.java:287)
at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:186)
at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:117)
at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:66)
at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:52)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:588)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 98 more
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.search.similarities.DefaultSimilarity
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1858)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701)
... 111 more
のpom.xml:私がしようとしています
<!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-core -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>6.4.2</version>
</dependency>
コード:
@Override
public void saveIndexes() {
//Apache Lucene Indexing Directory .txt files
try {
//indexing directory
Path path = Paths.get("/home/akshay/index/");
Directory directory = org.apache.lucene.store.FSDirectory.open(path);
IndexWriterConfig config = new IndexWriterConfig(new SimpleAnalyzer());
IndexWriter indexWriter = new IndexWriter(directory, config);
indexWriter.deleteAll();
File f = new File("/home/akshay/textfiles/"); // current directory
for (File file : f.listFiles()) {
System.out.println("indexed " + file.getCanonicalPath());
org.apache.lucene.document.Document doc = new org.apache.lucene.document.Document();
doc.add(new TextField("path", file.getName(), Field.Store.YES));
FileInputStream is = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuffer stringBuffer = new StringBuffer();
String line;
while((line = reader.readLine())!=null){
stringBuffer.append(line).append("\n");
}
reader.close();
doc.add(new TextField("contents", stringBuffer.toString(), Field.Store.YES));
indexWriter.addDocument(doc);
}
indexWriter.close();
directory.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
@Override
public void searchLucene(String text) {
//Apache Lucene searching text inside .txt files
try {
Path path = Paths.get("/home/akshay/index/");
Directory directory = FSDirectory.open(path);
IndexReader indexReader = DirectoryReader.open(directory);
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
QueryParser queryParser = new QueryParser("contents", new StandardAnalyzer());
Query query = queryParser.parse(text);
TopDocs topDocs = indexSearcher.search(query,10);
System.out.println("totalHits " + topDocs.totalHits);
for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
org.apache.lucene.document.Document document = indexSearcher.doc(scoreDoc.doc);
System.out.println("path " + document.get("path"));
System.out.println("content " + document.get("contents"));
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
を任意のアイデアは、あなたに感謝します。 、6.4.2バージョンでそれを探しているとき、それはもう存在しません:-)
のいずれかを使用しますかこのエラーが表示されますか? Tomcat?あなたは確かです、そのルシーンコアはクラスパスにありますか? – Mysterion