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/04/06 15:14:27 UTC
svn commit: r1089443 [2/2] - in /incubator/stanbol/trunk: commons/
commons/installer/ commons/installer/bundleprovider/
commons/installer/bundleprovider/src/
commons/installer/bundleprovider/src/main/
commons/installer/bundleprovider/src/main/java/ com...
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=1089443&r1=1089442&r2=1089443&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 Wed Apr 6 13:14:26 2011
@@ -18,34 +18,43 @@ 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.Hashtable;
+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.query.ConstraintTypePosition;
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.ConstraintTypePosition.PositionType;
+import org.apache.stanbol.entityhub.yard.solr.utils.SolrUtil;
-public class WildcardEncoder implements IndexConstraintTypeEncoder<String>{
+public class WildcardEncoder implements IndexConstraintTypeEncoder<IndexValue>{
private static final ConstraintTypePosition POS = new ConstraintTypePosition(PositionType.value);
+
+ private static final Set<IndexDataType> SUPPORTED_TYPES;
+ static {
+ Set<IndexDataType> types = new HashSet<IndexDataType>();
+ types.add(IndexDataTypeEnum.TXT.getIndexType());
+ types.add(IndexDataTypeEnum.STR.getIndexType());
+ SUPPORTED_TYPES = Collections.unmodifiableSet(types);
+ }
@Override
- public void encode(EncodedConstraintParts constraint, String value) {
+ public void encode(EncodedConstraintParts constraint, IndexValue value) {
if(value == 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: Use toLoverCase here, because I had problems with Solr that
- // Queries where not converted to lower case even that the
- // LowerCaseFilterFactory was present in the query analyser :(
- value = value.toLowerCase();
- /* NOTE:
- * When searching for multiple words we assume that we need to find
- * the exact pattern e.g. "best pract*" because of that we replace
- * spaces with '+'
- */
- value = value.replace(' ', '+');
- constraint.addEncoded(POS, value);
+ constraint.addEncoded(POS, SolrUtil.encodeQueryValue(value));
}
}
@@ -65,8 +74,8 @@ public class WildcardEncoder implements
}
@Override
- public Class<String> acceptsValueType() {
- return String.class;
+ public Class<IndexValue> acceptsValueType() {
+ return IndexValue.class;
}
}
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/EncodedConstraintParts.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/EncodedConstraintParts.java?rev=1089443&r1=1089442&r2=1089443&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/EncodedConstraintParts.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/EncodedConstraintParts.java Wed Apr 6 13:14:26 2011
@@ -49,11 +49,11 @@ import java.util.Map.Entry;
* @author Rupert Westenthaler
*
*/
-public class EncodedConstraintParts implements Iterable<Entry<ConstraintTypePosition,Set<String>>>{
+public class EncodedConstraintParts implements Iterable<Entry<ConstraintTypePosition,Set<Set<String>>>>{
/**
* This maps contains all the encoded parts of the query.
*/
- private SortedMap<ConstraintTypePosition,Set<String>> constraintMap = new TreeMap<ConstraintTypePosition, Set<String>>();
+ private SortedMap<ConstraintTypePosition,Set<Set<String>>> constraintMap = new TreeMap<ConstraintTypePosition, Set<Set<String>>>();
/**
* Adds an constraint type
* @param pos
@@ -63,12 +63,12 @@ public class EncodedConstraintParts impl
if(values == null || values.length<1){
return;
} else {
- Set<String> constraints = constraintMap.get(pos);
+ Set<Set<String>> constraints = constraintMap.get(pos);
if(constraints == null){
- constraints = new HashSet<String>();
+ constraints = new HashSet<Set<String>>();
constraintMap.put(pos, constraints);
}
- constraints.addAll(Arrays.asList(values));
+ constraints.add(new HashSet<String>(Arrays.asList(values)));
}
}
@@ -78,7 +78,7 @@ public class EncodedConstraintParts impl
}
@Override
- public Iterator<Entry<ConstraintTypePosition, Set<String>>> iterator() {
+ public Iterator<Entry<ConstraintTypePosition, Set<Set<String>>>> iterator() {
return constraintMap.entrySet().iterator();
}
@Override
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/utils/SolrUtil.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/utils/SolrUtil.java?rev=1089443&r1=1089442&r2=1089443&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/utils/SolrUtil.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/utils/SolrUtil.java Wed Apr 6 13:14:26 2011
@@ -18,6 +18,9 @@ package org.apache.stanbol.entityhub.yar
import java.util.regex.Pattern;
+import org.apache.stanbol.entityhub.yard.solr.defaults.IndexDataTypeEnum;
+import org.apache.stanbol.entityhub.yard.solr.model.IndexValue;
+
public final class SolrUtil {
private SolrUtil(){}
@@ -36,5 +39,35 @@ public final class SolrUtil {
public static String escapeSolrSpecialChars(String string) {
return string != null?LUCENE_PATTERN.matcher(string).replaceAll(REPLACEMENT_STRING):null;
}
+ /**
+ * This method encodes a parsed index value as needed for queries.<p>
+ * In case of TXT it is assumed that a whitespace tokenizer is used
+ * by the index. Therefore values with multiple words need to be
+ * treated and connected with AND to find only values that contain all.
+ * In case of STR no whitespace is assumed. Therefore spaces need to
+ * be replaced with '+' to search for tokens with the exact name.
+ * In all other cases the string need not to be converted.
+ *
+ * Note also that text queries are converted to lower case
+ * @param value the index value
+ * @return the (possible multiple) values that need to be connected with AND
+ */
+ public static String[] encodeQueryValue(IndexValue indexValue){
+ if(indexValue == null){
+ return null;
+ }
+ String[] queryConstraints;
+ String escapedValue = SolrUtil.escapeSolrSpecialChars(indexValue.getValue());
+ if(IndexDataTypeEnum.TXT.getIndexType().equals(indexValue.getType())){
+ escapedValue = escapedValue.toLowerCase();
+ queryConstraints = escapedValue.split(" ");
+ } else if(IndexDataTypeEnum.STR.equals(indexValue.getType())){
+ escapedValue = escapedValue.toLowerCase();
+ queryConstraints = new String[]{escapedValue.replace(' ', '+')};
+ } else {
+ queryConstraints = new String[]{escapedValue};
+ }
+ return queryConstraints;
+ }
}
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java?rev=1089443&r1=1089442&r2=1089443&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java Wed Apr 6 13:14:26 2011
@@ -71,12 +71,12 @@ public class SolrDirectoryManagerTest {
@Test(expected=IllegalArgumentException.class)
public void testNullIndexName(){
- solrDirectoryManager.getSolrDirectory(null);
+ solrDirectoryManager.getSolrDirectory(null,true);
}
@Test(expected=IllegalArgumentException.class)
public void testEmptyIndexName(){
- solrDirectoryManager.getSolrDirectory("");
+ solrDirectoryManager.getSolrDirectory("",true);
}
@Test
@@ -101,11 +101,11 @@ public class SolrDirectoryManagerTest {
}
@Test
- public void testIndexInitialisation(){
+ public void testDefaultIndexInitialisation(){
//this is actually tested already by the initialisation of the
//SolrYardTest ...
String indexName = "testIndexInitialisation_"+System.currentTimeMillis();
- File indexDir = solrDirectoryManager.getSolrDirectory(indexName);
+ File indexDir = solrDirectoryManager.getSolrDirectory(indexName,true);
assertEquals(new File(expectedManagedDirectory,indexName), indexDir);
assertTrue(indexDir.isDirectory());
}
Modified: incubator/stanbol/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/parent/pom.xml?rev=1089443&r1=1089442&r2=1089443&view=diff
==============================================================================
--- incubator/stanbol/trunk/parent/pom.xml (original)
+++ incubator/stanbol/trunk/parent/pom.xml Wed Apr 6 13:14:26 2011
@@ -864,6 +864,21 @@
<classifier>app</classifier>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.launchpad.installer</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.launchpad.api</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.installer.core</artifactId>
+ <version>3.1.2</version>
+ </dependency>
<!-- Testing Deps -->
<dependency>