Author: tommaso
Date: Tue Mar 4 10:34:48 2014
New Revision: 1574018
URL: http://svn.apache.org/r1574018
Log:
OAK-1490 - fixed support for multiple primary types restriction
Modified:
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexProvider.java
Modified:
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java?rev=1574018&r1=1574017&r2=1574018&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
(original)
+++
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
Tue Mar 4 10:34:48 2014
@@ -68,25 +68,18 @@ public class SolrQueryIndex implements F
@Override
public double getCost(Filter filter, NodeState root) {
- // TODO : estimate no of returned values and 0 is not good for no
restrictions
- return (filter.getPropertyRestrictions() != null ?
filter.getPropertyRestrictions().size() * 0.1 : 0)
- + (filter.getFulltextConditions() != null ?
filter.getFulltextConditions().size() * 0.01 : 0)
- + (filter.getPathRestriction() != null ? 0.2 : 0);
-//
-// FullTextExpression ft = filter.getFullTextConstraint();
-// if (ft == null) {
-// // TODO solr should only be triggered for full-text conditions
-// // return Double.POSITIVE_INFINITY;
-// }
-// int cost = 10;
-// Collection<PropertyRestriction> restrictions =
filter.getPropertyRestrictions();
-// if (restrictions != null) {
-// cost /= 2;
-// }
-// if (filter.getPathRestriction() != null) {
-// cost /= 2;
-// }
-// return cost;
+ if (filter.getFullTextConstraint() == null &&
filter.getFulltextConditions() == null) {
+ return Double.POSITIVE_INFINITY;
+ }
+ int cost = 10;
+ Collection<Filter.PropertyRestriction> restrictions =
filter.getPropertyRestrictions();
+ if (restrictions != null) {
+ cost /= 5;
+ }
+ if (filter.getPathRestriction() != null) {
+ cost /= 2;
+ }
+ return cost;
}
@Override
@@ -168,11 +161,21 @@ public class SolrQueryIndex implements F
}
}
- for (String pt : filter.getPrimaryTypes()) {
-
queryBuilder.append("jcr\\:primaryType").append(':').append(partialEscape(pt));
+ String[] pts = filter.getPrimaryTypes().toArray(new
String[filter.getPrimaryTypes().size()]);
+ for (int i = 0; i < pts.length; i++) {
+ String pt = pts[i];
+ if (i == 0) {
+ queryBuilder.append("(");
+ }
+
queryBuilder.append("jcr\\:primaryType").append(':').append(partialEscape(pt)).append("
");
+ if (i > 0 && i < pts.length - 1) {
+ queryBuilder.append("OR ");
+ }
+ if (i == pts.length - 1) {
+ queryBuilder.append(")");
+ }
}
-
Filter.PathRestriction pathRestriction = filter.getPathRestriction();
if (pathRestriction != null) {
String path = purgePath(filter);
@@ -245,6 +248,9 @@ public class SolrQueryIndex implements F
@Override
public Cursor query(Filter filter, NodeState root) {
+ if (log.isDebugEnabled()) {
+ log.debug("converting filter {}", filter);
+ }
Cursor cursor;
try {
SolrQuery query = getQuery(filter);
Modified:
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexProvider.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexProvider.java?rev=1574018&r1=1574017&r2=1574018&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexProvider.java
(original)
+++
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexProvider.java
Tue Mar 4 10:34:48 2014
@@ -66,18 +66,18 @@ public class SolrQueryIndexProvider impl
if (log.isDebugEnabled()) {
log.debug("found a Solr index definition {}",
entry.getName());
}
- }
- try {
- tempIndexes.add(new SolrQueryIndex(
- entry.getName(),
- solrServerProvider.getSolrServer(),
- oakSolrConfigurationProvider.getConfiguration()));
- } catch (Exception e) {
- if (log.isErrorEnabled()) {
- log.error("unable to create Solr query index at " +
entry.getName(), e);
+
+ try {
+ tempIndexes.add(new SolrQueryIndex(
+ entry.getName(),
+ solrServerProvider.getSolrServer(),
+ oakSolrConfigurationProvider.getConfiguration()));
+ } catch (Exception e) {
+ if (log.isErrorEnabled()) {
+ log.error("unable to create Solr query index at " +
entry.getName(), e);
+ }
}
}
-
}
return tempIndexes;
}