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 2011/07/22 12:50:24 UTC

svn commit: r1149562 - in /incubator/stanbol/trunk/entityhub: generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/ generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/ jersey/src/main/java/org/apache/stanbo...

Author: rwesten
Date: Fri Jul 22 10:50:21 2011
New Revision: 1149562

URL: http://svn.apache.org/viewvc?rev=1149562&view=rev
Log:
STANBOL-297: Implementation of multiple text constraint that are treaded as OR

TextConstraint:

* For API changes please see the STANBOL-297
* Decided to return null instead of an empty list for getTexts() in case no TextConstraint is set. This will not require to change code if users just rename getText() to getTexts() and want to check if no textConstraint is set
* Empty an NULL elements parsed as Text Constraints are filtered. If after filtering no textConstraints are left, than null will be returned by getTexts()

SPARQL implementation:

* For Virtuoso the bif:contain feature is used for implementation
* For Larq the documentation says that the normal Lucene query syntax can be used. However the implementation was not tested because no LARQ server was available for testing
* For standard SPARQL 1.0 multiple filters are connected with '||'
* Score Boosts are not implemented. However an implementation for LARQ and Virtuoso should be possible.

Solr implementation:

* Queries are translated to nested OR and AND
* Scores are automatically provided by Solr

Documetnation:

* Updated the Documentation of the Query interface in the RESTful API documentation of the Entityhub to reflect this new feature

BugFix:

* Corrected a Bug in the SolrQuery generation. But I think nobody encountered it yet because in such case invalid SolrQueries would have had generated.
* Deleted the duplicate JSONToFieldQuery class that got somehow re-added to SVN after renaming it

Removed:
    incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/JSONToFieldQuery.java
Modified:
    incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/DefaultFieldMapperImpl.java
    incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/FieldMappingUtils.java
    incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/TextConstraint.java
    incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java
    incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java
    incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_query.ftl
    incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_query.ftl
    incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_query.ftl
    incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/SparqlQueryUtils.java
    incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java
    incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrQueryFactory.java
    incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
    incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYardConfig.java
    incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/AssignmentEncoder.java
    incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/RegexEncoder.java
    incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/WildcardEncoder.java
    incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/ConstraintTypePosition.java
    incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/QueryUtils.java
    incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java

