You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by to...@apache.org on 2014/11/24 10:59:27 UTC
svn commit: r1641344 - in
/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr:
configuration/OakSolrNodeStateConfiguration.java query/SolrQueryIndex.java
Author: tommaso
Date: Mon Nov 24 09:59:27 2014
New Revision: 1641344
URL: http://svn.apache.org/r1641344
Log:
OAK-2286 - adjusted also node state config to address type/property mappings correctly
Modified:
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrNodeStateConfiguration.java
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrNodeStateConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrNodeStateConfiguration.java?rev=1641344&r1=1641343&r2=1641344&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrNodeStateConfiguration.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrNodeStateConfiguration.java Mon Nov 24 09:59:27 2014
@@ -16,9 +16,9 @@
*/
package org.apache.jackrabbit.oak.plugins.index.solr.configuration;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.LinkedList;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
@@ -47,9 +47,17 @@ public abstract class OakSolrNodeStateCo
@Override
public String getFieldNameFor(Type<?> propertyType) {
- if (Type.BINARIES.equals(propertyType) || Type.BINARY.equals(propertyType)) {
- // TODO : use Tika / SolrCell here
- return propertyType.toString() + "_bin";
+ Iterable<String> typeMappings = getStringValuesFor(Properties.TYPE_MAPPINGS);
+ if (typeMappings != null) {
+ for (String typeMapping : typeMappings) {
+ String[] mapping = typeMapping.split("=");
+ if (mapping.length == 2 && mapping[0] != null && mapping[1] != null) {
+ Type<?> type = Type.fromString(mapping[0]);
+ if (type != null && type.tag() == propertyType.tag()) {
+ return mapping[1];
+ }
+ }
+ }
}
return null;
}
@@ -95,6 +103,17 @@ public abstract class OakSolrNodeStateCo
@Override
public String getFieldForPropertyRestriction(Filter.PropertyRestriction propertyRestriction) {
+ Iterable<String> propertyMappings = getStringValuesFor(Properties.PROPERTY_MAPPINGS);
+ if (propertyMappings != null) {
+ for (String propertyMapping : propertyMappings) {
+ String[] mapping = propertyMapping.split("=");
+ if (mapping.length == 2 && mapping[0] != null && mapping[1] != null) {
+ if (propertyRestriction.propertyName.equals(mapping[0])) {
+ return mapping[1];
+ }
+ }
+ }
+ }
return null;
}
@@ -126,9 +145,12 @@ public abstract class OakSolrNodeStateCo
@Override
public Collection<String> getIgnoredProperties() {
Collection<String> ignoredProperties;
- String ignoredPropertiesString = getStringValueFor(Properties.IGNORED_PROPERTIES, SolrServerConfigurationDefaults.IGNORED_PROPERTIES);
- if (ignoredPropertiesString != null) {
- ignoredProperties = Arrays.asList(ignoredPropertiesString.split(","));
+ Iterable<String> ignoredPropertiesValues = getStringValuesFor(Properties.IGNORED_PROPERTIES);
+ if (ignoredPropertiesValues != null) {
+ ignoredProperties = new LinkedList<String>();
+ for (String ignoredProperty : ignoredPropertiesValues) {
+ ignoredProperties.add(ignoredProperty);
+ }
} else {
ignoredProperties = Collections.emptyList();
}
@@ -171,6 +193,18 @@ public abstract class OakSolrNodeStateCo
return value;
}
+ private Iterable<String> getStringValuesFor(String propertyName) {
+ Iterable<String> values = null;
+ NodeState configurationNodeState = getConfigurationNodeState();
+ if (configurationNodeState.exists()) {
+ PropertyState property = configurationNodeState.getProperty(propertyName);
+ if (property != null && property.isArray()) {
+ values = property.getValue(Type.STRINGS);
+ }
+ }
+ return values;
+ }
+
@Override
public SolrServerConfiguration<EmbeddedSolrServerProvider> getSolrServerConfiguration() {
String solrHomePath = getStringValueFor(Properties.SOLRHOME_PATH, SolrServerConfigurationDefaults.SOLR_HOME_PATH);
@@ -204,5 +238,7 @@ public abstract class OakSolrNodeStateCo
public static final String PRIMARY_TYPES = "primaryTypes";
public static final String PATH_RESTRICTIONS = "pathRestrictions";
public static final String IGNORED_PROPERTIES = "ignoredProperties";
+ public static final String TYPE_MAPPINGS = "typeMappings";
+ public static final String PROPERTY_MAPPINGS = "propertyMappings";
}
}
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=1641344&r1=1641343&r2=1641344&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 Mon Nov 24 09:59:27 2014
@@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.Deque;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import javax.annotation.CheckForNull;
@@ -48,6 +49,8 @@ import org.apache.jackrabbit.oak.spi.que
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.response.FacetField;
+import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.slf4j.Logger;
@@ -159,6 +162,20 @@ public class SolrQueryIndex implements F
}
}
+ // facet enable
+ String facetFunctionStartToken = "facet(";
+ String queryStatement = filter.getQueryStatement();
+ if (queryStatement != null) {
+ int facetTokenIndex = queryStatement.indexOf(facetFunctionStartToken);
+ if (facetTokenIndex > -1) {
+ String facetFieldsString = queryStatement.substring(facetTokenIndex +
+ facetFunctionStartToken.length(), queryStatement.indexOf(")", facetTokenIndex));
+ for (String facetField : facetFieldsString.split(",")) {
+ solrQuery.addFacetField(facetField);
+ }
+ }
+ }
+
Collection<Filter.PropertyRestriction> propertyRestrictions = filter.getPropertyRestrictions();
if (propertyRestrictions != null && !propertyRestrictions.isEmpty()) {
for (Filter.PropertyRestriction pr : propertyRestrictions) {
@@ -293,7 +310,7 @@ public class SolrQueryIndex implements F
if (log.isDebugEnabled()) {
log.debug("JCR query {} has been converted to Solr query {}",
- filter.getQueryStatement(), solrQuery.toString());
+ queryStatement, solrQuery.toString());
}
return solrQuery;
@@ -448,22 +465,30 @@ public class SolrQueryIndex implements F
public Cursor query(final Filter filter, NodeState root) {
Cursor cursor;
try {
- final Set<String> relPaths = filter.getFullTextConstraint() != null ? getRelativePaths(filter.getFullTextConstraint()) : Collections.<String>emptySet();
+ final Set<String> relPaths = filter.getFullTextConstraint() != null ? getRelativePaths(filter.getFullTextConstraint()) :
+ Collections.<String>emptySet();
final String parent = relPaths.size() == 0 ? "" : relPaths.iterator().next();
final int parentDepth = getDepth(parent);
-
cursor = new SolrRowCursor(new AbstractIterator<SolrResultRow>() {
+
private final Set<String> seenPaths = Sets.newHashSet();
private final Deque<SolrResultRow> queue = Queues.newArrayDeque();
+
private SolrDocument lastDoc;
+ private int lastFacet = 0;
+
public int offset = 0;
+ public List<FacetField> facetFields;
@Override
protected SolrResultRow computeNext() {
- while (!queue.isEmpty() || loadDocs()) {
+ if (!queue.isEmpty() || loadDocs()) {
return queue.remove();
+ } else if (facetFields != null && lastFacet < facetFields.size()) {
+ lastFacet++;
+ return new SolrResultRow(facetFields.get(lastFacet - 1));
}
return endOfData();
}
@@ -513,7 +538,11 @@ public class SolrQueryIndex implements F
if (log.isDebugEnabled()) {
log.debug("sending query {}", query);
}
- SolrDocumentList docs = solrServer.query(query).getResults();
+
+ QueryResponse queryResponse = solrServer.query(query);
+
+ facetFields = queryResponse.getFacetFields();
+ SolrDocumentList docs = queryResponse.getResults();
if (log.isDebugEnabled()) {
log.debug("getting docs {}", docs);
@@ -546,9 +575,10 @@ public class SolrQueryIndex implements F
}
static class SolrResultRow {
- final String path;
- final double score;
+ String path;
+ double score;
SolrDocument doc;
+ FacetField facetField;
SolrResultRow(String path, double score) {
this.path = path;
@@ -561,6 +591,11 @@ public class SolrQueryIndex implements F
this.doc = doc;
}
+ SolrResultRow(FacetField facetField) {
+ this.facetField = facetField;
+ this.path = "/" + facetField.toString();
+ }
+
@Override
public String toString() {
return String.format("%s (%1.2f)", path, score);
@@ -578,6 +613,7 @@ public class SolrQueryIndex implements F
SolrResultRow currentRow;
SolrRowCursor(final Iterator<SolrResultRow> it, QueryEngineSettings settings) {
+
Iterator<String> pathIterator = new Iterator<String>() {
@Override
@@ -598,8 +634,8 @@ public class SolrQueryIndex implements F
};
pathCursor = new Cursors.PathCursor(pathIterator, true, settings);
- }
+ }
@Override
public boolean hasNext() {