svn commit: r526622 - in /xml/xindice/trunk/java/src/org/apache/xindice/core: Collection.java DocumentCache.java

[email protected]
Newsgroups gmane.text.xml.xindice.devel
Message-ID <[email protected]>
Author: vgritsenko
Date: Sun Apr  8 16:47:39 2007
New Revision: 526622

URL: http://svn.apache.org/viewvc?view=rev&rev=526622
Log:
uncompressed collection fixes:
- convert passed in document in putDocument to xindice document impl
- compress & flush symbol table when storing uncompressed document
- save document string, not document itself in the document cache
  so that when document is requested from cache, new copy is created.

Modified:
    xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/DocumentCache.java

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java?view=diff&rev=526622&r1=526621&r2=526622
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java Sun Apr  8 16:47:39 2007
@@ -697,6 +697,7 @@
                 if (log.isTraceEnabled()) {
                     log.trace(localDebugHeader + "Returning cached: " + document);
                 }
+
                 return document;
             }
         }
@@ -738,15 +739,17 @@
                     documentCache.putDocument(this, key, value.getData());
                 }
             } else {
+                String documentChars = value.toString();
                 if (log.isTraceEnabled()) {
-                    log.trace(localDebugHeader + "Pre parseDocument(): value=<" + value + ">");
+                    log.trace(localDebugHeader + "Pre parseDocument(): value=<" + documentChars + ">");
                 }
 
-                document = parseDocument(key, value.toString());
+                // FIXME These should be no reason here to re-compress the document & flush symbols table?
+                document = parseDocument(key, documentChars);
                 flushSymbolTable();
 
                 if (documentCache != null) {
-                    documentCache.putDocument(this, key, document);
+                    documentCache.putDocument(this, key, documentChars);
                 }
             }
 
@@ -1127,34 +1130,48 @@
          */
 
         byte[] documentBytes;
+        String documentChars = null;
 
         if (compressed) {
+            // Create compressed document bytes to be stored in the filer
             documentBytes = DOMCompressor.compress(document, symbols);
             if (log.isTraceEnabled()) {
                 log.trace(localDebugHeader + "length=" + documentBytes.length);
             }
 
-            // Why must it be re-created?
+            // Create xindice document with just compressed bytes.
+            // Passed in document might not necessarily be xindice document,
+            // but we should be passing only our documents to index manager.
             document = new DocumentImpl(documentBytes, symbols, new NodeSource(this, key));
+
             if (log.isTraceEnabled()) {
                 log.trace(localDebugHeader + "packedDocument: length=" + documentBytes.length +
                           " document=<" + TextWriter.toString(document) + ">");
             }
         } else {
+            // Create uncompressed document bytes to be stored in the filer
+            documentChars = TextWriter.toString(document);
             try {
-                documentBytes = TextWriter.toString(document).getBytes("utf-8");
-                if (log.isTraceEnabled()) {
-                    log.trace(localDebugHeader + "utf8Document: length=" + documentBytes.length +
-                              " document=<" + new String(documentBytes, "utf-8") + ">");
-                }
+                documentBytes = documentChars.getBytes("utf-8");
             } catch (UnsupportedEncodingException e) {
                 // Should never happen
                 throw new DBException(FaultCodes.GEN_FATAL_ERROR,
                                       "utf-8 encoding not supported", e);
             }
+
+            // Create xindice document from the string.
+            // In addition to converting passed document to xindice document
+            // instance, parseDocument() also updates the symbol table,
+            // if necessary.
+            document = parseDocument(key, documentChars);
+
+            if (log.isTraceEnabled()) {
+                log.trace(localDebugHeader + "utf8Document: length=" + documentBytes.length +
+                          " document=<" + documentChars + ">");
+            }
         }
 
-        // TODO: Move into if(compressed) ?
+        // Symbol table could have been updated above, flush it to the disk.
         flushSymbolTable();
 
         // Temporary until insert and update are separate
@@ -1164,9 +1181,7 @@
         }
         indexManager.addDocument(key, document);
 
-        /*
-         * Construct the Value object that is stored in the BTree.
-         */
+        // Construct the Value object that is stored in the BTree.
         Value value;
         if (inlineMetaService == null) {
             value = new Value(documentBytes);
@@ -1182,11 +1197,11 @@
             if (compressed) {
                 documentCache.putDocument(this, key, documentBytes);
             } else {
-                documentCache.putDocument(this, key, document);
+                documentCache.putDocument(this, key, documentChars);
             }
         }
 
-        // update the meta for this document
+        // Update the meta for this document
         updateDocumentMeta(key.toString());
         DBObserver.getInstance().putDocument(this, key, document, oldDoc == null);
     }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/DocumentCache.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/DocumentCache.java?view=diff&rev=526622&r1=526621&r2=526622
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/DocumentCache.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/DocumentCache.java Sun Apr  8 16:47:39 2007
@@ -25,6 +25,7 @@
 import org.apache.xindice.xml.NodeSource;
 import org.apache.xindice.xml.SymbolTable;
 import org.apache.xindice.xml.dom.DBDocument;
+import org.apache.xindice.xml.dom.DOMParser;
 import org.apache.xindice.xml.dom.DocumentImpl;
 
 import org.w3c.dom.Document;
@@ -64,6 +65,15 @@
             return null;
         } else if (v instanceof Document) {
             return (Document) v;
+        } else if (v instanceof String) {
+            try {
+                Document doc = DOMParser.toDocument((String) v);
+                ((DBDocument) doc).setSource(new NodeSource(col, key));
+            } catch (Exception e) {
+                if (log.isWarnEnabled()) {
+                    log.warn("ignored exception", e);
+                }
+            }
         } else if (v instanceof byte[]) {
             try {
                 SymbolTable s = col.getSymbols();
@@ -95,11 +105,11 @@
      *
      * @param col document collection
      * @param key document key
-     * @param doc document to store in the cache
+     * @param chars uncompressed document
      */
-    public void putDocument(Collection col, Key key, Document doc) {
+    public void putDocument(Collection col, Key key, String chars) {
         CacheKey ckey = new CacheKey(col, key);
-        table.put(ckey, doc);
+        table.put(ckey, chars);
     }
 
     /**
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.