Mercurial > hg > fulltextIndexer
view src/de/mpiwg/dwinter/lucencetools/analyzer/LanguageAnalyzer.java @ 0:dc7622afcfea default tip
initial
author | dwinter |
---|---|
date | Wed, 03 Nov 2010 12:33:16 +0100 |
parents | |
children |
line wrap: on
line source
/* */ package de.mpiwg.dwinter.lucencetools.analyzer; /* */ /* */ import java.io.File; /* */ import java.io.IOException; /* */ import org.apache.lucene.analysis.Analyzer; /* */ import org.apache.lucene.index.CorruptIndexException; /* */ import org.apache.lucene.index.IndexReader; /* */ import org.apache.lucene.index.IndexWriter; /* */ import org.apache.lucene.index.IndexWriter.MaxFieldLength; /* */ import org.apache.lucene.search.IndexSearcher; /* */ import org.apache.lucene.store.Directory; /* */ import org.apache.lucene.store.LockObtainFailedException; import org.apache.lucene.store.NIOFSDirectory; import org.apache.lucene.store.SimpleFSLockFactory; /* */ /* */ public class LanguageAnalyzer /* */ { /* */ public String lang; /* */ public Analyzer analyzer; /* 19 */ public IndexWriter writer = null; /* 20 */ public IndexReader reader = null; /* 21 */ public IndexSearcher searcher = null; /* */ /* */ public LanguageAnalyzer(String lang, Analyzer analyzer, File index_dir, boolean onlyReader) /* */ throws CorruptIndexException, LockObtainFailedException, IOException /* */ { /* 35 */ this.lang = lang; /* 36 */ this.analyzer = analyzer; /* */ /* 38 */ boolean create = true; /* */ /* 40 */ if (!index_dir.exists()) { /* 41 */ index_dir.mkdir(); /* */ } /* */ /* 44 */ File lang_dir = new File(index_dir.getAbsolutePath() + "/" + lang); /* 45 */ if (lang_dir.exists()) { /* 46 */ create = false; /* */ } File dirFile= new File(index_dir + "/" + lang); /* 48 */ Directory indexDirectory = new NIOFSDirectory(dirFile); /* */ indexDirectory.setLockFactory(new SimpleFSLockFactory(dirFile)); // TODO:ansonsten probleme wenn NFS mounts /* 50 */ if (!onlyReader) /* */ { /* 52 */ this.writer = /* 53 */ new IndexWriter(indexDirectory, /* 53 */ analyzer, IndexWriter.MaxFieldLength.UNLIMITED); /* */ } /* 55 */ if (!index_dir.exists()) /* */ { /* 58 */ return; /* */ } /* */ /* 62 */ create = true; /* */ /* 65 */ if (lang_dir.exists()) { /* 66 */ create = false; /* */ } /* 68 */ if (create) /* */ return; /* 70 */ IndexReader reader = IndexReader.open(indexDirectory); /* 71 */ this.reader = reader; /* 72 */ this.searcher = new IndexSearcher(reader); /* */ } /* */ /* */ public LanguageAnalyzer(String lang, Analyzer analyzer, File index_dir) /* */ throws CorruptIndexException, LockObtainFailedException, IOException /* */ { /* 78 */ this(lang, analyzer, index_dir, false); /* */ } /* */ } /* Location: /private/tmp/fulltextIndexer.jar * Qualified Name: de.mpiwg.dwinter.lucencetools.analyzer.LanguageAnalyzer * JD-Core Version: 0.5.4 */