01: package pygmy.nntp;
02:
03: import org.apache.lucene.document.Document;
04: import org.apache.lucene.index.IndexWriter;
05: import org.apache.lucene.analysis.Analyzer;
06: import org.apache.lucene.analysis.WhitespaceAnalyzer;
07:
08: import java.io.IOException;
09:
10: public class AbstractNewsSpool implements ArticleSpool {
11:
12: private Forum forum;
13: private Analyzer ws = new WhitespaceAnalyzer();
14:
15: public AbstractNewsSpool() {
16: }
17:
18: public void addArticle(Article article, String host)
19: throws IOException {
20: doAddArticle(article, host);
21: }
22:
23: public void setForum(Forum aForum) {
24: forum = aForum;
25: }
26:
27: protected void doAddArticle(Article article, String host)
28: throws IOException {
29: String[] newsgroup = article.getNewsgroups();
30: for (int i = 0; i < newsgroup.length; i++) {
31: NewsGroup group = forum.getNewsgroup(newsgroup[i]);
32: if (group != null) {
33: group.addArticle(article, host);
34: }
35: }
36: indexArticle(article);
37: }
38:
39: private void indexArticle(Article article) throws IOException {
40: Document doc = article.getOveriewDocument();
41: IndexWriter writer = new IndexWriter(
42: forum.getArticleOverview(), ws, true);
43: writer.addDocument(doc);
44: writer.close();
45: }
46: }
|