1
私はLuceneをWebアプリケーションに統合しようとしています。 (未フルテキストインデックス作成のために、しかし、クイック検索用およびソート。)私は、サービスを作成しました:再生フレームワークでのLuceneの統合
trait Index {
def indexAd(a: Ad): Unit
}
@Singleton
class ConcreteIndex @Inject()(conf: Configuration) extends Index {
val dir = FSDirectory.open(FileSystems.getDefault.getPath(conf.getString("index.dir").get))
val writer = new IndexWriter(dir, new IndexWriterConfig(new StandardAnalyzer))
override def indexAd(a: Ad): Unit = {
val doc = new Document
...
}
}
とコントローラでそれを使用しよう:
@Singleton
class AdsController @Inject()(cache: CacheApi, index:Index) extends Controller {
...
}
をしかし、注入は成功しません。私は、ロックファイルを削除して、もう一度新鮮実行しようとした
Error injecting constructor, org.apache.lucene.store.LockObtainFailedException:
Lock held by this virtual machine: .../backend/index/write.lock
を得ました。それでも同じ例外がスローされます。誰も私にこれを手伝ってもらえますか?私はLucene 6.2.0を使用しています。 Play 2.5.x、scala 2.11.8
で終わったら 'IndexWriter'インスタンスを終了していますか?書き込みロックを解除する必要があります(https://lucene.apache.org/core/6_1_0/core/org/apache/lucene/index/IndexWriter.html#close--)。インデックスライターを開いたままにしてシャットダウンするときは、 'Lifecycle'インスタンスを' ConcreteIndex'に注入し、ライターを閉じるためのシャットダウンフックを追加してください。 – Mikesname
それは働いた。ありがとう@Mikesname。私はそれを解決済みとすることができるように答えることができますか? – yang