0
|
1 /* */ package de.mpiwg.dwinter.lucencetools.analyzer;
|
|
2 /* */
|
|
3 /* */ import java.io.File;
|
|
4 /* */ import java.io.IOException;
|
|
5 /* */ import org.apache.lucene.analysis.Analyzer;
|
|
6 /* */ import org.apache.lucene.index.CorruptIndexException;
|
|
7 /* */ import org.apache.lucene.index.IndexReader;
|
|
8 /* */ import org.apache.lucene.index.IndexWriter;
|
|
9 /* */ import org.apache.lucene.index.IndexWriter.MaxFieldLength;
|
|
10 /* */ import org.apache.lucene.search.IndexSearcher;
|
|
11 /* */ import org.apache.lucene.store.Directory;
|
|
12 /* */ import org.apache.lucene.store.LockObtainFailedException;
|
|
13 import org.apache.lucene.store.NIOFSDirectory;
|
|
14 import org.apache.lucene.store.SimpleFSLockFactory;
|
|
15 /* */
|
|
16 /* */ public class LanguageAnalyzer
|
|
17 /* */ {
|
|
18 /* */ public String lang;
|
|
19 /* */ public Analyzer analyzer;
|
|
20 /* 19 */ public IndexWriter writer = null;
|
|
21 /* 20 */ public IndexReader reader = null;
|
|
22 /* 21 */ public IndexSearcher searcher = null;
|
|
23 /* */
|
|
24 /* */ public LanguageAnalyzer(String lang, Analyzer analyzer, File index_dir, boolean onlyReader)
|
|
25 /* */ throws CorruptIndexException, LockObtainFailedException, IOException
|
|
26 /* */ {
|
|
27 /* 35 */ this.lang = lang;
|
|
28 /* 36 */ this.analyzer = analyzer;
|
|
29 /* */
|
|
30 /* 38 */ boolean create = true;
|
|
31 /* */
|
|
32 /* 40 */ if (!index_dir.exists()) {
|
|
33 /* 41 */ index_dir.mkdir();
|
|
34 /* */ }
|
|
35 /* */
|
|
36 /* 44 */ File lang_dir = new File(index_dir.getAbsolutePath() + "/" + lang);
|
|
37 /* 45 */ if (lang_dir.exists()) {
|
|
38 /* 46 */ create = false;
|
|
39 /* */ }
|
|
40 File dirFile= new File(index_dir + "/" + lang);
|
|
41 /* 48 */ Directory indexDirectory = new NIOFSDirectory(dirFile);
|
|
42 /* */ indexDirectory.setLockFactory(new SimpleFSLockFactory(dirFile)); // TODO:ansonsten probleme wenn NFS mounts
|
|
43 /* 50 */ if (!onlyReader)
|
|
44 /* */ {
|
|
45 /* 52 */ this.writer =
|
|
46 /* 53 */ new IndexWriter(indexDirectory,
|
|
47 /* 53 */ analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
|
|
48 /* */ }
|
|
49 /* 55 */ if (!index_dir.exists())
|
|
50 /* */ {
|
|
51 /* 58 */ return;
|
|
52 /* */ }
|
|
53 /* */
|
|
54 /* 62 */ create = true;
|
|
55 /* */
|
|
56 /* 65 */ if (lang_dir.exists()) {
|
|
57 /* 66 */ create = false;
|
|
58 /* */ }
|
|
59 /* 68 */ if (create)
|
|
60 /* */ return;
|
|
61 /* 70 */ IndexReader reader = IndexReader.open(indexDirectory);
|
|
62 /* 71 */ this.reader = reader;
|
|
63 /* 72 */ this.searcher = new IndexSearcher(reader);
|
|
64 /* */ }
|
|
65 /* */
|
|
66 /* */ public LanguageAnalyzer(String lang, Analyzer analyzer, File index_dir)
|
|
67 /* */ throws CorruptIndexException, LockObtainFailedException, IOException
|
|
68 /* */ {
|
|
69 /* 78 */ this(lang, analyzer, index_dir, false);
|
|
70 /* */ }
|
|
71 /* */ }
|
|
72
|
|
73 /* Location: /private/tmp/fulltextIndexer.jar
|
|
74 * Qualified Name: de.mpiwg.dwinter.lucencetools.analyzer.LanguageAnalyzer
|
|
75 * JD-Core Version: 0.5.4
|
|
76 */ |