1 16 package dlog4j.search; 17 18 import java.io.IOException ; 19 import java.util.List ; 20 21 import org.apache.lucene.analysis.Analyzer; 22 import org.apache.lucene.index.IndexReader; 23 import org.apache.lucene.index.IndexWriter; 24 import org.apache.lucene.queryParser.ParseException; 25 import org.apache.lucene.search.IndexSearcher; 26 import org.apache.lucene.search.Searcher; 27 import org.apache.lucene.store.Directory; 28 import org.apache.lucene.store.FSDirectory; 29 30 36 public abstract class SearchProxy { 37 38 public final static String SEGMENTS = "segments"; 39 43 public static SearchProxy getLogQuery() { 44 return new LogSearchProxy(); 45 } 46 47 51 public static SearchProxy getReplyQuery() { 52 return new ReplySearchProxy(); 53 } 54 55 62 public abstract List searchFor(int site,int catid,String word, int from, int count) throws IOException , ParseException; 63 64 70 public abstract int addIndex(Object obj) throws IOException ; 71 76 public abstract int deleteIndex(int[] id) throws IOException ; 77 78 83 public abstract int updateIndex(Object obj) throws IOException ; 84 88 public abstract IndexWriter getWriter() throws IOException ; 89 95 protected Searcher getSearcher(String idxPath) throws IOException { 96 Searcher searcher = null; 97 synchronized (getAnalyzer()) { 99 Directory searchDirectory = FSDirectory.getDirectory(idxPath, false); 100 IndexReader reader = IndexReader.open(searchDirectory); 101 searcher = new IndexSearcher(reader); 102 } 103 return searcher; 104 } 105 106 110 protected String getLogIndexPath() { 111 return SearchEnginePlugIn.getLogIndexPath(); 112 } 113 114 118 protected String getReplyIndexPath() { 119 return SearchEnginePlugIn.getReplyIndexPath(); 120 } 121 122 126 protected Analyzer getAnalyzer() { 127 return SearchEnginePlugIn.getAnalyzer(); 128 } 129 130 } 131 | Popular Tags |