Ignore:
Timestamp:
2009-02-05T14:02:25+13:00 (15 years ago)
Author:
davidb
Message:

Support for reindexing documents

File:
1 edited

Legend:

Unmodified
Added
Removed
  • indexers/trunk/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneIndexer.java

    r18444 r18464  
    294294    public void startDocument() throws SAXException
    295295    {
    296         if (mode_.equals("index")) {
    297         println("Starting to index " + file_id_);
    298         print("[");
    299         }
     296        println("Starting to process " + file_id_);
     297        print("[");
    300298    }
    301299
    302300    public void endDocument() throws SAXException
    303301    {
    304         if (mode_.equals("index")) {
    305         println("]");
    306         println("... indexing finished.");
    307         }
     302        println("]");
     303        println("... processing finished.");
    308304    }
    309305
     
    311307        throws SAXException
    312308    {
    313         if (mode_.equals("index")) {
    314         path_ = appendPathLink(path_, qName, atts);
     309        path_ = appendPathLink(path_, qName, atts);
     310       
     311        if (qName.equals(doc_tag_level_)) {
     312        mode_ = atts.getValue("gs2:mode");
     313
     314        pushOnStack(); // start new doc
     315        current_node_ = qName;
    315316       
    316         if (qName.equals(doc_tag_level_)) {
    317             pushOnStack(); // start new doc
    318             current_node_ = qName;
    319            
    320             String node_id = atts.getValue("gs2:id");
    321             print(" " + qName + ": " + node_id );
    322             current_doc_.add(new Field("nodeID", node_id, Field.Store.YES, Field.Index.UN_TOKENIZED));
    323            
    324             current_doc_oid_ = atts.getValue("gs2:docOID");
    325             current_doc_.add(new Field("docOID", current_doc_oid_, Field.Store.YES, Field.Index.UN_TOKENIZED));
    326         }
     317        String node_id = atts.getValue("gs2:id");
     318        print(" " + qName + ": " + node_id + " (" + mode_ + ")" );
     319        current_doc_.add(new Field("nodeID", node_id, Field.Store.YES, Field.Index.UN_TOKENIZED));
    327320       
    328         if (isIndexable(atts)) {
    329             indexable_current_node_ = qName;   
    330         }
    331         else {
    332             indexable_current_node_ = "";
    333         }
     321        current_doc_oid_ = atts.getValue("gs2:docOID");
     322        current_doc_.add(new Field("docOID", current_doc_oid_, Field.Store.YES, Field.Index.UN_TOKENIZED));
     323        }
     324       
     325        if (isIndexable(atts)) {
     326        indexable_current_node_ = qName;   
     327        }
     328        else {
     329        indexable_current_node_ = "";
    334330        }
    335331    }
     
    350346    public void endElement(String uri, String localName, String qName) throws SAXException
    351347    {
    352         if (mode_.equals("index")) {
     348        if (mode_.equals("delete")) {
     349        try {
     350            deleteDocument(current_doc_oid_);
     351        }
     352        catch (java.io.IOException e) {
     353            e.printStackTrace();
     354        }
     355        }
     356        else if (mode_.equals("index") || mode_.equals("reindex")) {
    353357        if (qName.equals(indexable_current_node_))
    354358            {
     
    367371        if (qName.equals(doc_tag_level_)) {
    368372            try {
     373            // perhaps this is more efficient if addDocument()
     374            // used for "index" and updateDocument() for reindex
    369375            writer_.updateDocument(new Term("docOID", current_doc_oid_), current_doc_, analyzer_);
    370376            }
     
    376382       
    377383        path_ = removePathLink(path_);
    378         }
    379         else if (mode_.equals("delete")) {
    380         if (qName.equals("Delete")) {
    381             try {
    382             deleteDocument(current_contents_);
    383             current_contents_ = "";
    384             }
    385             catch (java.io.IOException e) {
    386             e.printStackTrace();
    387             }
    388         }
    389384        }
    390385    }
Note: See TracChangeset for help on using the changeset viewer.