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 2015/04/10 15:13:36 UTC
svn commit: r1672642 - in /jackrabbit/oak/trunk/oak-solr-core/src/main:
java/org/apache/jackrabbit/oak/plugins/index/solr/index/
java/org/apache/jackrabbit/oak/plugins/index/solr/query/
java/org/apache/jackrabbit/oak/plugins/index/solr/util/ resources/...
Author: tommaso
Date: Fri Apr 10 13:13:36 2015
New Revision: 1672642
URL: http://svn.apache.org/r1672642
Log:
OAK-2750 - indexing only the first 1024 chars for sorting
Added:
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/util/SolrUtils.java (with props)
Modified:
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java
jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml
Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java?rev=1672642&r1=1672641&r2=1672642&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java Fri Apr 10 13:13:36 2015
@@ -45,6 +45,9 @@ import org.slf4j.LoggerFactory;
import static org.apache.jackrabbit.JcrConstants.JCR_DATA;
import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
+import static org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot;
+import static org.apache.jackrabbit.oak.plugins.index.solr.util.SolrUtils.getSortingField;
+import static org.apache.jackrabbit.oak.plugins.index.solr.util.SolrUtils.partialEscape;
/**
* Index editor for keeping a Solr index up to date.
@@ -204,21 +207,6 @@ class SolrIndexEditor implements IndexEd
return null; // no need to recurse down the removed subtree
}
- private static CharSequence partialEscape(CharSequence s) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
- if (c == '\\' || c == '!' || c == '(' || c == ')' ||
- c == ':' || c == '^' || c == '[' || c == ']' || c == '/' ||
- c == '{' || c == '}' || c == '~' || c == '*' || c == '?' ||
- c == '-' || c == ' ') {
- sb.append('\\');
- }
- sb.append(c);
- }
- return sb;
- }
-
private SolrInputDocument docFromState(NodeState state) {
SolrInputDocument inputDocument = new SolrInputDocument();
String path = getPath();
@@ -228,63 +216,53 @@ class SolrIndexEditor implements IndexEd
|| !configuration.getIgnoredProperties().contains(property.getName())) {
// try to get the field to use for this property from configuration
String fieldName = configuration.getFieldNameFor(property.getType());
+ Object fieldValue;
if (fieldName != null) {
- Object value = property.getValue(property.getType());
- inputDocument.addField(fieldName, value);
- // add sort field
- inputDocument.addField(getSortingField(property.getType().tag(), property.getName()), value);
+ fieldValue = property.getValue(property.getType());
} else {
+ fieldName = property.getName();
if (Type.BINARY.tag() == property.getType().tag()) {
- List<String> value = extractTextValues(property, state);
- inputDocument.addField(property.getName(), value);
- StringBuilder builder = new StringBuilder();
- for (String v : value) {
- if (builder.length() > 0) {
- builder.append(',');
- }
- builder.append(v);
- }
- // add sort field
- inputDocument.addField(getSortingField(property.getType().tag(), property.getName()), builder.toString());
- } else if (property.isArray()) { // or fallback to adding propertyName:stringValue(s)
- Iterable<String> strings = property.getValue(Type.STRINGS);
- StringBuilder builder = new StringBuilder();
- for (String s : strings) {
- inputDocument.addField(property.getName(), s);
- if (builder.length() > 0) {
- builder.append(',');
- }
- builder.append(s);
+ fieldValue = extractTextValues(property, state);
+ } else if (property.isArray()) {
+ fieldValue = property.getValue(Type.STRINGS);
+ } else {
+ fieldValue = property.getValue(Type.STRING);
+ }
+ }
+ // add property field
+ inputDocument.addField(fieldName, fieldValue);
+
+ Object sortValue;
+ if (fieldValue instanceof Iterable) {
+ Iterable values = (Iterable) fieldValue;
+ StringBuilder builder = new StringBuilder();
+ String stringValue = null;
+ for (Object value : values) {
+ builder.append(value);
+ if (builder.length() > 1024) {
+ stringValue = builder.substring(0, 1024);
+ break;
}
- // add sort field
- inputDocument.addField(getSortingField(property.getType().tag(), property.getName()), builder.toString());
+ }
+ if (stringValue == null) {
+ stringValue = builder.toString();
+ }
+ sortValue = stringValue;
+ } else {
+ if (fieldValue.toString().length() > 1024) {
+ sortValue = fieldValue.toString().substring(0, 1024);
} else {
- String value = property.getValue(Type.STRING);
- inputDocument.addField(property.getName(), value);
- // add sort field
- inputDocument.addField(getSortingField(property.getType().tag(), property.getName()), value);
+ sortValue = fieldValue;
}
}
+
+ // add sort field
+ inputDocument.addField(getSortingField(property.getType().tag(), property.getName()), sortValue);
}
}
return inputDocument;
}
- private String getSortingField(int tag, String s) {
-// switch (tag) {
-// case PropertyType.LONG:
-// return s+"_long_sort";
-// case PropertyType.DATE:
-// return s+"_date_sort";
-// case PropertyType.DOUBLE:
-// return s+"_double_sort";
-// case PropertyType.STRING:
-// return s+"_string_sort";
-// default:
- return s+"_string_sort";
-// }
- }
-
private List<String> extractTextValues(
PropertyState property, NodeState state) {
List<String> values = new LinkedList<String>();
Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java?rev=1672642&r1=1672641&r2=1672642&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java Fri Apr 10 13:13:36 2015
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
import java.util.Collection;
import java.util.List;
+import javax.jcr.PropertyType;
import org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration;
import org.apache.jackrabbit.oak.query.fulltext.FullTextAnd;
@@ -33,6 +34,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
+import static org.apache.jackrabbit.oak.plugins.index.solr.util.SolrUtils.getSortingField;
+import static org.apache.jackrabbit.oak.plugins.index.solr.util.SolrUtils.partialEscape;
/**
* the {@link org.apache.jackrabbit.oak.plugins.index.solr.query.FilterQueryParser} can parse {@link org.apache.jackrabbit.oak.spi.query.Filter}s
@@ -238,36 +241,6 @@ class FilterQueryParser {
return solrQuery;
}
- private static String getSortingField(int tag, String s) {
-// switch (tag) {
-// case PropertyType.LONG:
-// return s+"_long_sort";
-// case PropertyType.DATE:
-// return s+"_date_sort";
-// case PropertyType.DOUBLE:
-// return s+"_double_sort";
-// case PropertyType.STRING:
-// return s+"_string_sort";
-// default:
- return s+"_string_sort";
-// }
- }
-
- private static CharSequence partialEscape(CharSequence s) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
- if (c == '\\' || c == '!' || c == '(' || c == ')' ||
- c == ':' || c == '^' || c == '[' || c == ']' || c == '/' ||
- c == '{' || c == '}' || c == '~' || c == '*' || c == '?' ||
- c == '-' || c == ' ') {
- sb.append('\\');
- }
- sb.append(c);
- }
- return sb;
- }
-
private static String parseFullTextExpression(FullTextExpression ft, final OakSolrConfiguration configuration) {
final StringBuilder fullTextString = new StringBuilder();
ft.accept(new FullTextVisitor() {
Added: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/util/SolrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/util/SolrUtils.java?rev=1672642&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/util/SolrUtils.java (added)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/util/SolrUtils.java Fri Apr 10 13:13:36 2015
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.index.solr.util;
+
+import javax.jcr.PropertyType;
+
+/**
+ * Solr utility class
+ */
+public class SolrUtils {
+
+ /**
+ * Escape a char sequence in order to make it usable within a Solr query
+ *
+ * @param s the String to escape
+ * @return an escaped String
+ */
+ public static CharSequence partialEscape(CharSequence s) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ if (c == '\\' || c == '!' || c == '(' || c == ')' ||
+ c == ':' || c == '^' || c == '[' || c == ']' || c == '/' ||
+ c == '{' || c == '}' || c == '~' || c == '*' || c == '?' ||
+ c == '-' || c == ' ') {
+ sb.append('\\');
+ }
+ sb.append(c);
+ }
+ return sb;
+ }
+
+ /**
+ * Get the name of the field to be used for sorting a certain property
+ *
+ * @param tag the {@code Type#tag} of the given property
+ * @param propertyName the name of the given property
+ * @return the name of the Solr field to be used for sorting on the given property
+ */
+ public static String getSortingField(int tag, String propertyName) {
+ switch (tag) {
+ case PropertyType.BINARY:
+ return propertyName + "_binary_sort";
+ case PropertyType.DOUBLE:
+ return propertyName + "_double_sort";
+ case PropertyType.DECIMAL:
+ return propertyName + "_double_sort";
+ default:
+ return propertyName + "_string_sort";
+ }
+ }
+
+}
Propchange: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/util/SolrUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml?rev=1672642&r1=1672641&r2=1672642&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml Fri Apr 10 13:13:36 2015
@@ -121,10 +121,9 @@
<field name="_version_" type="long" indexed="true" stored="true"/>
<!-- sorting dynamic fields -->
- <!--<dynamicField name="*_long_sort" type="tlong" indexed="false" stored="false" multiValued="false" docValues="true"/>-->
- <!--<dynamicField name="*_double_sort" type="tdouble" indexed="false" stored="false" multiValued="false" docValues="true"/>-->
- <!--<dynamicField name="*_date_sort" type="tdate" indexed="false" stored="false" multiValued="false" docValues="true"/>-->
+ <dynamicField name="*_double_sort" type="tdouble" indexed="false" stored="false" multiValued="false" docValues="true"/>
<dynamicField name="*_string_sort" type="string" indexed="false" stored="false" multiValued="false" docValues="true"/>
+ <dynamicField name="*_binary_sort" type="string" indexed="true" stored="false" multiValued="false" omitNorms="true"/>
<dynamicField name="*" type="text_general" indexed="true" stored="true" multiValued="true"/>
</fields>