You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by mi...@apache.org on 2004/07/29 07:49:06 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/lucene/index AbstractDocumentCreator.java AbstractIndexer.java Index.java IndexIterator.java Indexer.java
michi 2004/07/28 22:49:06
Modified: src/java/org/apache/lenya/lucene/index
AbstractDocumentCreator.java AbstractIndexer.java
Index.java IndexIterator.java Indexer.java
Log:
incrementally indexing of a single document started
Revision Changes Path
1.9 +13 -2 cocoon-lenya/src/java/org/apache/lenya/lucene/index/AbstractDocumentCreator.java
Index: AbstractDocumentCreator.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/lucene/index/AbstractDocumentCreator.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AbstractDocumentCreator.java 11 May 2004 14:09:37 -0000 1.8
+++ AbstractDocumentCreator.java 29 Jul 2004 05:49:06 -0000 1.9
@@ -25,7 +25,11 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
+import org.apache.log4j.Category;
+
public class AbstractDocumentCreator implements DocumentCreator {
+ Category log = Category.getInstance(AbstractDocumentCreator.class);
+
/** Creates a new instance of AbstractDocumentCreator */
public AbstractDocumentCreator() {
}
@@ -72,10 +76,17 @@
// to tokenize the field into words.
doc.add(Field.Keyword("modified", DateField.timeToString(file.lastModified())));
+ // Add the id as a field, so that index can be incrementally maintained.
+ String id = IndexIterator.createID(file, htdocsDumpDir);
+ log.error(id);
+ doc.add(Field.Keyword("id", id));
+
// Add the uid as a field, so that index can be incrementally maintained.
// This field is not stored with document, it is indexed, but it is not
// tokenized prior to indexing.
- doc.add(new Field("uid", IndexIterator.createUID(file, htdocsDumpDir), false, true, false));
+ String uid = IndexIterator.createUID(file, htdocsDumpDir);
+ log.error(uid);
+ doc.add(new Field("uid", uid, false, true, false));
return doc;
}
1.18 +33 -2 cocoon-lenya/src/java/org/apache/lenya/lucene/index/AbstractIndexer.java
Index: AbstractIndexer.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/lucene/index/AbstractIndexer.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- AbstractIndexer.java 10 Jul 2004 23:17:24 -0000 1.17
+++ AbstractIndexer.java 29 Jul 2004 05:49:06 -0000 1.18
@@ -25,13 +25,14 @@
import java.util.Arrays;
import org.apache.log4j.Category;
+import org.apache.lenya.lucene.IndexConfiguration;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
-import org.w3c.dom.Element;
+import org.w3c.dom.Element;
/**
* Abstract base class for indexers.
@@ -91,6 +92,36 @@
public void updateIndex(File dumpDirectory, File index) throws Exception {
deleteStaleDocuments(dumpDirectory, index);
doIndex(dumpDirectory, index, false);
+ }
+
+ /**
+ * Updates the index re one document
+ *
+ * <ol>
+ * <li>old documents to be deleted</li>
+ * <li>unchanged documents, to be left alone, or</li>
+ * <li>new documents, to be indexed.</li>
+ * </ol>
+ */
+ public void indexDocument(File file) throws Exception {
+ IndexConfiguration config = new IndexConfiguration(configFileName);
+ log.debug("File: " + file);
+
+ File dumpDir = new File(config.resolvePath(config.getHTDocsDumpDir()));
+ log.debug("Dump dir: " + dumpDir);
+
+ File indexDir = new File(config.resolvePath(config.getIndexDir()));
+ log.debug("Index dir: " + indexDir);
+
+ String id = IndexIterator.createID(file, dumpDir);
+ log.error("id: " + id);
+
+ IndexReader reader = IndexReader.open(indexDir.getAbsolutePath());
+ //Term term = ...
+ //reader.delete(term);
+ reader.close();
+
+ //addFile(file);
}
/**
1.15 +21 -3 cocoon-lenya/src/java/org/apache/lenya/lucene/index/Index.java
Index: Index.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/lucene/index/Index.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Index.java 1 Mar 2004 16:18:15 -0000 1.14
+++ Index.java 29 Jul 2004 05:49:06 -0000 1.15
@@ -40,9 +40,9 @@
boolean create = false;
File root = null;
- String usage = "Index <lucene.xconf>";
+ String usage = "Index <lucene.xconf> [file]";
- if (argv.length != 1) {
+ if (argv.length == 0) {
System.err.println("Usage: " + usage);
return;
@@ -72,6 +72,11 @@
Document config = DocumentHelper.readDocument(new File(path));
indexer.configure(du.getElement(config.getDocumentElement(), new XPath("indexer")), argv[0]);
+ if (argv.length == 2) {
+ indexer.indexDocument(new File(argv[1]));
+ return;
+ }
+
if (create) {
indexer.createIndex(root, new File(index));
} else {
@@ -85,5 +90,18 @@
} catch (Exception e) {
e.printStackTrace(System.out);
}
+ }
+
+ /**
+ * Get indexer from configuration
+ */
+ public static Indexer getIndexer(String luceneConfig) throws Exception {
+ IndexConfiguration ie = new IndexConfiguration(luceneConfig);
+ Indexer indexer = (Indexer) ie.getIndexerClass().newInstance();
+ DOMUtil du = new DOMUtil();
+ Document config = DocumentHelper.readDocument(new File(luceneConfig));
+ indexer.configure(du.getElement(config.getDocumentElement(), new XPath("indexer")), luceneConfig);
+
+ return indexer;
}
}
1.13 +20 -1 cocoon-lenya/src/java/org/apache/lenya/lucene/index/IndexIterator.java
Index: IndexIterator.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/lucene/index/IndexIterator.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- IndexIterator.java 14 Apr 2004 13:06:41 -0000 1.12
+++ IndexIterator.java 29 Jul 2004 05:49:06 -0000 1.13
@@ -225,6 +225,25 @@
}
/**
+ * Create a unique id
+ *
+ * @param file file to index
+ * @param dumpDir dump directory
+ *
+ * @return id
+ */
+ public static String createID(File file, File dumpDir) {
+ if (dumpDir.getPath().length() <= file.getPath().length()) {
+ String id = file.getPath().substring(dumpDir.getPath().length());
+ //id = id.replace(File.separatorChar, '\u0000'));
+ return id;
+ } else {
+ log.warn("Length of dumping directory is less than length of file name!");
+ }
+ return null;
+ }
+
+ /**
* Append path and date into a string in such a way that lexicographic sorting gives the same
* results as a walk of the file hierarchy. Thus null (\u0000) is used both to separate
* directory components and to separate the path from the date.
1.11 +7 -1 cocoon-lenya/src/java/org/apache/lenya/lucene/index/Indexer.java
Index: Indexer.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/lucene/index/Indexer.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Indexer.java 1 Mar 2004 16:18:15 -0000 1.10
+++ Indexer.java 29 Jul 2004 05:49:06 -0000 1.11
@@ -40,4 +40,10 @@
*/
void updateIndex(File dumpDirectory, File index)
throws Exception;
+
+ /**
+ * Indexes the content of one file
+ */
+ void indexDocument(File file)
+ throws Exception;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org