You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by sh...@apache.org on 2009/04/27 18:55:47 UTC

svn commit: r769058 - in /lucene/solr/trunk/contrib/dataimporthandler: ./ src/main/java/org/apache/solr/handler/dataimport/

Author: shalin
Date: Mon Apr 27 16:55:46 2009
New Revision: 769058

URL: http://svn.apache.org/viewvc?rev=769058&view=rev
Log:
SOLR-1120 followup -- Introduced a DocWrapper which takes care of maintaining document level session variables

Modified:
    lucene/solr/trunk/contrib/dataimporthandler/CHANGES.txt
    lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/ContextImpl.java
    lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataConfig.java
    lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java

Modified: lucene/solr/trunk/contrib/dataimporthandler/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/CHANGES.txt?rev=769058&r1=769057&r2=769058&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/CHANGES.txt (original)
+++ lucene/solr/trunk/contrib/dataimporthandler/CHANGES.txt Mon Apr 27 16:55:46 2009
@@ -267,6 +267,7 @@
               EntityProcessor#destroy has been modified to be called once per parent-row at the end of row. A new
               method EntityProcessor#close is added which is called at the end of import. A new method
               Context#getResolvedEntityAttribute is added which returns the resolved value of an entity's attribute.
+              Introduced a DocWrapper which takes care of maintaining document level session variables.
               (Noble Paul, shalin)
 
 ================== Release 1.3.0 20080915 ==================

Modified: lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/ContextImpl.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/ContextImpl.java?rev=769058&r1=769057&r2=769058&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/ContextImpl.java (original)
+++ lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/ContextImpl.java Mon Apr 27 16:55:46 2009
@@ -48,18 +48,21 @@
 
   private DataImporter dataImporter;
 
-  private Map<String, Object> entitySession, globalSession, docSession;
+  private Map<String, Object> entitySession, globalSession;
+
+  DocBuilder.DocWrapper doc;
 
   DocBuilder docBuilder;
 
+
   public ContextImpl(DataConfig.Entity entity, VariableResolverImpl resolver,
                      DataSource ds, String currProcess,
                      Map<String, Object> global, ContextImpl parentContext, DocBuilder docBuilder) {
     this.entity = entity;
+    this.docBuilder = docBuilder;
     this.resolver = resolver;
     this.ds = ds;
     this.currProcess = currProcess;
-    this.docBuilder = docBuilder;
     if (docBuilder != null) {
       this.requestParams = docBuilder.requestParameters.requestParams;
       dataImporter = docBuilder.dataImporter;
@@ -90,9 +93,8 @@
       entity.dataSrc = dataImporter.getDataSourceInstance(entity, entity.dataSource, this);
     }
     if (entity.dataSrc != null && docBuilder != null && docBuilder.verboseDebug &&
-            currProcess == Context.FULL_DUMP) {
+             Context.FULL_DUMP.equals(currentProcess())) {
       //debug is not yet implemented properly for deltas
-
       entity.dataSrc = docBuilder.writer.getDebugLogger().wrapDs(entity.dataSrc);
     }
     return entity.dataSrc;
@@ -128,9 +130,9 @@
         globalSession.put(name, val);
       }
     } else if (Context.SCOPE_DOC.equals(scope)) {
-      Map<String, Object> docsession = getDocSession();
-      if (docsession != null)
-        docsession.put(name, val);
+      DocBuilder.DocWrapper doc = getDocument();
+      if (doc != null)
+        doc.setSessionAttribute(name, val);
     } else if (SCOPE_SOLR_CORE.equals(scope)){
       if(dataImporter != null) dataImporter.getCoreScopeSession().put(name, val);
     }
@@ -146,9 +148,8 @@
         return globalSession.get(name);
       }
     } else if (Context.SCOPE_DOC.equals(scope)) {
-      Map<String, Object> docsession = getDocSession();
-      if (docsession != null)
-        return docsession.get(name);
+      DocBuilder.DocWrapper doc = getDocument();      
+      return doc == null ? null: doc.getSessionAttribute(name);
     } else if (SCOPE_SOLR_CORE.equals(scope)){
        return dataImporter == null ? null : dataImporter.getCoreScopeSession().get(name);
     }
@@ -159,11 +160,11 @@
     return parent;
   }
 
