package jules;

import java.io.File;

import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.*;
import org.apache.lucene.index.*;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;

import edu.jhu.nlp.wikipedia.*;


public class Indexer {
	public static void Main(String[] args){
		Indexer indexer = new Indexer();
		indexer.index();
	}
	private String wikiFile;
	private String indexDir;
	
	
	public Indexer(){
		wikiFile = "./svwiki-20141031-pages-meta-current.xml";
		indexDir = "./indexDir/";
	}
	
	public void index(){
		WikiXMLDOMParser wxp = new WikiXMLDOMParser(wikiFile);
		WikiPage page;
		Analyzer analyzer = new StandardAnalyzer();
		IndexWriterConfig iwc = new IndexWriterConfig(Version.LATEST, analyzer);
		try{
			IndexWriter writer = new IndexWriter(FSDirectory.open(new File(indexDir)), iwc);
			wxp.parse();
			WikiPageIterator it = wxp.getIterator();
			while(it.hasMorePages()){
				page = it.nextPage();
				Document doc = new Document();
				doc.add(new IntField("id", Integer.parseInt(page.getID()), Field.Store.NO));
				doc.add(new TextField("title", page.getTitle(), Field.Store.NO));
				doc.add(new TextField("text", page.getText(), Field.Store.NO));
				
				/*
				 * Check also
				 * 
				 * Infobox
				 * Categories
				 * Links
				 * Redirect pages
				 */
				
				writer.addDocument(doc);
			}
			writer.commit();
			writer.close();
		}catch(Exception e){ e.printStackTrace(); }
	}
}

@@ -631,27 +631,24 @@
 )%7B%0A%09%09WikiXML
-DOM
 Parser wxp =
@@ -651,20 +651,16 @@
 xp =
- new
  WikiXML
 DOMP
@@ -655,16 +655,33 @@
  WikiXML
+ParserFactory.get
 DOMParse
@@ -1068,24 +1068,100 @@
 Document();%0A
+%09%09%09%09System.out.println(page.getID() + %22: Adding File: %22 + page.getTitle());%0A
 %09%09%09%09doc.add(

change parser to parserfactory