You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2013/05/10 10:52:46 UTC

svn commit: r1480939 - in /stanbol/trunk/entityhub/yard/solr/src: main/java/org/apache/stanbol/entityhub/yard/solr/defaults/ main/java/org/apache/stanbol/entityhub/yard/solr/impl/ main/java/org/apache/stanbol/entityhub/yard/solr/model/ test/java/org/ap...

Author: rwesten
Date: Fri May 10 08:52:46 2013
New Revision: 1480939

URL: http://svn.apache.org/r1480939
Log:
fix for STANBOL-1065

Modified:
    stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/defaults/IndexDataTypeEnum.java
    stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java
    stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrQueryFactory.java
    stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
    stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/FieldMapper.java
    stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java

Modified: stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/defaults/IndexDataTypeEnum.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/defaults/IndexDataTypeEnum.java?rev=1480939&r1=1480938&r2=1480939&view=diff
==============================================================================
--- stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/defaults/IndexDataTypeEnum.java (original)
+++ stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/defaults/IndexDataTypeEnum.java Fri May 10 08:52:46 2013
@@ -17,15 +17,19 @@
 package org.apache.stanbol.entityhub.yard.solr.defaults;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Date;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.UUID;
 
 import javax.xml.datatype.Duration;
 
+import org.apache.stanbol.entityhub.servicesapi.defaults.DataTypeEnum;
 import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
 import org.apache.stanbol.entityhub.servicesapi.model.Reference;
 import org.apache.stanbol.entityhub.servicesapi.model.Text;
