001    /**
002     * LuceneDocument.java
003     * jCOLIBRI2 framework. 
004     * @author Juan A. Recio-García.
005     * GAIA - Group for Artificial Intelligence Applications
006     * http://gaia.fdi.ucm.es
007     * 10/04/2007
008     */
009    package jcolibri.extensions.textual.lucene;
010    
011    import jcolibri.datatypes.Text;
012    
013    import org.apache.lucene.document.Document;
014    import org.apache.lucene.document.Field;
015    
016    /**
017     * Wraps a Lucene document object. 
018     * This wrapper defines an unique ID for each document and allows to add different fields.<br>
019     * A Lucene document is divided into several fields. This allows to search only in some of them.
020     * 
021     * @author Juan A. Recio-García
022     * @version 2.0
023     */
024    public class LuceneDocument {
025    
026        Document doc;
027        public static String ID_FIELD = "ID";
028        
029        public LuceneDocument(String docID)
030        {
031            doc = new Document();
032            setDocID(docID);
033        }
034        
035        protected Document getInternalDocument()
036        {
037            return doc;
038        }
039        
040        
041        public void setDocID(String id)
042        {
043            doc.add(new Field(ID_FIELD, id, Field.Store.YES, Field.Index.NO));      
044        }
045        public String getDocID()
046        {
047            return doc.get(ID_FIELD);
048        }
049        
050        public void addContentField(String fieldname, Text content)
051        {
052            doc.add(new Field(fieldname, content.toString(), Field.Store.YES, Field.Index.TOKENIZED));
053        }
054        public String getContentField(String fieldname)
055        {
056            return doc.get(fieldname);
057        }
058    }