Modified: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/DefaultFieldMapperImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/DefaultFieldMapperImpl.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/DefaultFieldMapperImpl.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/DefaultFieldMapperImpl.java Fri Jul 22 10:50:21 2011
@@ -355,7 +355,7 @@ public class DefaultFieldMapperImpl impl
      * @return the modified collection to allow nested calls
      */
     private Collection<Object> processFilter(TextConstraint textConstraint, Collection<Object> values,boolean filterNonTextValues) {
-        if(textConstraint.getText() != null){
+        if(textConstraint.getTexts() != null){
             log.warn("Filtering based on values is not implemented");
         }
         /*

Modified: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/FieldMappingUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/FieldMappingUtils.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/FieldMappingUtils.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/FieldMappingUtils.java Fri Jul 22 10:50:21 2011
@@ -295,7 +295,7 @@ public final class FieldMappingUtils {
                 log.warn("Unable to parse a language form \"%s\"! A language filter MUST define at least a singel language. No filter will be used."+filterString);
                 return null;
             } else {
-                return new TextConstraint(null,langs);
+                return new TextConstraint((String)null,langs);
             }
         } else {
             log.warn(String.format("Filters need to start with \"p=\" (dataType) or \"@=\" (language). Parsed filter: \"%s\".",filterString));

Modified: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/TextConstraint.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/TextConstraint.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/TextConstraint.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/TextConstraint.java Fri Jul 22 10:50:21 2011
@@ -16,9 +16,12 @@
  */
 package org.apache.stanbol.entityhub.servicesapi.query;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.Set;
 
 
@@ -42,24 +45,59 @@ public class TextConstraint extends Cons
     private final PatternType wildcardType;
     private final Set<String> languages;
     private final boolean caseSensitive;
-    private final String text;
+    private final List<String> texts;
+    /**
+     * Creates a TextConstraint for multiple texts and languages. Parsed texts
+     * are connected using OR and may appear in any of the parsed languages.
+     * @param text the texts or <code>null</code> to search for any text in active languages
+     * @param languages the set of active languages
+     */
+    public TextConstraint(List<String> text,String...languages) {
+        this(text,PatternType.none,false,languages);
+    }
     /**
      * Creates a TextConstraint for a text and languages.
      * @param text the text or <code>null</code> to search for any text in active languages
      * @param languages the set of active languages.
      */
     public TextConstraint(String text,String...languages) {
-        this(text,PatternType.none,false,languages);
+        this(text == null || text.isEmpty() ? null : Collections.singletonList(text),
+                PatternType.none,false,languages);
     }
-    public TextConstraint(String text,boolean caseSensitive,String...languages) {
+    public TextConstraint(List<String> text,boolean caseSensitive,String...languages) {
         this(text,PatternType.none,caseSensitive,languages);
     }
+    public TextConstraint(String text,boolean caseSensitive,String...languages) {
+        this(text == null || text.isEmpty() ? null : Collections.singletonList(text),
+                PatternType.none,caseSensitive,languages);
+    }
     public TextConstraint(String text,PatternType wildcardType,boolean caseSensitive,String...languages) {
+        this(text == null || text.isEmpty() ? null : Collections.singletonList(text),
+                wildcardType,caseSensitive,languages);
+    }
+    public TextConstraint(List<String> text,PatternType wildcardType,boolean caseSensitive,String...languages) {
         super(ConstraintType.text);
-        if((text == null || text.isEmpty()) && (languages == null || languages.length<1)){
+        //create a local copy and filter null and empty elements
+        if(text == null || text.isEmpty()){
+            this.texts = null;
+        } else {
+            List<String> processedText = new ArrayList<String>(text);
+            for(Iterator<String> constraints = processedText.iterator();constraints.hasNext();){
+                String constraint = constraints.next();
+                if(constraint == null || constraint.isEmpty()){
+                    constraints.remove(); //remove null and empty elements
+                }
+            }
+            if(processedText.isEmpty()){
+                this.texts = null;
+            } else {
+                this.texts = Collections.unmodifiableList(processedText);
+            }
+        }
+        //check that we have at least a text or a language
+        if(this.texts == null && (languages == null || languages.length<1)){
             throw new IllegalArgumentException("Text Constraint MUST define a non empty text OR a non empty list of language constraints");
         }
-        this.text = text;
         if(wildcardType == null){
             this.wildcardType = PatternType.none;
         } else {
@@ -83,33 +121,48 @@ public class TextConstraint extends Cons
 
     }
     /**
+     * The pattern type to be used for this query.
      * @return the wildcardType
      */
     public final PatternType getPatternType() {
         return wildcardType;
     }
     /**
+     * The set of languages for this query.
      * @return the languages
      */
     public final Set<String> getLanguages() {
         return languages;
     }
     /**
-     * @return the caseSensitive
+     * If the query is case sensitive
+     * @return the caseSensitive state
      */
     public final boolean isCaseSensitive() {
         return caseSensitive;
     }
     /**
-     * @return the text
+     * Getter for the text constraints. Multiple constraints need to be connected
+     * with OR. For AND simple post all required words in a single String.
+     * @return the text constraints
+     */
+    public final List<String> getTexts() {
+        return texts;
+    }
+    /**
+     * Getter for the first text constraint. If multiple constrains are set only
+     * the first one will be returned.
+     * @return the fist text constraint (of possible multiple text constraints)
+     * @deprecated 
      */
-    public final String getText() {
-        return text;
+    @Deprecated
+    public final String getText(){
+        return texts == null || texts.isEmpty() ? null : texts.get(0);
     }
     @Override
     public String toString() {
         return String.format("TextConstraint[value=%s|%s|case %sensitive|languages:%s]",
-                text,wildcardType.name(),caseSensitive?"":"in",languages);
+                texts,wildcardType.name(),caseSensitive?"":"in",languages);
     }
 
 }

Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java Fri Jul 22 10:50:21 2011
@@ -23,6 +23,8 @@ import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
 
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.HttpHeaders;
@@ -325,7 +327,17 @@ public class FieldQueryReader implements
         }
         //parse text and create constraint
         if(jConstraint.has("text") && !jConstraint.isNull("text")){
-            constraint = new TextConstraint(jConstraint.getString("text"),
+            List<String> textConstraints;
+            JSONArray jTextConstraints = jConstraint.optJSONArray("text");
+            if(jTextConstraints != null){
+                textConstraints = new ArrayList<String>(jTextConstraints.length());
+                for(int i=0;i<jTextConstraints.length();i++){
+                   textConstraints.add(jTextConstraints.getString(i));
+                }
+            } else {
+                textConstraints = Collections.singletonList(jConstraint.getString("text"));
+            }
+            constraint = new TextConstraint(textConstraints,
                 patternType,caseSensitive,
                 languages == null?null:languages.toArray(new String[languages.size()]));
         } else {

Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java Fri Jul 22 10:50:21 2011
@@ -102,8 +102,12 @@ final class FieldQueryToJSON {
                     jConstraint.put("languages", new JSONArray(textConstraint.getLanguages()));
                 }
                 jConstraint.put("patternType", textConstraint.getPatternType().name());
-                if (textConstraint.getText() != null && !textConstraint.getText().isEmpty()) {
-                    jConstraint.put("text", textConstraint.getText());
+                if (textConstraint.getTexts() != null && !textConstraint.getTexts().isEmpty()) {
+                    if(textConstraint.getTexts().size() == 1){ //write a string
+                        jConstraint.put("text", textConstraint.getTexts().get(0));
+                    } else { //write an array
+                        jConstraint.put("text", textConstraint.getTexts());
+                    }
                 }
                 if(textConstraint.isCaseSensitive()){
                     jConstraint.put("caseSensitive", true);

Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_query.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_query.ftl?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_query.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_query.ftl Fri Jul 22 10:50:21 2011
@@ -144,7 +144,13 @@ TextConstraint for this</p>
 
 <p>Additional key:</p>
 <ul>
-    <li><code>text</code>: the text to search (required)</li>
+    <li><code>text</code>: the text to search (required). If multiple values
+        are parsed, that those values are connected by using OR.<br>
+        Parsing "Barack Obama" returns Entities that contain "Barack Obama" as
+        value for the field. Parsing ["Barack","Obama"] will return all Entities
+        that contain any of the two words. Most Sites however will boost results
+        that contain both values over such that only contain a single one. 
+    </li>
     <li><code>languages</code>: json array with the languages to search 
         (default is all languages) </li>
     <li><code>patternType</code>: one of "wildcard", "regex" or "none" 
@@ -154,8 +160,12 @@ TextConstraint for this</p>
 
 <h5>Example:</h5>
 
-<p>Searches for entities with an german rdfs:label starting with "Frankf"</p>
-
+<p>
+(1) Searches for entities with an german rdfs:label starting with "Frankf"<br>
+(2) Searches for entities that contain "Frankfurt" OR "Main" OR "Airport".
+Typically the "Frankfurt am Main Airport" should be ranked first because it
+contains all the optional terms.
+</p>
 <code><pre>
 { 
    "type": "text", 
@@ -164,6 +174,11 @@ TextConstraint for this</p>
    "text": "Frankf*", 
    "field": "http:\/\/www.w3.org\/2000\/01\/rdf-schema#label" 
 }, 
+{ 
+   "type": "text", 
+   "text": ["Frankfurt","Main","Airport"] 
+   "field": "http:\/\/www.w3.org\/2000\/01\/rdf-schema#label" 
+}, 
 </pre></code>
 
 <h4>Range Constraint: </h4>

Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_query.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_query.ftl?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_query.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_query.ftl Fri Jul 22 10:50:21 2011
@@ -144,7 +144,13 @@ TextConstraint for this</p>
 
 <p>Additional key:</p>
 <ul>
-    <li><code>text</code>: the text to search (required)</li>
+    <li><code>text</code>: the text to search (required). If multiple values
+        are parsed, that those values are connected by using OR.<br>
+        Parsing "Barack Obama" returns Entities that contain "Barack Obama" as
+        value for the field. Parsing ["Barack","Obama"] will return all Entities
+        that contain any of the two words. Most Sites however will boost results
+        that contain both values over such that only contain a single one. 
+    </li>
     <li><code>languages</code>: json array with the languages to search 
         (default is all languages) </li>
     <li><code>patternType</code>: one of "wildcard", "regex" or "none" 
@@ -154,8 +160,12 @@ TextConstraint for this</p>
 
 <h5>Example:</h5>
 
-<p>Searches for entities with an german rdfs:label starting with "Frankf"</p>
-
+<p>
+(1) Searches for entities with an german rdfs:label starting with "Frankf"<br>
+(2) Searches for entities that contain "Frankfurt" OR "Main" OR "Airport".
+Typically the "Frankfurt am Main Airport" should be ranked first because it
+contains all the optional terms.
+</p>
 <code><pre>
 { 
    "type": "text", 
@@ -164,6 +174,11 @@ TextConstraint for this</p>
    "text": "Frankf*", 
    "field": "http:\/\/www.w3.org\/2000\/01\/rdf-schema#label" 
 }, 
+{ 
+   "type": "text", 
+   "text": ["Frankfurt","Main","Airport"] 
+   "field": "http:\/\/www.w3.org\/2000\/01\/rdf-schema#label" 
+}, 
 </pre></code>
 
 <h4>Range Constraint: </h4>

Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_query.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_query.ftl?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_query.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_query.ftl Fri Jul 22 10:50:21 2011
@@ -144,7 +144,13 @@ TextConstraint for this</p>
 
 <p>Additional key:</p>
 <ul>
-    <li><code>text</code>: the text to search (required)</li>
+    <li><code>text</code>: the text to search (required). If multiple values
+        are parsed, that those values are connected by using OR.<br>
+        Parsing "Barack Obama" returns Entities that contain "Barack Obama" as
+        value for the field. Parsing ["Barack","Obama"] will return all Entities
+        that contain any of the two words. Most Sites however will boost results
+        that contain both values over such that only contain a single one. 
+    </li>
     <li><code>languages</code>: json array with the languages to search 
         (default is all languages) </li>
     <li><code>patternType</code>: one of "wildcard", "regex" or "none" 
@@ -154,7 +160,12 @@ TextConstraint for this</p>
 
 <h5>Example:</h5>
 
-<p>Searches for entities with an german rdfs:label starting with "Frankf"</p>
+<p>
+(1) Searches for entities with an german rdfs:label starting with "Frankf"<br>
+(2) Searches for entities that contain "Frankfurt" OR "Main" OR "Airport".
+Typically the "Frankfurt am Main Airport" should be ranked first because it
+contains all the optional terms.
+</p>
 
 <code><pre>
 { 
@@ -164,6 +175,11 @@ TextConstraint for this</p>
    "text": "Frankf*", 
    "field": "http:\/\/www.w3.org\/2000\/01\/rdf-schema#label" 
 }, 
+{ 
+   "type": "text", 
+   "text": ["Frankfurt","Main","Airport"] 
+   "field": "http:\/\/www.w3.org\/2000\/01\/rdf-schema#label" 
+}, 
 </pre></code>
 
 <h4>Range Constraint: </h4>

Modified: incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/SparqlQueryUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/SparqlQueryUtils.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/SparqlQueryUtils.java (original)
+++ incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/SparqlQueryUtils.java Fri Jul 22 10:50:21 2011
@@ -17,6 +17,7 @@
 package org.apache.stanbol.entityhub.query.clerezza;
 
 import java.text.DateFormat;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -584,59 +585,60 @@ public final class SparqlQueryUtils {
      */
     private static void addTextConstraint(StringBuilder queryString,String var,TextConstraint constraint,EndpointTypeEnum endpointType,String intend){
         boolean filterAdded = false;
-        boolean isTextValueConstraint = constraint.getText() != null && constraint.getText().length()>0;
+        boolean isTextValueConstraint = constraint.getTexts() != null && !constraint.getTexts().isEmpty();
         if(isTextValueConstraint){
             if(constraint.getPatternType() == PatternType.regex){
                 queryString.append(" \n").append(intend).append("  FILTER(");
                 filterAdded = true;
-                addRegexFilter(queryString,var,constraint.getText(),constraint.isCaseSensitive());
+                addRegexFilter(queryString,var,constraint.getTexts(),constraint.isCaseSensitive());
             } else {
                 //TODO: This optimised versions for Virtuoso and LARQ might not
                 //      respect case sensitive queries. Need more testing!
                 if (EndpointTypeEnum.Virtuoso == endpointType) {
                     queryString.append(". \n  ").append(intend);
-                    queryString.append(String.format("?%s bif:contains '",var));
-                    boolean firstWord = true;;
-                    //TODO: maybe we should use a better word tokenizer
-                    for(String word : constraint.getText().split(" ")){
-                        word = word.trim();
-                        if(!word.isEmpty()){
-                            if(firstWord){
-                                firstWord = false;
-                            } else {
-                                queryString.append(" AND ");
-                            }
-                            queryString.append('"').append(word).append('"');
-                        }
-                    }
-                    queryString.append('\'');
-//                    queryString.append(String.format("?%s bif:contains '\"%s\"'", var,constraint.getText()
-//                        .replace("'", " ") //escape search string to avoid breaking the SPARQL query!
-//                        //.replace(" ", " AND ") looks like AND operator is no longer supported by Virtuoso
-//                        ));
-                    //q.append("ORDER BY DESC ( <LONG::IRI_RANK> (?uri) ) ");
+                    queryString.append(String.format("?%s bif:contains '%s'",
+                        var,createFullTextQueryString(constraint.getTexts())));
                 } else if (EndpointTypeEnum.LARQ == endpointType) {
                     queryString.append(". \n  ").append(intend);
-                    queryString.append(String.format("?%s <http://jena.hpl.hp.com/ARQ/property#textMatch> '+%s'", var, constraint.getText().replace("'", " ")));
-                    //q.append("?incoming ?p ?uri . } ");
-                    //q.append("ORDER BY DESC (COUNT (?incoming) ) ");
+                    queryString.append(String.format("?%s <http://jena.hpl.hp.com/ARQ/property#textMatch> '%s'", 
+                        var, createFullTextQueryString(constraint.getTexts())));
                 } else {
                     queryString.append(" \n").append(intend).append("  FILTER(");
                     filterAdded = true;
                     if(constraint.getPatternType() == PatternType.none){
                         if(constraint.isCaseSensitive()){
-                            queryString.append(String.format("(str(?%s) = \"%s\")", var,constraint.getText()));
+                            boolean first = true;
+                            for(String textConstraint : constraint.getTexts()){
+                                if(first){
+                                    first = false;
+                                } else {
+                                    queryString.append(" || ");
+                                }
+                                if(textConstraint != null && !textConstraint.isEmpty()){
+                                    queryString.append(String.format("(str(?%s) = \"%s\")", var,textConstraint));
+                                }
+                            }
                         } else {
-                            String regexQueryText = PatternUtils.value2Regex(constraint.getText());
-                            addRegexFilter(queryString,var,regexQueryText,constraint.isCaseSensitive());
+                            Collection<String> regexQueryTexts = new ArrayList<String>(constraint.getTexts().size());
+                            for(String textConstraint : constraint.getTexts()){
+                                if(textConstraint != null && !textConstraint.isEmpty()){
+                                    regexQueryTexts.add(PatternUtils.value2Regex(textConstraint));
+                                }
+                            }
+                            addRegexFilter(queryString,var,regexQueryTexts,constraint.isCaseSensitive());
                         }
                     } else if(constraint.getPatternType() == PatternType.wildcard){
                         //parse false, because that is more in line with the expectations of users!
-                        String regexQueryText = PatternUtils.wildcardToRegex(constraint.getText(),false);
-                        addRegexFilter(queryString,var,regexQueryText,constraint.isCaseSensitive());
+                        Collection<String> regexQueryTexts = new ArrayList<String>(constraint.getTexts().size());
+                        for(String textConstraint : constraint.getTexts()){
+                            if(textConstraint != null && !textConstraint.isEmpty()){
+                                regexQueryTexts.add(PatternUtils.wildcardToRegex(textConstraint,false));
+                            }
+                        }
+                        addRegexFilter(queryString,var,regexQueryTexts,constraint.isCaseSensitive());
                     } else {
-                        log.warn("Unspported Patterntype "+constraint.getPatternType()+"! Change this impplementation to support this type! -> treat constaint \""+constraint.getText()+"\"as REGEX");
-                        addRegexFilter(queryString,var,constraint.getText(),constraint.isCaseSensitive());
+                        log.warn("Unspported Patterntype "+constraint.getPatternType()+"! Change this impplementation to support this type! -> treat constaint \""+constraint.getTexts()+"\"as REGEX");
+                        addRegexFilter(queryString,var,constraint.getTexts(),constraint.isCaseSensitive());
                     }
                 }
             }
@@ -658,14 +660,69 @@ public final class SparqlQueryUtils {
     }
 
     /**
+     * (Creates AND Text) OR (Query AND String) like queries based on the
+     * parsed TextConstraint as used by {@link EndpointTypeEnum#LARQ LARQ} and
+     * {@link EndpointTypeEnum#Virtuoso VIRTUOSO} SPARQL endpoints to speed up
+     * full text queries.
+     * @param constraints the as returned by {@link TextConstraint#getTexts()}
+     * @return the full text query string 
+     */
+    private static String createFullTextQueryString(Collection<String> constraints) {
+        StringBuilder textQuery = new StringBuilder();
+        boolean firstText = true;
+        for(String constraintText : constraints){
+            if(constraintText != null && !constraintText.isEmpty()){
+                if(firstText){
+                    firstText = false;
+                } else {
+                    textQuery.append(" OR ");
+                }
+                //TODO: maybe we should use a word tokenizer here
+                String[] words = constraintText.split("\\s");
+                if(words.length>1){
+                    //not perfect because words might contain empty string, but
+                    //it will eliminate most unnecessary brackets .
+                    textQuery.append('(');
+                }
+                boolean firstAndWord = true;
+                for(String word : words){
+                    word = word.trim();
+                    if(!word.isEmpty()){
+                        if(firstAndWord){
+                            firstAndWord = false;
+                        } else {
+                            textQuery.append(" AND ");
+                        }
+                        textQuery.append('"').append(word).append('"');
+                    }
+                }
+                if(words.length>1){
+                    textQuery.append(')');
+                }
+            } //end if not null and not empty
+        }
+        return textQuery.toString();
+    }
+
+    /**
      * Adds a SPARQL regex filter to the parsed query string
      * @param queryString the string builder to add the constraint
      * @param var the variable to constrain
-     * @param regexQueryText the regex encoded search string
+     * @param regexContraints the regex encoded search strings (connected with '||' (OR))
      * @param isCasesensitive if the constraint is case sensitive or not
      */
-    private static void addRegexFilter(StringBuilder queryString, String var, String regexQueryText,boolean isCasesensitive) {
-        queryString.append(String.format("regex(str(?%s),\"%s\"%s)", var,regexQueryText,isCasesensitive?"":",\"i\""));
+    private static void addRegexFilter(StringBuilder queryString, String var, Collection<String> regexContraints,boolean isCasesensitive) {
+        boolean first = true;
+        for(String regex : regexContraints){
+            if(regex != null && !regex.isEmpty()){
+                if(first){
+                    first = false;
+                } else {
+                    queryString.append(" || ");
+                }
+                queryString.append(String.format("regex(str(?%s),\"%s\"%s)", var,regex,isCasesensitive?"":",\"i\""));
+            }
+        }
     }
 
     /**
@@ -787,7 +844,7 @@ public final class SparqlQueryUtils {
     }
 
 
-/*    public static void main(String[] args) {
+    public static void main(String[] args) {
         SparqlFieldQuery query = SparqlFieldQueryFactory.getInstance().createFieldQuery();
 //        query.setConstraint("urn:field1", new ReferenceConstraint("urn:testReference"));
 //        query.setConstraint("urn:field1a", new ValueConstraint(null, Arrays.asList(
@@ -801,12 +858,13 @@ public final class SparqlQueryUtils {
 //        query.setConstraint("urn:field1d", new ValueConstraint(9, Arrays.asList(
 //                DataTypeEnum.Float.getUri(),DataTypeEnum.Double.getUri(),DataTypeEnum.Decimal.getUri())));
 //        query.setConstraint("urn:field2", new TextConstraint("test value"));
-        query.setConstraint("urn:field3", new TextConstraint("text value",true));
+        query.setConstraint("urn:field3", new TextConstraint(Arrays.asList(
+            "text value","anothertest","some more values"),true));
 //        query.setConstraint("urn:field2a", new TextConstraint(":-]")); //tests escaping of REGEX
-        query.setConstraint("urn:field3", new TextConstraint("language text","en"));
+//        query.setConstraint("urn:field3", new TextConstraint("language text","en"));
 //        query.setConstraint("urn:field4", new TextConstraint("multi language text","en","de",null));
-        query.setConstraint("urn:field5", new TextConstraint("wildcar*",PatternType.wildcard,false,"en","de"));
-        query.addSelectedField("urn:field5");
+//        query.setConstraint("urn:field5", new TextConstraint("wildcar*",PatternType.wildcard,false,"en","de"));
+//        query.addSelectedField("urn:field5");
 //        query.setConstraint("urn:field6", new TextConstraint("^regex",PatternType.REGEX,true));
 //        query.setConstraint("urn:field7", new TextConstraint("par*",PatternType.WildCard,false,"en","de",null));
 //        query.setConstraint("urn:field8", new TextConstraint(null,"en","de",null));
@@ -826,7 +884,7 @@ public final class SparqlQueryUtils {
         System.out.println(createSparqlSelectQuery(query,true,0,EndpointTypeEnum.Standard));
         System.out.println();
         System.out.println(createSparqlConstructQuery(query,0,EndpointTypeEnum.Virtuoso));
-    }*/
+    }
 
     /**
      * @param query

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java Fri Jul 22 10:50:21 2011
@@ -134,7 +134,8 @@ public class SolrFieldMapper implements 
 
     public SolrFieldMapper(SolrServer server) {
         if (server == null) {
-            throw new IllegalArgumentException("The parsed SolrServer MUST NOT be NULL");
+            log.warn("NULL parsed as SolrServer: Loading and Saving of the Namespace Prefix Settings will be deactivated!");
+            log.warn("  This is OK for Unit Test but should not happen in productive use!");
         }
         this.server = server;
     }
@@ -755,14 +756,16 @@ public class SolrFieldMapper implements 
         for (Entry<String,String> entry : prefixMap.entrySet()) {
             inputDoc.addField(getConfigFieldName(entry.getKey()), entry.getValue());
         }
-        try {
-            server.add(inputDoc);
-        } catch (IOException e) {
-            log.error("Unable save Configuration to SolrProvider", e);
-        } catch (SolrServerException e) {
-            log.error("Unable save Configuration to SolrProvider", e);
-        } catch (SolrException e) {
-            log.error("Unable save Configuration to SolrProvider", e);
+        if(server != null){
+            try {
+                server.add(inputDoc);
+            } catch (IOException e) {
+                log.error("Unable save Configuration to SolrProvider", e);
+            } catch (SolrServerException e) {
+                log.error("Unable save Configuration to SolrProvider", e);
+            } catch (SolrException e) {
+                log.error("Unable save Configuration to SolrProvider", e);
+            }
         }
     }
 
@@ -773,6 +776,9 @@ public class SolrFieldMapper implements 
      *            the document to store
      */
     protected SolrDocument getSolrDocument(String uri) throws SolrServerException, IOException {
+        if(server == null){
+            return null;
+        }
         SolrQuery solrQuery = new SolrQuery();
         solrQuery.addField("*"); // select all fields
         solrQuery.setRows(1); // we query for the id, there is only one result

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrQueryFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrQueryFactory.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrQueryFactory.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrQueryFactory.java Fri Jul 22 10:50:21 2011
@@ -22,30 +22,29 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumMap;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Set;
+import java.util.Map.Entry;
 
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.common.SolrDocument;
 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.servicesapi.defaults.DataTypeEnum;
+import org.apache.stanbol.entityhub.core.model.InMemoryValueFactory;
+import org.apache.stanbol.entityhub.core.query.DefaultQueryFactory;
 import org.apache.stanbol.entityhub.servicesapi.model.Representation;
-import org.apache.stanbol.entityhub.servicesapi.model.Text;
 import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
 import org.apache.stanbol.entityhub.servicesapi.query.Constraint;
-import org.apache.stanbol.entityhub.servicesapi.query.Constraint.ConstraintType;
 import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
 import org.apache.stanbol.entityhub.servicesapi.query.Query;
 import org.apache.stanbol.entityhub.servicesapi.query.RangeConstraint;
 import org.apache.stanbol.entityhub.servicesapi.query.SimilarityConstraint;
 import org.apache.stanbol.entityhub.servicesapi.query.TextConstraint;
 import org.apache.stanbol.entityhub.servicesapi.query.ValueConstraint;
+import org.apache.stanbol.entityhub.servicesapi.query.Constraint.ConstraintType;
 import org.apache.stanbol.entityhub.servicesapi.util.ModelUtils;
 import org.apache.stanbol.entityhub.yard.solr.defaults.IndexDataTypeEnum;
 import org.apache.stanbol.entityhub.yard.solr.impl.queryencoders.AssignmentEncoder;
@@ -67,7 +66,6 @@ import org.apache.stanbol.entityhub.yard
 import org.apache.stanbol.entityhub.yard.solr.query.EncodedConstraintParts;
 import org.apache.stanbol.entityhub.yard.solr.query.IndexConstraintTypeEncoder;
 import org.apache.stanbol.entityhub.yard.solr.query.IndexConstraintTypeEnum;
-import org.apache.stanbol.entityhub.yard.solr.query.QueryUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -136,8 +134,8 @@ public class SolrQueryFactory {
                 fieldMapper));
         constraintEncoders.put(IndexConstraintTypeEnum.FIELD, new FieldEncoder(fieldMapper));
         constraintEncoders.put(IndexConstraintTypeEnum.EQ, new AssignmentEncoder(indexValueFactory));
-        constraintEncoders.put(IndexConstraintTypeEnum.WILDCARD, new WildcardEncoder());
-        constraintEncoders.put(IndexConstraintTypeEnum.REGEX, new RegexEncoder());
+        constraintEncoders.put(IndexConstraintTypeEnum.WILDCARD, new WildcardEncoder(indexValueFactory));
+        constraintEncoders.put(IndexConstraintTypeEnum.REGEX, new RegexEncoder(indexValueFactory));
         constraintEncoders.put(IndexConstraintTypeEnum.GE, new GeEncoder(indexValueFactory));
         constraintEncoders.put(IndexConstraintTypeEnum.LE, new LeEncoder(indexValueFactory));
         constraintEncoders.put(IndexConstraintTypeEnum.GT, new GtEncoder(indexValueFactory));
@@ -311,19 +309,22 @@ public class SolrQueryFactory {
      * @param textConstraint
      */
     private void initIndexConstraint(IndexConstraint indexConstraint, TextConstraint textConstraint) {
-        Text text = valueFactory.createText(textConstraint.getText());
-        IndexValue textValue = indexValueFactory.createIndexValue(text);
-        indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.DATATYPE, text);
+        List<IndexValue> textValues = new ArrayList<IndexValue>(textConstraint.getTexts().size());
+        for(String text : textConstraint.getTexts()){
+            textValues.add(indexValueFactory.createIndexValue(
+                valueFactory.createText(text)));
+        }
+        indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.DATATYPE, IndexDataTypeEnum.TXT.getIndexType());
         indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.LANG, textConstraint.getLanguages());
         switch (textConstraint.getPatternType()) {
             case none:
-                indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.EQ, textValue);
+                indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.EQ, textValues);
                 break;
             case wildcard:
-                indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.WILDCARD, textValue);
+                indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.WILDCARD, textValues);
                 break;
             case regex:
-                indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.REGEX, textValue);
+                indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.REGEX, textValues);
                 break;
             default:
                 indexConstraint.setInvalid(String.format(
@@ -629,28 +630,41 @@ public class SolrQueryFactory {
                                                    EncodedConstraintParts encodedConstraintParts) {
             // list of all constraints that need to be connected with OR
             List<List<StringBuilder>> constraints = new ArrayList<List<StringBuilder>>();
+            log.info("Constriants: "+encodedConstraintParts);
             // init with a single constraint
             constraints.add(new ArrayList<StringBuilder>(Arrays.asList(new StringBuilder())));
             for (Entry<ConstraintTypePosition,Set<Set<String>>> entry : encodedConstraintParts) {
                 // one position may contain multiple options that need to be connected with OR
+//                log.info("process: pos {} ({})",entry.getKey().getPos(),entry.getKey());
                 Set<Set<String>> orParts = entry.getValue();
-                int i = 0;
                 int constraintsSize = constraints.size();
+                int i = 0;
                 for (Set<String> andParts : orParts) {
+//                    log.info("  OR {}",andParts);
                     i++;
                     // add the and constraints to all or
                     if (i == orParts.size()) {
                         // for the last iteration, append the part to the existing constraints
                         for (int j = 0; j < constraintsSize; j++) {
+//                            String parsedConstraint = constraints.get(j).toString();
                             encodeAndParts(andParts, constraints.get(j));
+//                            log.info("    appand AND {} to [{}]:{} -> {}",
+//                                new Object[]{andParts,j,parsedConstraint, constraints.get(j).toString()});
                         }
                     } else {
                         // if there is more than one value, we need to generate new variants for
                         // every option other than the last.
                         for (int j = 0; j < constraintsSize; j++) {
-                            List<StringBuilder> additional = new ArrayList<StringBuilder>(constraints.get(j));
-                            encodeAndParts(andParts, additional);
+                            //we need a deep "clone" of the Constraints of index 'j'
+                            List<StringBuilder> additional = new ArrayList<StringBuilder>(constraints.get(j).size());
+                            for(StringBuilder sb : constraints.get(j)){
+                                additional.add(new StringBuilder(sb));
+                            }
                             constraints.add(additional);
+//                            String parsedConstraint = constraints.get(j).toString();
+                            encodeAndParts(andParts, additional);
+//                            log.info("    create AND {} to [{}]:{} -> {}",
+//                                new Object[]{andParts,j,parsedConstraint, constraints.get(j).toString()});
                         }
                     }
                 }
@@ -663,7 +677,7 @@ public class SolrQueryFactory {
                         queryString.append('(');
                         firstOr = false;
                     } else {
-                        queryString.append(" OR (");
+                        queryString.append(") OR (");
                     }
                     boolean firstAnd = true;
                     for (StringBuilder andConstraint : constraint) {
@@ -728,4 +742,20 @@ public class SolrQueryFactory {
         // this.fieldConstraints.remove(constraintType);
         // }
     }
+    public static void main(String[] args) {
+        SolrQueryFactory factory = new SolrQueryFactory(
+            InMemoryValueFactory.getInstance(), 
+            IndexValueFactory.getInstance(), 
+            new SolrFieldMapper(null));
+        FieldQuery query = DefaultQueryFactory.getInstance().createFieldQuery();
+//        query.setConstraint("urn:field2", new TextConstraint("test","en","de"));
+        query.setConstraint("urn:field3", new TextConstraint(Arrays.asList(
+            "text value","anothertest","some more values"),"en","de",null));
+        query.addSelectedField("urn:field2a");
+        query.addSelectedField("urn:field3");
+        query.setLimit(5);
+        query.setOffset(5);
+        SolrQuery solrQuery = factory.parseFieldQuery(query, SELECT.QUERY);
+        System.out.println(solrQuery.getQuery());
+    }
 }

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java Fri Jul 22 10:50:21 2011
@@ -52,8 +52,8 @@ import org.apache.solr.client.solrj.resp
 import org.apache.solr.common.SolrDocument;
 import org.apache.solr.common.SolrInputDocument;
 import org.apache.stanbol.commons.solr.SolrDirectoryManager;
-import org.apache.stanbol.commons.solr.SolrServerProvider;
 import org.apache.stanbol.commons.solr.SolrServerProviderManager;
+import org.apache.stanbol.commons.solr.SolrServerTypeEnum;
 import org.apache.stanbol.commons.solr.utils.ConfigUtils;
 import org.apache.stanbol.commons.solr.utils.SolrUtil;
 import org.apache.stanbol.commons.solr.utils.StreamQueryRequest;
@@ -173,7 +173,7 @@ public class SolrYard extends AbstractYa
      * Key used to configure the implementation of the {@link SolrServer} to be used by this SolrYard
      * implementation. The default value is determined by the type of the value configured by the
      * {@link #SOLR_SERVER_LOCATION}. In case a path of a File URI is used, the type is set to
-     * {@link Type#EMBEDDED} otherwise {@link Type#HTTP} is used as default.
+     * {@link SolrServerTypeEnum#EMBEDDED} otherwise {@link SolrServerTypeEnum#HTTP} is used as default.
      */
     public static final String SOLR_SERVER_TYPE = "org.apache.stanbol.entityhub.yard.solr.solrServerType";
     /**
@@ -280,9 +280,9 @@ public class SolrYard extends AbstractYa
 
     /**
      * Manager used to create the {@link SolrServer} instance used by this yard. Supports also
-     * {@link Type#STREAMING} and {@link Type#LOAD_BALANCE} type of servers. TODO: In case a remove SolrServer
+     * {@link SolrServerTypeEnum#STREAMING} and {@link SolrServerTypeEnum#LOAD_BALANCE} type of servers. TODO: In case a remove SolrServer
      * is configured by the {@link SolrYardConfig#getSolrServerLocation()}, than it would be possible to
-     * create both an {@link StreamingUpdateSolrServer} (by parsing {@link Type#STREAMING}) and an normal
+     * create both an {@link StreamingUpdateSolrServer} (by parsing {@link SolrServerTypeEnum#STREAMING}) and an normal
      * {@link CommonsHttpSolrServer}. The streaming update one should be used for indexing requests and the
      * commons http one for all other requests. This would provide performance advantages when updating
      * {@link Representation}s stored in a SolrYard using an remote SolrServer.
@@ -468,7 +468,7 @@ public class SolrYard extends AbstractYa
     private void initSolrServer() throws YardException {
         SolrYardConfig config = (SolrYardConfig) this.getConfig();
         String solrIndexLocation;
-        if (config.getSolrServerType() == SolrServerProvider.Type.EMBEDDED) {
+        if (config.getSolrServerType() == SolrServerTypeEnum.EMBEDDED) {
             File indexDirectory = ConfigUtils.toFile(config.getSolrServerLocation());
             if (!indexDirectory.isAbsolute()) { // relative paths
                 SolrDirectoryManager solrDirectoryManager = this.solrDirectoryManager;

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYardConfig.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYardConfig.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYardConfig.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYardConfig.java Fri Jul 22 10:50:21 2011
@@ -20,10 +20,9 @@ import java.util.Dictionary;
 import java.util.Map;
 
 import org.apache.solr.client.solrj.SolrServer;
-import org.apache.stanbol.commons.solr.SolrServerProvider;
+import org.apache.stanbol.commons.solr.SolrServerTypeEnum;
 import org.apache.stanbol.entityhub.core.yard.AbstractYard.YardConfig;
 import org.apache.stanbol.commons.solr.SolrDirectoryManager;
-import org.apache.stanbol.commons.solr.SolrServerProvider.Type;
 import org.osgi.service.cm.ConfigurationException;
 
 /**
@@ -82,7 +81,7 @@ public final class SolrYardConfig extend
      * @param type
      *            The type to use
      */
-    public void setSolrServerType(SolrServerProvider.Type type) {
+    public void setSolrServerType(SolrServerTypeEnum type) {
         if (type == null) {
             config.remove(SolrYard.SOLR_SERVER_TYPE);
         } else {
@@ -90,14 +89,14 @@ public final class SolrYardConfig extend
         }
     }
 
-    public SolrServerProvider.Type getSolrServerType() {
+    public SolrServerTypeEnum getSolrServerType() {
         Object serverType = config.get(SolrYard.SOLR_SERVER_TYPE);
         if (serverType != null) {
-            if (serverType instanceof SolrServerProvider.Type) {
-                return (SolrServerProvider.Type) serverType;
+            if (serverType instanceof SolrServerTypeEnum) {
+                return (SolrServerTypeEnum) serverType;
             } else {
                 try {
-                    return SolrServerProvider.Type.valueOf(serverType.toString());
+                    return SolrServerTypeEnum.valueOf(serverType.toString());
                 } catch (IllegalArgumentException e) {
                     // invalid value set!
                     config.remove(SolrYard.SOLR_SERVER_TYPE);
@@ -108,9 +107,9 @@ public final class SolrYardConfig extend
         String serverLocation = getSolrServerLocation();
         // TODO: maybe we need to improve this detection code.
         if (serverLocation.startsWith("http")) {
-            return SolrServerProvider.Type.HTTP;
+            return SolrServerTypeEnum.HTTP;
         } else {
-            return SolrServerProvider.Type.EMBEDDED;
+            return SolrServerTypeEnum.EMBEDDED;
         }
     }
 

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/AssignmentEncoder.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/AssignmentEncoder.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/AssignmentEncoder.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/AssignmentEncoder.java Fri Jul 22 10:50:21 2011
@@ -18,6 +18,10 @@ package org.apache.stanbol.entityhub.yar
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 import org.apache.stanbol.entityhub.yard.solr.model.IndexValue;
 import org.apache.stanbol.entityhub.yard.solr.model.IndexValueFactory;
@@ -49,28 +53,25 @@ public class AssignmentEncoder implement
 
     @Override
     public void encode(EncodedConstraintParts constraint, Object value) {
-        IndexValue indexValue;
-        if (value == null) {
-            indexValue = null;
-        } else if (value instanceof IndexValue) {
-            indexValue = (IndexValue) value;
-        } else {
-            indexValue = indexValueFactory.createIndexValue(value);
-        }
+        Set<IndexValue> indexValues = QueryUtils.parseIndexValues(indexValueFactory,value);
         // encode the value based on the type
-        String[] queryConstraints = QueryUtils.encodeQueryValue(indexValue, true);
-        String[] eqConstraints;
-        if (queryConstraints != null) {
-            eqConstraints = new String[queryConstraints.length];
-            for (int i = 0; i < eqConstraints.length; i++) {
-                eqConstraints[i] = EQ + queryConstraints[i];
+        for(IndexValue indexValue : indexValues){
+            String[] queryConstraints = QueryUtils.encodeQueryValue(indexValue, true);
+            String[] eqConstraints;
+            if (queryConstraints != null) {
+                eqConstraints = new String[queryConstraints.length];
+                for (int i = 0; i < eqConstraints.length; i++) {
+                    eqConstraints[i] = EQ + queryConstraints[i];
+                }
+            } else {
+                eqConstraints = new String[] {EQ};
             }
-        } else {
-            eqConstraints = new String[] {EQ};
+            constraint.addEncoded(POS, eqConstraints);
         }
-        constraint.addEncoded(POS, eqConstraints);
     }
 
+
+
     @Override
     public boolean supportsDefault() {
         return true;

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/RegexEncoder.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/RegexEncoder.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/RegexEncoder.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/RegexEncoder.java Fri Jul 22 10:50:21 2011
@@ -25,11 +25,13 @@ import java.util.Set;
 import org.apache.stanbol.entityhub.yard.solr.defaults.IndexDataTypeEnum;
 import org.apache.stanbol.entityhub.yard.solr.model.IndexDataType;
 import org.apache.stanbol.entityhub.yard.solr.model.IndexValue;
+import org.apache.stanbol.entityhub.yard.solr.model.IndexValueFactory;
 import org.apache.stanbol.entityhub.yard.solr.query.ConstraintTypePosition;
 import org.apache.stanbol.entityhub.yard.solr.query.ConstraintTypePosition.PositionType;
 import org.apache.stanbol.entityhub.yard.solr.query.EncodedConstraintParts;
 import org.apache.stanbol.entityhub.yard.solr.query.IndexConstraintTypeEncoder;
 import org.apache.stanbol.entityhub.yard.solr.query.IndexConstraintTypeEnum;
+import org.apache.stanbol.entityhub.yard.solr.query.QueryUtils;
 
 /**
  * TODO: This encoder is not functional! It would need to convert the REGEX Pattern to the according WildCard
@@ -39,7 +41,7 @@ import org.apache.stanbol.entityhub.yard
  * @author Rupert Westenthaler
  * 
  */
-public class RegexEncoder implements IndexConstraintTypeEncoder<IndexValue> {
+public class RegexEncoder implements IndexConstraintTypeEncoder<Object> {
 
     private static final ConstraintTypePosition POS = new ConstraintTypePosition(PositionType.value);
 
@@ -50,18 +52,33 @@ public class RegexEncoder implements Ind
         types.add(IndexDataTypeEnum.STR.getIndexType());
         SUPPORTED_TYPES = Collections.unmodifiableSet(types);
     }
+    private final IndexValueFactory indexValueFactory;
+
+    public RegexEncoder(IndexValueFactory indexValueFactory) {
+        if (indexValueFactory == null) {
+            throw new IllegalArgumentException("The indexValueFactory MUST NOT be NULL");
+        }
+        this.indexValueFactory = indexValueFactory;
+    }
 
     @Override
-    public void encode(EncodedConstraintParts constraint, IndexValue value) {
-        if (value == null) {
+    public void encode(EncodedConstraintParts constraint, Object value) {
+        Set<IndexValue> indexValues = QueryUtils.parseIndexValues(indexValueFactory,value);
+        if(indexValues.size() == 1 && indexValues.iterator().next() == null){
             throw new IllegalArgumentException("This encoder does not support the NULL IndexValue!");
-        } else if (!SUPPORTED_TYPES.contains(value.getType())) {
-            throw new IllegalArgumentException(String.format(
-                "This encoder does not support the IndexDataType %s (supported: %s)", value.getType(),
-                SUPPORTED_TYPES));
-        } else {
-            // TODO: Implement some REGEX to WILDCard conversion for Solr
-            constraint.addEncoded(POS, value.getValue().toLowerCase());
+        }
+        // encode the value based on the type
+        for(IndexValue indexValue : indexValues){
+            if (value != null) {
+                if (!SUPPORTED_TYPES.contains(indexValue.getType())) {
+                    throw new IllegalArgumentException(String.format(
+                        "This encoder does not support the IndexDataType %s (supported: %s)", indexValue.getType(),
+                        SUPPORTED_TYPES));
+                } else {
+                    // TODO: Implement some REGEX to WILDCard conversion for Solr
+                    constraint.addEncoded(POS, indexValue.getValue().toLowerCase());
+                }
+            } //else ignore null element
         }
     }
 
@@ -81,8 +98,8 @@ public class RegexEncoder implements Ind
     }
 
     @Override
-    public Class<IndexValue> acceptsValueType() {
-        return IndexValue.class;
+    public Class<Object> acceptsValueType() {
+        return Object.class;
     }
 
 }

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/WildcardEncoder.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/WildcardEncoder.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/WildcardEncoder.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/WildcardEncoder.java Fri Jul 22 10:50:21 2011
@@ -25,6 +25,7 @@ import java.util.Set;
 import org.apache.stanbol.entityhub.yard.solr.defaults.IndexDataTypeEnum;
 import org.apache.stanbol.entityhub.yard.solr.model.IndexDataType;
 import org.apache.stanbol.entityhub.yard.solr.model.IndexValue;
+import org.apache.stanbol.entityhub.yard.solr.model.IndexValueFactory;
 import org.apache.stanbol.entityhub.yard.solr.query.ConstraintTypePosition;
 import org.apache.stanbol.entityhub.yard.solr.query.ConstraintTypePosition.PositionType;
 import org.apache.stanbol.entityhub.yard.solr.query.EncodedConstraintParts;
@@ -32,7 +33,7 @@ import org.apache.stanbol.entityhub.yard
 import org.apache.stanbol.entityhub.yard.solr.query.IndexConstraintTypeEnum;
 import org.apache.stanbol.entityhub.yard.solr.query.QueryUtils;
 
-public class WildcardEncoder implements IndexConstraintTypeEncoder<IndexValue> {
+public class WildcardEncoder implements IndexConstraintTypeEncoder<Object> {
 
     private static final ConstraintTypePosition POS = new ConstraintTypePosition(PositionType.value);
 
@@ -43,17 +44,32 @@ public class WildcardEncoder implements 
         types.add(IndexDataTypeEnum.STR.getIndexType());
         SUPPORTED_TYPES = Collections.unmodifiableSet(types);
     }
+    private final IndexValueFactory indexValueFactory;
+
+    public WildcardEncoder(IndexValueFactory indexValueFactory) {
+        if (indexValueFactory == null) {
+            throw new IllegalArgumentException("The indexValueFactory MUST NOT be NULL");
+        }
+        this.indexValueFactory = indexValueFactory;
+    }
 
     @Override
-    public void encode(EncodedConstraintParts constraint, IndexValue value) {
-        if (value == null) {
+    public void encode(EncodedConstraintParts constraint, Object value) {
+        Set<IndexValue> indexValues = QueryUtils.parseIndexValues(indexValueFactory,value);
+        if(indexValues.size() == 1 && indexValues.iterator().next() == null){
             throw new IllegalArgumentException("This encoder does not support the NULL IndexValue!");
-        } else if (!SUPPORTED_TYPES.contains(value.getType())) {
-            throw new IllegalArgumentException(String.format(
-                "This encoder does not support the IndexDataType %s (supported: %s)", value.getType(),
-                SUPPORTED_TYPES));
-        } else {
-            constraint.addEncoded(POS, QueryUtils.encodeQueryValue(value, false));
+        }
+        // encode the value based on the type
+        for(IndexValue indexValue : indexValues){
+            if (indexValue != null) {
+                if (!SUPPORTED_TYPES.contains(indexValue.getType())) {
+                    throw new IllegalArgumentException(String.format(
+                        "This encoder does not support the IndexDataType %s (supported: %s)", indexValue.getType(),
+                        SUPPORTED_TYPES));
+                } else {
+                    constraint.addEncoded(POS, QueryUtils.encodeQueryValue(indexValue, false));
+                }
+            } // else ignore null value
         }
     }
 
@@ -73,8 +89,8 @@ public class WildcardEncoder implements 
     }
 
     @Override
-    public Class<IndexValue> acceptsValueType() {
-        return IndexValue.class;
+    public Class<Object> acceptsValueType() {
+        return Object.class;
     }
 
 }

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/ConstraintTypePosition.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/ConstraintTypePosition.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/ConstraintTypePosition.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/ConstraintTypePosition.java Fri Jul 22 10:50:21 2011
@@ -79,9 +79,12 @@ public class ConstraintTypePosition impl
         return obj instanceof ConstraintTypePosition && ((ConstraintTypePosition) obj).type == type
                && ((ConstraintTypePosition) obj).pos == pos;
     }
+    public String getPos(){
+        return type.ordinal()+"."+pos;
+    }
 
     @Override
     public String toString() {
-        return String.format("constraintPosition %s,%d", type, pos);
+        return type.name()+'.'+ pos;
     }
 }

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/QueryUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/QueryUtils.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/QueryUtils.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/QueryUtils.java Fri Jul 22 10:50:21 2011
@@ -19,13 +19,16 @@ package org.apache.stanbol.entityhub.yar
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.regex.Pattern;
 
 import org.apache.stanbol.commons.solr.utils.SolrUtil;
 import org.apache.stanbol.entityhub.yard.solr.defaults.IndexDataTypeEnum;
 import org.apache.stanbol.entityhub.yard.solr.model.IndexValue;
+import org.apache.stanbol.entityhub.yard.solr.model.IndexValueFactory;
 
 public final class QueryUtils {
     private QueryUtils() {}
@@ -67,4 +70,38 @@ public final class QueryUtils {
         }
         return queryConstraints;
     }
+    
+    /**
+     * Utility Method that extracts IndexValues form an parsed {@link Object}.
+     * This checks for {@link IndexValue}, {@link Iterable}s and values
+     * @param indexValueFactory The indexValueFactory used to create indexValues if necessary
+     * @param value the value to parse
+     * @return A set with the parsed values. The returned Set is guaranteed 
+     * not to be <code>null</code> and contains at least a single element. 
+     * If no IndexValue could be parsed from the parsed value than a set containing
+     * the <code>null</code> value is returned.
+     */
+    public static Set<IndexValue> parseIndexValues(IndexValueFactory indexValueFactory,Object value) {
+        Set<IndexValue> indexValues;
+        if (value == null) {
+            indexValues = Collections.singleton(null);
+        } else if (value instanceof IndexValue) {
+            indexValues = Collections.singleton((IndexValue) value);
+        } else if (value instanceof Iterable<?>){
+            indexValues = new HashSet<IndexValue>();
+            for(Object o : (Iterable<?>) value){
+                if(o instanceof IndexValue){
+                    indexValues.add((IndexValue)o);
+                } else if (o != null){
+                    indexValues.add(indexValueFactory.createIndexValue(o));
+                }
+            }
+            if(indexValues.isEmpty()){
+                indexValues.add(null); //add null element instead of an empty set
+            }
+        } else {
+            indexValues = Collections.singleton(indexValueFactory.createIndexValue(value));
+        }
+        return indexValues;
+    }
 }

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java?rev=1149562&r1=1149561&r2=1149562&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java Fri Jul 22 10:50:21 2011
@@ -123,13 +123,13 @@ public class SolrYardTest extends YardTe
         assertNotNull(updatedIterable);
 
         FieldQuery query = yard.getQueryFactory().createFieldQuery();
-        query.setConstraint(field, new TextConstraint("text content"));
+        query.setConstraint(field, new TextConstraint(Arrays.asList("text content")));
         QueryResultList<Representation> results = yard.find(query);
         assertEquals(2, results.size());
 
         // fetch the light / minimal representation
         query = yard.getQueryFactory().createFieldQuery();
-        query.setConstraint(field, new TextConstraint("value2"));
+        query.setConstraint(field, new TextConstraint(Arrays.asList("value2")));
         results = yard.find(query);
         assertEquals(1, results.size());
         Representation result = results.iterator().next();
@@ -189,7 +189,7 @@ public class SolrYardTest extends YardTe
         // combine similarity with traditional filtering
         query = yard.getQueryFactory().createFieldQuery();
         query.setConstraint(similarityfield, new SimilarityConstraint("aaaa aaaa aaaa aaaa zzzz yyyy"));
-        query.setConstraint(filterfield, new TextConstraint("other"));
+        query.setConstraint(filterfield, new TextConstraint(Arrays.asList("other")));
         results = yard.find(query);
         assertEquals(1, results.size());
         it = results.iterator();