【发布时间】:2016-09-08 10:24:57
【问题描述】:
我正在尝试将 Lucene 集成到 Web 应用程序中。 (不是为了全文索引,而是为了快速搜索和排序。)我创建了一个服务:
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。玩 2.5.x,scala 2.11.8
【问题讨论】:
-
您是否在完成后关闭
IndexWriter实例?这是necessary to release the write lock。如果您想保持索引编写器打开并在关闭时将其关闭,请将Lifecycle实例注入您的ConcreteIndex并添加关闭挂钩以关闭编写器。 -
成功了。谢谢@Mikesname。您能回答一下,以便我将其标记为已解决吗?
标签: playframework dependency-injection lucene