This is my sample code:
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUser("root");
dataSource.setPassword("ncl");
dataSource.setDatabaseName("userdb");
dataSource.setEmulateLocators(true); //This is important because we are dealing with a blob type data field
try{
JdbcDirectory jdbcDir = new JdbcDirectory(dataSource, new MySQLDialect(), "tttable");
StandardAnalyzer analyzer = new StandardAnalyzer();
IndexWriter writer = new IndexWriter(jdbcDir, analyzer,false);
writer.optimize();
writer.close();
}catch(Exception e){
System.out.print(e);
}
I am stuck at this line: IndexWriter writer = new IndexWriter(jdbcDir, analyzer,false);
Everytime I try to run this code, I receive the following exception:
------"org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: PhantomReadLock[write.lock/tttable]"------------
I cannot find what is wrong with the code. It may be it is a jar compatibility issue.
I am unable to get an IndexWriter object.
-
It seems like the index is locked. If you're sure it shouldn't be locked, then maybe some process crashed without proper cleanup.
Try adding the line
jdbcDir.clearLock();before creating the indexWriter.
Don't leave it there, tough. You generally want to let Lucene manage the locks, to disallow two IndexWriters from writing to the same index.
From itsadok -
I get the same thing. So do I have to turn back on the lock then?
0 comments:
Post a Comment