Changeset 16429
- Timestamp:
- 2008-07-16T15:58:24+12:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
indexers/trunk/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneDelete.java
r13686 r16429 33 33 34 34 import java.io.IOException; 35 import java.util.Arrays;36 import java.util.Enumeration;37 import java.util.Vector;38 39 import org.apache.lucene.analysis.Analyzer;40 35 import org.apache.lucene.analysis.standard.StandardAnalyzer; 41 import org.apache.lucene. document.Document;42 import org.apache.lucene. document.Field;36 import org.apache.lucene.index.IndexWriter; 37 import org.apache.lucene.index.Term; 43 38 44 39 … … 61 56 { 62 57 // Parse arguments 58 String index_path = ""; 63 59 int node_id = -1; 64 String index_path = "";65 60 66 61 for (int i = 0; i < args.length; i += 2) 67 { 68 if (args[i].equals("--index")) 69 { 70 index_path = args[i + 1]; 71 } 72 else if (args[i].equals("--nodeid")) 73 { 74 String temp = args[i + 1]; 75 node_id = Integer.parseInt(temp); 76 temp = null; // Off to the gc with you! 77 } 78 else 79 { 80 System.out.println("Error! Unknown argument: " + args[i]); 81 GS2LuceneDelete.printUsage(); 82 } 83 } 62 { 63 if (args[i].equals("--index")) 64 { 65 index_path = args[i + 1]; 66 } 67 else if (args[i].equals("--nodeid")) 68 { 69 node_id = Integer.parseInt(args[i + 1]); 70 } 71 else 72 { 73 System.out.println("Error! Unknown argument: " + args[i]); 74 GS2LuceneDelete.printUsage(); 75 System.exit(0); 76 } 77 } 84 78 85 79 // Check arguments 86 if(index_path.equals("")) 87 { 88 System.out.println("Error! Missing index path"); 89 GS2LuceneDelete.printUsage(); 90 } 91 if(node_id == -1) 92 { 93 System.out.println("Error! Missing or invalid Node ID"); 94 GS2LuceneDelete.printUsage(); 95 } 96 80 if (index_path.equals("")) 81 { 82 System.out.println("Error! Missing index path"); 83 GS2LuceneDelete.printUsage(); 84 System.exit(0); 85 } 86 if (node_id == -1) 87 { 88 System.out.println("Error! Missing or invalid Node ID"); 89 GS2LuceneDelete.printUsage(); 90 System.exit(0); 91 } 97 92 98 93 // Instantiate deletor, and perform the delete … … 102 97 deletor = null; 103 98 } 104 /** main() **/105 99 106 /** **/107 private boolean debug = true;108 109 /** **/110 private GS2IndexModifier index_modifier;111 112 /** Constructor which takes the path to the Lucene index to be edited.113 *114 * @param index_path The full path to the index directory as a String115 */116 public GS2LuceneDelete(String index_path)117 throws IOException118 {119 Analyzer analyzer = new StandardAnalyzer();120 index_modifier = new GS2IndexModifier(index_path, analyzer);121 }122 /** GS2LuceneDelete **/123 124 /** When called prints a debug message but only if debugging is enabled.125 */126 public void debug(String message)127 {128 if(debug)129 {130 System.err.println(message);131 }132 }133 /** debug() **/134 135 /** Destructor which unallocates connection to Lucene.136 */137 public void destroy()138 throws IOException139 {140 index_modifier.close();141 index_modifier = null;142 }143 144 /** Delete the indicated document from the Lucene index. This process is145 * very similar to the initial step of index editing.146 *147 * @param node_id The unique identifier of a Lucene document as an148 * integer149 */150 public void deleteDocument(int node_id)151 throws IOException152 {153 debug("GS2LuceneDelete.deleteDocument(" + node_id + ")");154 debug("- Initial number of documents in index: " + index_modifier.docCount());155 // Retrieve the document requested156 int doc_num = index_modifier.getDocNumByNodeID(node_id);157 if (doc_num != -1)158 {159 debug("* Found document #" + doc_num);160 // Retrieve the actual document161 Document document = index_modifier.document(doc_num);162 // Remove the document from the index before modifying163 index_modifier.deleteDocument(doc_num);164 debug("* Removed document from index");165 }166 else167 {168 debug("- No such document!");169 }170 debug("- Final number of documents in index: " + index_modifier.docCount());171 }172 /** editIndex() **/173 100 174 101 /** Display program usage message. … … 184 111 System.out.println(" same as the docnum in the GDBM"); 185 112 System.out.println(""); 186 System.exit(0);187 113 } 188 /** printUsage() **/189 114 115 116 /** **/ 117 private boolean debug = true; 118 119 /** **/ 120 private IndexWriter index_writer = null; 121 122 123 /** Constructor which takes the path to the Lucene index to be edited. 124 * 125 * @param index_path The full path to the index directory as a String 126 */ 127 public GS2LuceneDelete(String index_path) 128 throws IOException 129 { 130 index_writer = new IndexWriter(index_path, new StandardAnalyzer()); 131 } 132 133 134 /** When called prints a debug message but only if debugging is enabled. 135 */ 136 public void debug(String message) 137 { 138 if (debug) 139 { 140 System.err.println(message); 141 } 142 } 143 144 145 /** Destructor which unallocates connection to Lucene. 146 */ 147 public void destroy() 148 throws IOException 149 { 150 index_writer.close(); 151 index_writer = null; 152 } 153 154 155 /** Delete the indicated document from the Lucene index. This process is 156 * very similar to the initial step of index editing. 157 * 158 * @param node_id The unique identifier of a Lucene document as an 159 * integer 160 */ 161 public void deleteDocument(int node_id) 162 throws IOException 163 { 164 debug("GS2LuceneDelete.deleteDocument(" + node_id + ")"); 165 debug("- Initial number of documents in index: " + index_writer.docCount()); 166 index_writer.deleteDocuments(new Term("nodeid", "" + node_id)); 167 debug("- Final number of documents in index: " + index_writer.docCount()); 168 } 190 169 } 191 /** class GS2LuceneDelete **/
Note:
See TracChangeset
for help on using the changeset viewer.