mirror of https://github.com/apache/lucene.git
SOLR-1120 followup -- Introduced a DocWrapper which takes care of maintaining document level session variables
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@769058 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6ea022f90b
commit
d7f7ca176f
|
@ -267,6 +267,7 @@ Other
|
|||
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 ==================
|
||||
|
|
|
@ -48,18 +48,21 @@ public class ContextImpl extends Context {
|
|||
|
||||
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 @@ public class ContextImpl extends Context {
|
|||
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 @@ public class ContextImpl extends Context {
|
|||
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 @@ public class ContextImpl extends Context {
|
|||
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 @@ public class ContextImpl extends Context {
|
|||
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 class ContextImpl extends Context {
|
|||
}
|
||||
}
|
||||
|
||||
public void setDocSession(Map<String, Object> docSession) {
|
||||
this.docSession = docSession;
|
||||
public void setDoc(DocBuilder.DocWrapper docWrapper) {
|
||||
this.doc = docWrapper;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ public class DataConfig {
|
|||
|
||||
public Entity parentEntity;
|
||||
|
||||
public EntityProcessor processor;
|
||||
public EntityProcessorWrapper processor;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public DataSource dataSrc;
|
||||
|
|
|
@ -38,7 +38,6 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||
* @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 @@ public class DocBuilder {
|
|||
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 @@ public class DocBuilder {
|
|||
}
|
||||
|
||||
@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 @@ public class DocBuilder {
|
|||
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 @@ public class DocBuilder {
|
|||
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 @@ public class DocBuilder {
|
|||
}
|
||||
importStatistics.rowsCount.incrementAndGet();
|
||||
if (doc != null) {
|
||||
handleSpecialCommands(arow);
|
||||
handleSpecialCommands(arow, doc);
|
||||
addFields(entity, doc, arow);
|
||||
}
|
||||
if (isRoot)
|
||||
|
@ -423,18 +415,21 @@ public class DocBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
doc.setDocumentBoost(value);
|
||||
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);
|
||||
}
|
||||
|
||||
private void handleSpecialCommands(Map<String, Object> arow) {
|
||||
public Object getSessionAttribute(String key) {
|
||||
return session == null ? null : session.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ public class DocBuilder {
|
|||
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 @@ public class DocBuilder {
|
|||
}
|
||||
|
||||
@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 @@ public class DocBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ public class DocBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
private EntityProcessor getEntityProcessor(DataConfig.Entity entity) {
|
||||
private EntityProcessorWrapper getEntityProcessor(DataConfig.Entity entity) {
|
||||
if (entity.processor != null)
|
||||
return entity.processor;
|
||||
EntityProcessor entityProcessor;
|
||||
|
|
Loading…
Reference in New Issue