Mercurial Hosting > luan
comparison lucene/src/luan/modules/lucene/LuceneIndex.java @ 527:ef0336efe33c
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 27 May 2015 03:29:04 -0600 |
parents | 70bda9184158 |
children | c5a93767cc5c |
comparison
equal
deleted
inserted
replaced
526:f24d824e9fe5 | 527:ef0336efe33c |
---|---|
1 package luan.modules.lucene; | 1 package luan.modules.lucene; |
2 | 2 |
3 import java.io.Closeable; | |
3 import java.io.File; | 4 import java.io.File; |
4 import java.io.FileOutputStream; | 5 import java.io.FileOutputStream; |
5 import java.io.FileInputStream; | 6 import java.io.FileInputStream; |
6 import java.io.IOException; | 7 import java.io.IOException; |
7 import java.util.concurrent.locks.Lock; | 8 import java.util.concurrent.locks.Lock; |
33 import luan.LuanException; | 34 import luan.LuanException; |
34 import org.slf4j.Logger; | 35 import org.slf4j.Logger; |
35 import org.slf4j.LoggerFactory; | 36 import org.slf4j.LoggerFactory; |
36 | 37 |
37 | 38 |
38 public final class LuceneIndex { | 39 public final class LuceneIndex implements Closeable { |
39 private static final Logger logger = LoggerFactory.getLogger(LuceneIndex.class); | 40 private static final Logger logger = LoggerFactory.getLogger(LuceneIndex.class); |
40 | 41 |
41 private static final String FLD_NEXT_ID = "nextId"; | 42 private static final String FLD_NEXT_ID = "nextId"; |
42 | 43 |
43 final Lock writeLock = new ReentrantLock(); | 44 final Lock writeLock = new ReentrantLock(); |
46 final IndexWriter writer; | 47 final IndexWriter writer; |
47 private DirectoryReader reader; | 48 private DirectoryReader reader; |
48 private LuceneSearcher searcher; | 49 private LuceneSearcher searcher; |
49 public final FieldTable fields = new FieldTable(); | 50 public final FieldTable fields = new FieldTable(); |
50 private boolean isClosed = false; | 51 private boolean isClosed = false; |
51 private final Runnable closer; | |
52 | 52 |
53 public LuceneIndex(LuanState luan,String indexDirStr) throws LuanException, IOException { | 53 public LuceneIndex(LuanState luan,String indexDirStr) throws LuanException, IOException { |
54 File indexDir = new File(indexDirStr); | 54 File indexDir = new File(indexDirStr); |
55 this.indexDir = indexDir; | 55 this.indexDir = indexDir; |
56 Directory dir = FSDirectory.open(indexDir); | 56 Directory dir = FSDirectory.open(indexDir); |
60 snapshotDeletionPolicy = new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()); | 60 snapshotDeletionPolicy = new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()); |
61 conf.setIndexDeletionPolicy(snapshotDeletionPolicy); | 61 conf.setIndexDeletionPolicy(snapshotDeletionPolicy); |
62 writer = new IndexWriter(dir,conf); | 62 writer = new IndexWriter(dir,conf); |
63 writer.commit(); // commit index creation | 63 writer.commit(); // commit index creation |
64 reader = DirectoryReader.open(dir); | 64 reader = DirectoryReader.open(dir); |
65 closer = new Runnable(){public void run(){ | 65 luan.onClose(this); |
66 try { | |
67 close(); | |
68 } catch(IOException e) { | |
69 logger.error("",e); | |
70 } | |
71 }}; | |
72 luan.onClose(closer); | |
73 searcher = new LuceneSearcher(this,reader); | 66 searcher = new LuceneSearcher(this,reader); |
74 initId(luan); | 67 initId(luan); |
75 } | 68 } |
76 | 69 |
77 Document toLucene(LuanState luan,LuanTable table) throws LuanException { | 70 Document toLucene(LuanState luan,LuanTable table) throws LuanException { |