mirror of https://github.com/apache/lucene.git
SOLR-2581: UIMAToSolrMapper wrongly instantiates Type with reflection
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1135009 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
39e48e33e2
commit
52e432be3a
|
@ -31,6 +31,9 @@ Bug Fixes
|
||||||
* SOLR-2579: UIMAUpdateRequestProcessor ignore error fails if text.length() < 100.
|
* SOLR-2579: UIMAUpdateRequestProcessor ignore error fails if text.length() < 100.
|
||||||
(Elmer Garduno via koji)
|
(Elmer Garduno via koji)
|
||||||
|
|
||||||
|
* SOLR-2581: UIMAToSolrMapper wrongly instantiates Type with reflection.
|
||||||
|
(Tommaso Teofili via koji)
|
||||||
|
|
||||||
================== 3.2.0 ==================
|
================== 3.2.0 ==================
|
||||||
|
|
||||||
Upgrading from Solr 3.1
|
Upgrading from Solr 3.1
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
import org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField;
|
import org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField;
|
||||||
|
import org.apache.solr.uima.processor.exception.FieldMappingException;
|
||||||
import org.apache.uima.cas.FSIterator;
|
import org.apache.uima.cas.FSIterator;
|
||||||
import org.apache.uima.cas.FeatureStructure;
|
import org.apache.uima.cas.FeatureStructure;
|
||||||
import org.apache.uima.cas.Type;
|
import org.apache.uima.cas.Type;
|
||||||
|
@ -49,27 +50,24 @@ public class UIMAToSolrMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* map features of a certain UIMA type to corresponding Solr fields based on the mapping
|
* map features of a certain UIMA type to corresponding Solr fields based on the mapping
|
||||||
*
|
*
|
||||||
* @param typeName
|
* @param typeName name of UIMA type to map
|
||||||
* name of UIMA type to map
|
|
||||||
* @param featureFieldsmapping
|
* @param featureFieldsmapping
|
||||||
*/
|
*/
|
||||||
public void map(String typeName, Map<String, MapField> featureFieldsmapping) {
|
public void map(String typeName, Map<String, MapField> featureFieldsmapping) throws FieldMappingException {
|
||||||
try {
|
try {
|
||||||
FeatureStructure fsMock = (FeatureStructure) Class.forName(typeName).getConstructor(
|
Type type = cas.getTypeSystem().getType(typeName);
|
||||||
JCas.class).newInstance(cas);
|
|
||||||
Type type = fsMock.getType();
|
|
||||||
for (FSIterator<FeatureStructure> iterator = cas.getFSIndexRepository().getAllIndexedFS(type); iterator
|
for (FSIterator<FeatureStructure> iterator = cas.getFSIndexRepository().getAllIndexedFS(type); iterator
|
||||||
.hasNext();) {
|
.hasNext(); ) {
|
||||||
FeatureStructure fs = iterator.next();
|
FeatureStructure fs = iterator.next();
|
||||||
for (String featureName : featureFieldsmapping.keySet()) {
|
for (String featureName : featureFieldsmapping.keySet()) {
|
||||||
MapField mapField = featureFieldsmapping.get(featureName);
|
MapField mapField = featureFieldsmapping.get(featureName);
|
||||||
String fieldNameFeature = mapField.getFieldNameFeature();
|
String fieldNameFeature = mapField.getFieldNameFeature();
|
||||||
String fieldNameFeatureValue = fieldNameFeature == null ? null :
|
String fieldNameFeatureValue = fieldNameFeature == null ? null :
|
||||||
fs.getFeatureValueAsString(type.getFeatureByBaseName(fieldNameFeature));
|
fs.getFeatureValueAsString(type.getFeatureByBaseName(fieldNameFeature));
|
||||||
String fieldName = mapField.getFieldName(fieldNameFeatureValue);
|
String fieldName = mapField.getFieldName(fieldNameFeatureValue);
|
||||||
log.info(new StringBuffer("mapping ").append(typeName).append("@").append(featureName)
|
log.info(new StringBuffer("mapping ").append(typeName).append("@").append(featureName)
|
||||||
.append(" to ").append(fieldName).toString());
|
.append(" to ").append(fieldName).toString());
|
||||||
String featureValue = null;
|
String featureValue = null;
|
||||||
if (fs instanceof Annotation && "coveredText".equals(featureName)) {
|
if (fs instanceof Annotation && "coveredText".equals(featureName)) {
|
||||||
featureValue = ((Annotation) fs).getCoveredText();
|
featureValue = ((Annotation) fs).getCoveredText();
|
||||||
|
@ -77,12 +75,13 @@ public class UIMAToSolrMapper {
|
||||||
featureValue = fs.getFeatureValueAsString(type.getFeatureByBaseName(featureName));
|
featureValue = fs.getFeatureValueAsString(type.getFeatureByBaseName(featureName));
|
||||||
}
|
}
|
||||||
log.info(new StringBuffer("writing ").append(featureValue).append(" in ").append(
|
log.info(new StringBuffer("writing ").append(featureValue).append(" in ").append(
|
||||||
fieldName).toString());
|
fieldName).toString());
|
||||||
document.addField(fieldName, featureValue, 1.0f);
|
document.addField(fieldName, featureValue, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getLocalizedMessage());
|
throw new FieldMappingException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,24 +17,23 @@ package org.apache.solr.uima.processor;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
|
||||||
import org.apache.solr.common.SolrException.ErrorCode;
|
import org.apache.solr.common.SolrException.ErrorCode;
|
||||||
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField;
|
import org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField;
|
||||||
import org.apache.solr.uima.processor.ae.AEProvider;
|
import org.apache.solr.uima.processor.ae.AEProvider;
|
||||||
import org.apache.solr.uima.processor.ae.AEProviderFactory;
|
import org.apache.solr.uima.processor.ae.AEProviderFactory;
|
||||||
import org.apache.solr.update.AddUpdateCommand;
|
import org.apache.solr.update.AddUpdateCommand;
|
||||||
import org.apache.solr.update.processor.UpdateRequestProcessor;
|
import org.apache.solr.update.processor.UpdateRequestProcessor;
|
||||||
import org.apache.uima.UIMAException;
|
|
||||||
import org.apache.uima.analysis_engine.AnalysisEngine;
|
import org.apache.uima.analysis_engine.AnalysisEngine;
|
||||||
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
|
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
|
||||||
import org.apache.uima.jcas.JCas;
|
import org.apache.uima.jcas.JCas;
|
||||||
import org.apache.uima.resource.ResourceInitializationException;
|
import org.apache.uima.resource.ResourceInitializationException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update document(s) to be indexed with UIMA extracted information
|
* Update document(s) to be indexed with UIMA extracted information
|
||||||
*
|
*
|
||||||
|
@ -69,7 +68,7 @@ public class UIMAUpdateRequestProcessor extends UpdateRequestProcessor {
|
||||||
String[] texts = getTextsToAnalyze(solrInputDocument);
|
String[] texts = getTextsToAnalyze(solrInputDocument);
|
||||||
for (int i = 0; i < texts.length; i++) {
|
for (int i = 0; i < texts.length; i++) {
|
||||||
text = texts[i];
|
text = texts[i];
|
||||||
if (text != null && !"".equals(text)) {
|
if (text != null && text.length()>0) {
|
||||||
/* process the text value */
|
/* process the text value */
|
||||||
JCas jcas = processText(text);
|
JCas jcas = processText(text);
|
||||||
|
|
||||||
|
@ -83,7 +82,7 @@ public class UIMAUpdateRequestProcessor extends UpdateRequestProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (UIMAException e) {
|
} catch (Exception e) {
|
||||||
String logField = solrUIMAConfiguration.getLogField();
|
String logField = solrUIMAConfiguration.getLogField();
|
||||||
String optionalFieldInfo = logField == null ? "." :
|
String optionalFieldInfo = logField == null ? "." :
|
||||||
new StringBuilder(". ").append(logField).append("=")
|
new StringBuilder(". ").append(logField).append("=")
|
||||||
|
@ -110,7 +109,7 @@ public class UIMAUpdateRequestProcessor extends UpdateRequestProcessor {
|
||||||
private String[] getTextsToAnalyze(SolrInputDocument solrInputDocument) {
|
private String[] getTextsToAnalyze(SolrInputDocument solrInputDocument) {
|
||||||
String[] fieldsToAnalyze = solrUIMAConfiguration.getFieldsToAnalyze();
|
String[] fieldsToAnalyze = solrUIMAConfiguration.getFieldsToAnalyze();
|
||||||
boolean merge = solrUIMAConfiguration.isFieldsMerging();
|
boolean merge = solrUIMAConfiguration.isFieldsMerging();
|
||||||
String[] textVals = null;
|
String[] textVals;
|
||||||
if (merge) {
|
if (merge) {
|
||||||
StringBuilder unifiedText = new StringBuilder("");
|
StringBuilder unifiedText = new StringBuilder("");
|
||||||
for (int i = 0; i < fieldsToAnalyze.length; i++) {
|
for (int i = 0; i < fieldsToAnalyze.length; i++) {
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package org.apache.solr.uima.processor.exception;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception thrown when an error happening while mapping UIMA CAS model to Solt fields
|
||||||
|
*/
|
||||||
|
public class FieldMappingException extends Exception {
|
||||||
|
public FieldMappingException(Exception e) {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue