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 2012/04/25 06:28:28 UTC
svn commit: r1330096 - in /incubator/stanbol/trunk/entityhub/yard/solr/src:
main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrQueryFactory.java
test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java
Author: rwesten
Date: Wed Apr 25 04:28:27 2012
New Revision: 1330096
URL: http://svn.apache.org/viewvc?rev=1330096&view=rev
Log:
STANBOL-589: SimilarityConstraint now respect the parsed Fields (before they statically used the _text field in the SolrIndex). This was a left over TODO from STANBOL-202. Also needed to adapt the UnitTest to use a field that is configured to support MLT queries in the SolrIndex (termVectors enabled)
Modified:
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/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java
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=1330096&r1=1330095&r2=1330096&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 Wed Apr 25 04:28:27 2012
@@ -62,6 +62,7 @@ import org.apache.stanbol.entityhub.yard
import org.apache.stanbol.entityhub.yard.solr.impl.queryencoders.WildcardEncoder;
import org.apache.stanbol.entityhub.yard.solr.model.FieldMapper;
import org.apache.stanbol.entityhub.yard.solr.model.IndexDataType;
+import org.apache.stanbol.entityhub.yard.solr.model.IndexField;
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.model.NoConverterException;
@@ -168,7 +169,8 @@ public class SolrQueryFactory {
if (fieldConstraint.getValue().getType() == ConstraintType.similarity) {
// TODO: log make the FieldQuery ensure that there is no more than one instead of similarity
// constraint per query
- List<String> fields = Arrays.asList(fieldConstraint.getKey());
+ List<String> fields = new ArrayList<String>();
+ fields.add(fieldConstraint.getKey());
SimilarityConstraint simConstraint = (SimilarityConstraint) fieldConstraint.getValue();
IndexValue indexValue = indexValueFactory.createIndexValue(simConstraint.getContext());
fields.addAll(simConstraint.getAdditionalFields());
@@ -177,12 +179,21 @@ public class SolrQueryFactory {
query.set(MoreLikeThisParams.MIN_DOC_FREQ, 1);
query.set(MoreLikeThisParams.MIN_TERM_FREQ, 1);
query.set(MoreLikeThisParams.INTERESTING_TERMS, "details");
-
- // TODO: right now we ignore the fields and fallback to the hardcoded "_text" field
+ List<String> indexFields = new ArrayList<String>();
+ for(String field : fields){
+ indexFields.addAll(fieldMapper.getFieldNames(
+ new IndexField(Collections.singletonList(field),
+ IndexDataTypeEnum.TXT.getIndexType())));
+ }
+ /* rwesten: 2012-04-24: no parsed fields are parsed
+ // Obsolete: right now we ignore the fields and fallback to the hardcoded "_text" field
//Collection<String> mappedFields = fieldMapper.getFieldNames(fields, indexValue);
//query.set(MoreLikeThisParams.SIMILARITY_FIELDS, StringUtils.join(mappedFields, ","));
query.set(MoreLikeThisParams.SIMILARITY_FIELDS, "_text");
+ */
+ query.set(MoreLikeThisParams.SIMILARITY_FIELDS, indexFields.toArray(new String[fields.size()]));
query.set(CommonParams.STREAM_BODY, indexValue.getValue());
+ processedFieldConstraints.put(fieldConstraint.getKey(), fieldConstraint.getValue());
} else {
IndexConstraint indexConstraint = createIndexConstraint(fieldConstraint);
if (indexConstraint.isInvalid()) {
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=1330096&r1=1330095&r2=1330096&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 Wed Apr 25 04:28:27 2012
@@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.Iterator;
import org.apache.stanbol.commons.solr.managed.ManagedSolrServer;
+import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
import org.apache.stanbol.entityhub.servicesapi.model.Representation;
import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
import org.apache.stanbol.entityhub.servicesapi.query.QueryResultList;
@@ -152,7 +153,7 @@ public class SolrYardTest extends YardTe
String id1 = "urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id1";
String id2 = "urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id2";
String id3 = "urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id3";
- String similarityfield = "urn:the.field:used.for.testFieldQueryWithSimilarityConstraint.similarity";
+ String similarityfield = NamespaceEnum.rdfs+"comment";
String filterfield = "urn:the.field:used.for.testFieldQueryWithSimilarityConstraint.filter";
Representation test1 = create(id1, true);
Representation test2 = create(id2, true);