-  public Map<String, Object> getDocSession() {
+  private DocBuilder.DocWrapper getDocument() {
     ContextImpl c = this;
     while (true) {
-      if (c.docSession != null)
-        return c.docSession;
+      if (c.doc != null)
+        return c.doc;
       if (c.parent != null)
         c = c.parent;
       else
@@ -171,8 +172,8 @@
     }
   }
 
-  public void setDocSession(Map<String, Object> docSession) {
-    this.docSession = docSession;
+  public void setDoc(DocBuilder.DocWrapper docWrapper) {
+    this.doc = docWrapper;
   }
 
 

Modified: lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataConfig.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataConfig.java?rev=769058&r1=769057&r2=769058&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataConfig.java (original)
+++ lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataConfig.java Mon Apr 27 16:55:46 2009
@@ -97,7 +97,7 @@
 
     public Entity parentEntity;
 
-    public EntityProcessor processor;
+    public EntityProcessorWrapper processor;
 
     @SuppressWarnings("unchecked")
     public DataSource dataSrc;

Modified: lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java?rev=769058&r1=769057&r2=769058&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java (original)
+++ lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java Mon Apr 27 16:55:46 2009
@@ -38,7 +38,6 @@
  * @since solr 1.3
  */
 public class DocBuilder {
-  public static final String DOC_BOOST = "$docBoost";
 
   private static final Logger LOG = LoggerFactory.getLogger(DocBuilder.class);
 
@@ -257,7 +256,7 @@
     Iterator<Map<String, Object>> pkIter = allPks.iterator();
     while (pkIter.hasNext()) {
       Map<String, Object> map = pkIter.next();
-      vri.addNamespace(DataConfig.IMPORTER_NS + ".delta", map);
+      vri.addNamespace(DataConfig.IMPORTER_NS_SHORT + ".delta", map);
       buildDocument(vri, null, map, root, true, null);
       pkIter.remove();
       // check for abort
@@ -286,11 +285,11 @@
   }
 
   @SuppressWarnings("unchecked")
-  private void buildDocument(VariableResolverImpl vr, SolrInputDocument doc,
+  private void buildDocument(VariableResolverImpl vr, DocWrapper doc,
                              Map<String, Object> pk, DataConfig.Entity entity, boolean isRoot,
                              ContextImpl parentCtx) {
 
-    EntityProcessor entityProcessor = getEntityProcessor(entity);
+    EntityProcessorWrapper entityProcessor = getEntityProcessor(entity);
 
     ContextImpl ctx = new ContextImpl(entity, vr, null,
             pk == null ? Context.FULL_DUMP : Context.DELTA_DUMP,
@@ -323,11 +322,8 @@
             writer.log(SolrWriter.START_DOC, entity.name, null);
           }
           if (doc == null && entity.isDocRoot) {
-            if (ctx.getDocSession() != null)
-              ctx.getDocSession().clear();
-            else
-              ctx.setDocSession(new HashMap<String, Object>());
-            doc = new SolrInputDocument();
+            doc = new DocWrapper();
+            ctx.setDoc(doc);
             DataConfig.Entity e = entity;
             while (e.parentEntity != null) {
               addFields(e.parentEntity, doc, (Map<String, Object>) vr
@@ -342,10 +338,6 @@
             break;            
           }
 
-          if (arow.containsKey(DOC_BOOST)) {
-            setDocumentBoost(doc, arow);
-          }
-
           // Support for start parameter in debug mode
           if (entity.isDocRoot) {
             if (seenDocCount <= requestParameters.start)
@@ -361,7 +353,7 @@
           }
           importStatistics.rowsCount.incrementAndGet();
           if (doc != null) {
-            handleSpecialCommands(arow);
+            handleSpecialCommands(arow, doc);
             addFields(entity, doc, arow);
           }
           if (isRoot)
@@ -423,18 +415,21 @@
     }
   }
 
-  private void setDocumentBoost(SolrInputDocument doc, Map<String, Object> arow) {
-    Object v = arow.get(DOC_BOOST);
-    float value = 1.0f;
-    if (v instanceof Number) {
-      value = ((Number) v).floatValue();
-    } else {
-      value = Float.parseFloat(v.toString());
+  static class DocWrapper extends SolrInputDocument {
+    //final SolrInputDocument solrDocument = new SolrInputDocument();
+    Map<String ,Object> session;
+
+    public void setSessionAttribute(String key, Object val){
+      if(session == null) session = new HashMap<String, Object>();
+      session.put(key, val);
+    }
+
+    public Object getSessionAttribute(String key) {
+      return session == null ? null : session.get(key);
     }
-    doc.setDocumentBoost(value);
   }
 
-  private void handleSpecialCommands(Map<String, Object> arow) {
+  private void handleSpecialCommands(Map<String, Object> arow, DocWrapper doc) {
     Object value = arow.get("$deleteDocById");
     if (value != null) {
       if (value instanceof Collection) {
@@ -453,11 +448,21 @@
         for (Object o : collection) {
           writer.deleteByQuery(o.toString());
         }
-
       } else {
         writer.deleteByQuery(value.toString());
       }
     }
+    value = arow.get("$docBoost");
+    if (value != null) {
+      float value1 = 1.0f;
+      if (value instanceof Number) {
+        value1 = ((Number) value).floatValue();
+      } else {
+        value1 = Float.parseFloat(value.toString());
+      }
+      doc.setDocumentBoost(value1);
+    }
+
     value = arow.get("$skipDoc");
     if (value != null) {
       if (Boolean.parseBoolean(value.toString())) {
@@ -475,7 +480,7 @@
   }
 
   @SuppressWarnings("unchecked")
-  private void addFields(DataConfig.Entity entity, SolrInputDocument doc, Map<String, Object> arow) {
+  private void addFields(DataConfig.Entity entity, DocWrapper doc, Map<String, Object> arow) {
     for (Map.Entry<String, Object> entry : arow.entrySet()) {
       String key = entry.getKey();
       Object value = entry.getValue();
@@ -502,7 +507,7 @@
     }
   }
 
-  private void addFieldToDoc(Object value, String name, float boost, boolean multiValued, SolrInputDocument doc) {
+  private void addFieldToDoc(Object value, String name, float boost, boolean multiValued, DocWrapper doc) {
     if (value instanceof Collection) {
       Collection collection = (Collection) value;
       if (multiValued) {
@@ -529,7 +534,7 @@
     }
   }
 
-  private EntityProcessor getEntityProcessor(DataConfig.Entity entity) {
+  private EntityProcessorWrapper getEntityProcessor(DataConfig.Entity entity) {
     if (entity.processor != null)
       return entity.processor;
     EntityProcessor entityProcessor;