@@ -45,46 +49,54 @@ import org.apache.stanbol.entityhub.yard
  * 
  */
 public enum IndexDataTypeEnum {
-    BOOLEAN(NamespaceEnum.xsd + "boolean", "bool", Boolean.class),
+    BOOLEAN(NamespaceEnum.xsd + "boolean", "bool", Boolean.class, DataTypeEnum.Boolean),
     // BYTE("byt",Byte.class),
-    INT(NamespaceEnum.xsd + "int", "int", Integer.class),
-    LONG(NamespaceEnum.xsd + "long", "lon", Long.class),
-    FLOAT(NamespaceEnum.xsd + "float", "flo", Float.class),
-    DOUBLE(NamespaceEnum.xsd + "double", "dou", Double.class),
-    REF(RdfResourceEnum.ReferenceDataType.getUri(), "ref", Reference.class),
+    INT(NamespaceEnum.xsd + "int", "int", Integer.class, DataTypeEnum.Int),
+    LONG(NamespaceEnum.xsd + "long", "lon", Long.class, DataTypeEnum.Long, DataTypeEnum.Integer),
+    FLOAT(NamespaceEnum.xsd + "float", "flo", Float.class, DataTypeEnum.Float),
+    DOUBLE(NamespaceEnum.xsd + "double", "dou", Double.class, DataTypeEnum.Double, DataTypeEnum.Decimal),
+    REF(RdfResourceEnum.ReferenceDataType.getUri(), "ref", Reference.class, DataTypeEnum.AnyUri, DataTypeEnum.Reference),
     // URI(NamespaceEnum.xsd+"anyURI","uri",URI.class), //currently URIs are modelled as REF
     // TODO: DATE & DUR to be removed. The plan is to add explicit support for ranged queries over time
     // spans/points!
-    DATE(NamespaceEnum.xsd + "dateTime", "cal", Date.class),
-    DUR(NamespaceEnum.xsd + "duration", "dur", Duration.class),
-    TXT(RdfResourceEnum.TextDataType.getUri(), null, Text.class, true), // no type prefix, but typically
+    DATE(NamespaceEnum.xsd + "dateTime", "cal", Date.class, DataTypeEnum.Date, DataTypeEnum.DateTime, DataTypeEnum.Time),
+    DUR(NamespaceEnum.xsd + "duration", "dur", Duration.class, DataTypeEnum.Duration),
+    TXT(RdfResourceEnum.TextDataType.getUri(), null, Text.class, true, DataTypeEnum.Text), // no type prefix, but typically
                                                                         // languageType prefixes
-    STR(NamespaceEnum.xsd + "string", "str", String.class, true), // string values (not used for languageType)
+    STR(NamespaceEnum.xsd + "string", "str", String.class, true, DataTypeEnum.String), // string values (not used for languageType)
     ID(NamespaceEnum.xsd + "id", "id", UUID.class), ;
     private IndexDataType indexType;
     private Class<?> javaType;
     private String prefix;
     private String suffix;
+    private final Set<DataTypeEnum> dataTypes;
     /**
      * if true, values of this dataType should be treated as natural languageType texts and added to the
      * {@link SolrConst#LANG_MERGER_FIELD}
      */
     private boolean languageType;
 
-    IndexDataTypeEnum(String name, String prefix, Class<?> type) {
-        this(name, prefix, null, type, false);
+    IndexDataTypeEnum(String name, String prefix, Class<?> type, DataTypeEnum...dataTypes) {
+        this(name, prefix, null, type, false,dataTypes);
     }
 
-    IndexDataTypeEnum(String name, String prefix, Class<?> type, boolean language) {
-        this(name, prefix, null, type, language);
+    IndexDataTypeEnum(String name, String prefix, Class<?> type, boolean language,DataTypeEnum...dataTypes) {
+        this(name, prefix, null, type, language, dataTypes);
     }
 
-    IndexDataTypeEnum(String name, String prefix, String suffix, Class<?> type, boolean language) {
+    IndexDataTypeEnum(String name, String prefix, String suffix, Class<?> type, boolean language,DataTypeEnum...dataTypes) {
         this.indexType = new IndexDataType(name);
         this.prefix = prefix;
         this.suffix = suffix;
         this.javaType = type;
         this.languageType = language;
+        if(dataTypes == null || dataTypes.length < 1){
+            this.dataTypes = Collections.emptySet();
+        } else {
+            EnumSet<DataTypeEnum> types = EnumSet.noneOf(DataTypeEnum.class);
+            types.addAll(Arrays.asList(dataTypes));
+            this.dataTypes = Collections.unmodifiableSet(types);
+        }
     }
 
     /**
@@ -132,6 +144,14 @@ public enum IndexDataTypeEnum {
     public boolean isLanguageType() {
         return languageType;
     }
+    /**
+     * The Entityhub {@link DataTypeEnum datatypes} mapped to this SolrYard
+     * {@link IndexDataType}
+     * @return the mapped {@link DataTypeEnum}s
+     */
+    public Set<DataTypeEnum> getMappedDataTypes(){
+        return dataTypes;
+    }
 
     /*--------------------------------------------------------------------------
      * Code that reads the config and inits lookup tables (also checks config)
@@ -142,6 +162,8 @@ public enum IndexDataTypeEnum {
     private static Map<IndexDataType,IndexDataTypeEnum> indexTypeMap;
     private static Map<List<String>,IndexDataTypeEnum> prefixSuffixMap;
     private static Map<String,IndexDataTypeEnum> uriMap;
+    private static Map<DataTypeEnum,IndexDataTypeEnum> dataTypeMap;
+    
     static {
         /*
          * This inits the Mappings and also validates the configuration provided by the Enumeration!
@@ -150,6 +172,8 @@ public enum IndexDataTypeEnum {
         Map<IndexDataType,IndexDataTypeEnum> itm = new HashMap<IndexDataType,IndexDataTypeEnum>();
         Map<List<String>,IndexDataTypeEnum> psm = new HashMap<List<String>,IndexDataTypeEnum>();
         Map<String,IndexDataTypeEnum> um = new HashMap<String,IndexDataTypeEnum>();
+        Map<DataTypeEnum, IndexDataTypeEnum> dm = new HashMap<DataTypeEnum,IndexDataTypeEnum>();
+        
         for (IndexDataTypeEnum dt : IndexDataTypeEnum.values()) {
             if (jtm.containsKey(dt.javaType)) {
                 throw new IllegalStateException(String.format(
@@ -178,11 +202,19 @@ public enum IndexDataTypeEnum {
             } else {
                 um.put(dt.getIndexType().getId(), dt);
             }
+            //inverse mappings for IndexDataTypesEnum -> DataTypeEnum
+            for(DataTypeEnum mdt : dt.getMappedDataTypes()){
+                if(dm.put(mdt, dt) != null){
+                    throw new IllegalStateException(String.format(
+                        "Found multiple IndexDataTypes are mapped with DataType %s!",mdt));
+                }
+            }
         }
         javaTypeMap = Collections.unmodifiableMap(jtm);
         indexTypeMap = Collections.unmodifiableMap(itm);
         prefixSuffixMap = Collections.unmodifiableMap(psm);
         uriMap = Collections.unmodifiableMap(um);
+        dataTypeMap = Collections.unmodifiableMap(dm);
     }
 
     /**
@@ -238,4 +270,14 @@ public enum IndexDataTypeEnum {
     public static IndexDataTypeEnum forUri(String uri) {
         return uriMap.get(uri);
     }
+    
+    /**
+     * Lookup table for the IndexDataTypeEnum based on the Entityhub {@link DataTypeEnum}
+     * @param dt the {@link DataTypeEnum}
+     * @return the {@link IndexDataTypeEnum} or <code>null</code> if the parsed datatype is not mapped.
+     */
+    public static IndexDataTypeEnum forDataTyoe(DataTypeEnum dt){
+        return dataTypeMap.get(dt);
+    }
+    
 }

Modified: stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java?rev=1480939&r1=1480938&r2=1480939&view=diff
==============================================================================
--- stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java (original)
+++ stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java Fri May 10 08:52:46 2013
@@ -130,9 +130,9 @@ public class SolrFieldMapper implements 
      * 
      * @see LinkedHashMap#
      */
-    private final Map<IndexField,Collection<String>> indexFieldMappings = 
+    private final Map<IndexField,List<String>> indexFieldMappings = 
             //STANBOL-669: LRU chaches MUST BE synchronized!
-            Collections.synchronizedMap(new LRU<IndexField,Collection<String>>());
+            Collections.synchronizedMap(new LRU<IndexField,List<String>>());
     /**
      * The assumption is, that only a handful of fields appear in index documents. So it makes sense to keep
      * some mappings within a cache rather than calculating them again and again.
@@ -327,20 +327,30 @@ public class SolrFieldMapper implements 
     }
 
     @Override
-    public Collection<String> getFieldNames(IndexField indexField) throws IllegalArgumentException {
+    public Collection<String> getQueryFieldNames(IndexField indexField) throws IllegalArgumentException {
+        List<String> fields = getFieldNames(indexField);
+        if((indexField.getLanguages() != null && !indexField.getLanguages().isEmpty()) &&
+                IndexDataTypeEnum.forIndexType(indexField.getDataType()).isLanguageType()){
+            return fields.subList(0, fields.size()-1); //cut of the field with all languages
+        } else {
+            return fields;
+        }
+    }
+    @Override
+    public List<String> getFieldNames(IndexField indexField) throws IllegalArgumentException {
         if (indexField == null) {
             throw new IllegalArgumentException("The parsed IndexField name MUST NOT be NULL!");
         }
-        Collection<String> fieldNames = indexFieldMappings.get(indexField);
+        List<String> fieldNames = indexFieldMappings.get(indexField);
         if (fieldNames == null) {
             SpecialFieldEnum specialField = indexField.getSpecialField();//check for special field;
             if(specialField != null){
                 switch (specialField) {
                     case fullText:
-                        fieldNames = Collections.singleton(getFullTextSearchField());
+                        fieldNames = Collections.singletonList(getFullTextSearchField());
                         break;
                     case references:
-                        fieldNames = Collections.singleton(getReferredDocumentField());
+                        fieldNames = Collections.singletonList(getReferredDocumentField());
                         break;
                     default:
                         throw new IllegalStateException("Unsupported Special Field '"
@@ -349,7 +359,7 @@ public class SolrFieldMapper implements 
                             + "JIRA issue at https://issues.apache.org/jira/browse/STANBOL!");
                 }
             } else {
-                fieldNames = new HashSet<String>(2); //typically only 1 or 2 values
+                fieldNames = new ArrayList<String>(2); //typically only 1 or 2 values
                 IndexDataTypeEnum dataTypeConfig = IndexDataTypeEnum.forIndexType(indexField.getDataType());
                 if (dataTypeConfig == null) {
                     throw new IllegalStateException(String.format(

Modified: stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrQueryFactory.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrQueryFactory.java?rev=1480939&r1=1480938&r2=1480939&view=diff
==============================================================================
--- stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrQueryFactory.java (original)
+++ stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrQueryFactory.java Fri May 10 08:52:46 2013
@@ -25,6 +25,7 @@ import static org.apache.solr.common.par
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumMap;
 import java.util.HashMap;
@@ -37,11 +38,13 @@ import java.util.Map.Entry;
 
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.MoreLikeThisParams;
 import org.apache.stanbol.commons.solr.utils.SolrUtil;
 import org.apache.stanbol.entityhub.core.model.InMemoryValueFactory;
 import org.apache.stanbol.entityhub.core.query.DefaultQueryFactory;
+import org.apache.stanbol.entityhub.servicesapi.defaults.DataTypeEnum;
 import org.apache.stanbol.entityhub.servicesapi.defaults.SpecialFieldEnum;
 import org.apache.stanbol.entityhub.servicesapi.model.Representation;
 import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
@@ -118,6 +121,10 @@ public class SolrQueryFactory {
     private final IndexValueFactory indexValueFactory;
     private final ValueFactory valueFactory;
     private final Map<IndexConstraintTypeEnum,IndexConstraintTypeEncoder<?>> constraintEncoders;
+    /**
+     * {@link IndexConstraintTypeEncoder} used for MLT requests to encode the parsed fields
+     */
+    private final List<IndexConstraintTypeEncoder<IndexField>> mltFieldEncoders;
 
     private String domain;
     private Integer maxQueryResults = MAX_QUERY_RESULTS;
@@ -140,10 +147,12 @@ public class SolrQueryFactory {
         this.indexValueFactory = indexValueFactory;
         this.constraintEncoders = new HashMap<IndexConstraintTypeEnum,IndexConstraintTypeEncoder<?>>();
         // TODO: Make this configuration more flexible!
-        constraintEncoders.put(IndexConstraintTypeEnum.LANG, new LangEncoder(fieldMapper));
-        constraintEncoders.put(IndexConstraintTypeEnum.DATATYPE, new DataTypeEncoder(indexValueFactory,
-                fieldMapper));
-        constraintEncoders.put(IndexConstraintTypeEnum.FIELD, new FieldEncoder(fieldMapper));
+        IndexConstraintTypeEncoder<IndexField> langEncoder = new LangEncoder(fieldMapper);
+        constraintEncoders.put(IndexConstraintTypeEnum.LANG, langEncoder);
+        IndexConstraintTypeEncoder<IndexField> datatypeEncoder = new DataTypeEncoder(indexValueFactory, fieldMapper);
+        constraintEncoders.put(IndexConstraintTypeEnum.DATATYPE, datatypeEncoder);
+        IndexConstraintTypeEncoder<IndexField> fieldEncoder = new FieldEncoder(fieldMapper);
+        constraintEncoders.put(IndexConstraintTypeEnum.FIELD, fieldEncoder);
         constraintEncoders.put(IndexConstraintTypeEnum.EQ, new AssignmentEncoder(indexValueFactory));
         constraintEncoders.put(IndexConstraintTypeEnum.WILDCARD, new WildcardEncoder(indexValueFactory));
         constraintEncoders.put(IndexConstraintTypeEnum.REGEX, new RegexEncoder(indexValueFactory));
@@ -151,6 +160,7 @@ public class SolrQueryFactory {
         constraintEncoders.put(IndexConstraintTypeEnum.LE, new LeEncoder(indexValueFactory));
         constraintEncoders.put(IndexConstraintTypeEnum.GT, new GtEncoder(indexValueFactory));
         constraintEncoders.put(IndexConstraintTypeEnum.LT, new LtEncoder(indexValueFactory));
+        this.mltFieldEncoders = Arrays.asList(langEncoder,datatypeEncoder,fieldEncoder);
     }
 
     public enum SELECT {
@@ -182,12 +192,13 @@ public class SolrQueryFactory {
                 List<String> fields = new ArrayList<String>();
                 fields.add(fieldConstraint.getKey());
                 SimilarityConstraint simConstraint = (SimilarityConstraint) fieldConstraint.getValue();
-                IndexValue indexValue = indexValueFactory.createIndexValue(simConstraint.getContext());
+                final IndexValue contextValue = 
+                        indexValueFactory.createIndexValue(simConstraint.getContext());
                 fields.addAll(simConstraint.getAdditionalFields());
                 if(!similarityConstraintPresent){
                     similarityConstraintPresent = true; //similarity constraint present
                     //add the constraint to the query
-                    query.setQueryType(MLT_QUERY_TYPE);
+                    query.setRequestHandler(MLT_QUERY_TYPE);
                     query.set(MATCH_INCLUDE, false);
                     query.set(MIN_DOC_FREQ, 1);
                     query.set(MIN_TERM_FREQ, 1);
@@ -195,12 +206,16 @@ public class SolrQueryFactory {
                     query.set("mlt.boost", true); //testing
                     List<String> indexFields = new ArrayList<String>();
                     for(String field : fields){
+                        //we need to get the actual fields in the index for the
+                        //logical fields parsed with the constraint
+                        IndexDataTypeEnum mapedIndexTypeEnum = IndexDataTypeEnum.forDataTyoe(simConstraint.getContextType());
                         IndexField indexField = new IndexField(Collections.singletonList(field), 
-                            IndexDataTypeEnum.TXT.getIndexType());
-                        indexFields.addAll(fieldMapper.getFieldNames(indexField));
+                            mapedIndexTypeEnum == null ? null : mapedIndexTypeEnum.getIndexType(),
+                            simConstraint.getLanguages());
+                        indexFields.addAll(fieldMapper.getQueryFieldNames(indexField));
                     }
                     query.set(SIMILARITY_FIELDS, indexFields.toArray(new String[fields.size()]));
-                    query.set(STREAM_BODY, indexValue.getValue());
+                    query.set(STREAM_BODY, contextValue.getValue());
                     processedFieldConstraints.put(fieldConstraint.getKey(), fieldConstraint.getValue());
                 } else { //similarity constraint already present -> ignore further
                     //NOTE: users are informed about that by NOT including further

Modified: stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java?rev=1480939&r1=1480938&r2=1480939&view=diff
==============================================================================
--- stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java (original)
+++ stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java Fri May 10 08:52:46 2013
@@ -293,7 +293,7 @@ public class SolrYard extends AbstractYa
             }
         }
         if(query.getRequestHandler() == SolrQueryFactory.MLT_QUERY_TYPE){
-            log.info("{}",response);
+            log.debug("{}",response);
         }
         long queryTime = System.currentTimeMillis();
         // return a queryResultList
@@ -513,7 +513,7 @@ public class SolrYard extends AbstractYa
                     if(config.isMultiYardIndexLayout()){
                         //make sure we only delete the Entity only if it is  managed by 
                         //this Yard. Entities of other Yards MUST NOT be deleted!
-                        server.deleteByQuery(String.format("%s:%s AND %s:%s",
+                        server.deleteByQuery(String.format("%s:%s AND %s:\"%s\"",
                             fieldMapper.getDocumentDomainField(),
                             SolrUtil.escapeSolrSpecialChars(getId()),
                             fieldMapper.getDocumentIdField(),
@@ -560,7 +560,7 @@ public class SolrYard extends AbstractYa
                         //if someone parses an ID managed by an other yard we MUST NOT
                         //delete it!
                         for(String id : toRemove){
-                            server.deleteByQuery(String.format("%s:%s AND %s:%s",
+                            server.deleteByQuery(String.format("%s:%s AND %s:\"%s\"",
                                 fieldMapper.getDocumentDomainField(),
                                 SolrUtil.escapeSolrSpecialChars(getId()),
                                 fieldMapper.getDocumentIdField(),
@@ -1016,7 +1016,7 @@ public class SolrYard extends AbstractYa
                     if (num > 0) {
                         queryBuilder.append(" OR ");
                     }
-                    queryBuilder.append(String.format("%s:%s", fieldMapper.getDocumentIdField(),
+                    queryBuilder.append(String.format("%s:\"%s\"", fieldMapper.getDocumentIdField(),
                         SolrUtil.escapeSolrSpecialChars(uri)));
                     num++;
                 }
@@ -1074,7 +1074,7 @@ public class SolrYard extends AbstractYa
             }
         }
         solrQuery.setRows(1); // we query for the id, there is only one result
-        String queryString = String.format("%s:%s", fieldMapper.getDocumentIdField(),
+        String queryString = String.format("%s:\"%s\"", fieldMapper.getDocumentIdField(),
             SolrUtil.escapeSolrSpecialChars(uri));
         solrQuery.setQuery(queryString);
         QueryResponse queryResponse;

Modified: stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/FieldMapper.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/FieldMapper.java?rev=1480939&r1=1480938&r2=1480939&view=diff
==============================================================================
--- stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/FieldMapper.java (original)
+++ stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/FieldMapper.java Fri May 10 08:52:46 2013
@@ -97,6 +97,15 @@ public interface FieldMapper {
      *             if the parsed index field is <code>null</code>.
      */
     Collection<String> getFieldNames(IndexField indexField) throws IllegalArgumentException;
+    /**
+     * Getter for the actual field names representing the parsed logical {@link IndexField}
+     * in the context of a Query.
+     * @param indexField the index field
+     * @return the actual field names in the index that need to be searched for the
+     * finding values of the parsed {@link IndexField}
+     * @throws IllegalArgumentException
+     */
+    Collection<String> getQueryFieldNames(IndexField indexField) throws IllegalArgumentException;
 
     /**
      * Getter for the logical {@link IndexField} of an given fieldName, typically as found in a document

Modified: stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java?rev=1480939&r1=1480938&r2=1480939&view=diff
==============================================================================
--- stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java (original)
+++ stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java Fri May 10 08:52:46 2013
@@ -16,8 +16,9 @@
  */
 package org.apache.stanbol.entityhub.yard.solr;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import java.io.File;
 import java.io.IOError;
@@ -37,6 +38,7 @@ import org.apache.stanbol.commons.solr.m
 import org.apache.stanbol.commons.solr.managed.standalone.StandaloneManagedSolrServer;
 import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
 import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.apache.stanbol.entityhub.servicesapi.model.Text;
 import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
 import org.apache.stanbol.entityhub.servicesapi.query.QueryResultList;
 import org.apache.stanbol.entityhub.servicesapi.query.SimilarityConstraint;
@@ -130,7 +132,45 @@ public class SolrYardTest extends YardTe
     public void testSolrYardConfigInitWithNullID() {
         new SolrYardConfig(null, TEST_SOLR_CORE_NAME);
     }
-
+    /**
+     * Additional test for <a href="https://issues.apache.org/jira/browse/STANBOL-1065">
+     * STANBOL-1065</a>
+     * @throws YardException
+     */
+    @Test
+    public void testUriWithSpaces() throws YardException {
+        Yard yard = getYard();
+        String id1 = "http://www.example.com/with space";
+        String id2 = "http://www.example.com/other";
+        Representation test1 = create(id1,true);
+        Representation test2 = create(id2,true);
+        //now add a label containing space to id2
+        test1.addNaturalText(NamespaceEnum.rdfs+"label","expected result","en");
+        test2.addNaturalText(NamespaceEnum.rdfs+"label","space","en");
+        test2.addNaturalText(NamespaceEnum.rdfs+"comment","URIs with space got separated "
+            + "in queries causing parts in URIs after spaces to form full text " 
+            + "queries instead!","en");
+        yard.update(test1);
+        yard.update(test2);
+        //now try to query for some combination
+        assertNull("No Entity with ID 'http://www.example.com/with URIs' expected",
+            yard.getRepresentation("http://www.example.com/with URIs"));
+        assertNull("No Entity with ID 'http://www.example.com/with' expected",
+            yard.getRepresentation("http://www.example.com/with"));
+        //no check that lookups do work withspace uris
+        Representation result = yard.getRepresentation(id1);
+        assertNotNull("Entity with ID 'http://www.example.com/with space' expected",
+            result);
+        assertEquals("Entity with id '"+id1+"' expected, but got '"
+            + result.getId() + "' instead", id1, result.getId());
+        //finally test removal of Entities with space
+        yard.remove(id1);
+        assertNull("Entity with ID 'http://www.example.com/with space' got not deleted",
+            yard.getRepresentation(id1));
+        //and also clean up the 2nd entity used for the test
+        yard.remove(id2);
+    }
+    
     @Test
     public void testFieldQuery() throws YardException {
         // NOTE: this does not test if the updated view of the representation is