From 7ce866e3ce34aea025a71b8e78876a8c5b799e8a Mon Sep 17 00:00:00 2001 From: Danesh Date: Thu, 9 Apr 2015 20:40:00 +0530 Subject: [PATCH] Revert "Enabled multivalued support for property fields" --- .../registry/indexing/SolrConstants.java | 4 -- .../indexer/IndexDocumentCreator.java | 2 +- .../registry/indexing/solr/SolrClient.java | 59 +++++++++---------- 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/SolrConstants.java b/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/SolrConstants.java index 3207f55b7..f6d2f0a2f 100644 --- a/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/SolrConstants.java +++ b/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/SolrConstants.java @@ -72,10 +72,6 @@ private SolrConstants(){} public static final String SOLR_DOUBLE_FIELD_KEY_SUFFIX = "_d"; // Constant for solr multivalued string field key suffix public static final String SOLR_MULTIVALUED_STRING_FIELD_KEY_SUFFIX = "_ss"; - //Constant for solr multivalued int field key suffix - public static final String SOLR_MULTIVALUED_INT_FIELD_KEY_SUFFIX = "_is"; - //Constant for solr multivalued double field key suffix - public static final String SOLR_MULTIVALUED_DOUBLE_FIELD_KEY_SUFFIX = "_ds"; // Constant for String type public static final String TYPE_STRING = "string"; // Constant for Integer type diff --git a/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/indexer/IndexDocumentCreator.java b/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/indexer/IndexDocumentCreator.java index 17c446d43..660e4f11a 100644 --- a/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/indexer/IndexDocumentCreator.java +++ b/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/indexer/IndexDocumentCreator.java @@ -143,7 +143,7 @@ private void addPropertyData() { if (values != null) { for (Object value : values) { - propertyValue += value + ","; + propertyValue = value + ","; } } else { propertyValue = ","; diff --git a/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/solr/SolrClient.java b/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/solr/SolrClient.java index dbfa34d13..91d1d0c73 100755 --- a/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/solr/SolrClient.java +++ b/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/solr/SolrClient.java @@ -53,7 +53,6 @@ import java.io.OutputStream; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -269,7 +268,10 @@ public void addDocument(IndexDocument indexDoc) throws SolrException { addDynamicFields(fields, solrInputDocument); // Add solr input document to server server.add(solrInputDocument); - } catch (SolrServerException | IOException e) { + } catch (SolrServerException e) { + String message = "Error at indexing."; + throw new SolrException(ErrorCode.SERVER_ERROR, message, e); + } catch (IOException e) { String message = "Error at indexing."; throw new SolrException(ErrorCode.SERVER_ERROR, message, e); } @@ -295,8 +297,8 @@ private void addDynamicFields(Map> fields, SolrInputDocumen for (String value : fieldList.getValue()) { String[] propertyValArray = value.split(","); fieldKey = propertyValArray[0]; - String [] propValues = Arrays.copyOfRange(propertyValArray, 1, propertyValArray.length); - addPropertyField(fieldKey, propValues, solrInputDocument); + value = propertyValArray[1]; + addPropertyField(fieldKey, value, solrInputDocument); } } else { fieldKey = fieldList.getKey() + SolrConstants.SOLR_MULTIVALUED_STRING_FIELD_KEY_SUFFIX; @@ -335,28 +337,22 @@ private void addDynamicFields(Map> fields, SolrInputDocumen /** * Method to add property values * @param fieldKey property field key value - * @param values property field values + * @param value property field value * @param solrInputDocument Solr InputDocument */ - private void addPropertyField(String fieldKey, String[] values, SolrInputDocument solrInputDocument) { + private void addPropertyField(String fieldKey, String value, SolrInputDocument solrInputDocument) { int intValue; double doubleValue; // Check whether the value is an Int or decimal or string - String valueType = getType(values[0]); - for (String propValue : values) { - switch (valueType) { - case SolrConstants.TYPE_INT: - intValue = Integer.parseInt(propValue); - solrInputDocument.addField(fieldKey + SolrConstants.SOLR_MULTIVALUED_INT_FIELD_KEY_SUFFIX, intValue); - break; - case SolrConstants.TYPE_DOUBLE: - doubleValue = Double.parseDouble(propValue); - solrInputDocument.addField(fieldKey + SolrConstants.SOLR_MULTIVALUED_DOUBLE_FIELD_KEY_SUFFIX, doubleValue); - break; - case SolrConstants.TYPE_STRING: - solrInputDocument.addField(fieldKey + SolrConstants.SOLR_MULTIVALUED_STRING_FIELD_KEY_SUFFIX, propValue); - break; - } + String valueType = getType(value); + if (valueType.equals(SolrConstants.TYPE_INT)) { + intValue = Integer.parseInt(value); + solrInputDocument.addField(fieldKey + SolrConstants.SOLR_INT_FIELD_KEY_SUFFIX, intValue); + } else if (valueType.equals(SolrConstants.TYPE_DOUBLE)) { + doubleValue = Double.parseDouble(value); + solrInputDocument.addField(fieldKey + SolrConstants.SOLR_DOUBLE_FIELD_KEY_SUFFIX, doubleValue); + } else if (valueType.equals(SolrConstants.TYPE_STRING)) { + solrInputDocument.addField(fieldKey + SolrConstants.SOLR_STRING_FIELD_KEY_SUFFIX, value); } } @@ -458,7 +454,10 @@ public synchronized void deleteFromIndex(String path, int tenantId) throws SolrE if (log.isDebugEnabled()) { log.debug("Solr delete index path: " + path + " id: " + id); } - } catch (SolrServerException | IOException e) { + } catch (SolrServerException e) { + // Throw unchecked exception: SolrException, this will throw when there is an error in connection. + throw new SolrException(ErrorCode.SERVER_ERROR, "Failure at deleting", e); + } catch (IOException e) { // Throw unchecked exception: SolrException, this will throw when there is an error in connection. throw new SolrException(ErrorCode.SERVER_ERROR, "Failure at deleting", e); } @@ -730,9 +729,9 @@ private void setQueryFilterProperty(SolrQuery query, String propertyName, String double rightDoubleValue = 0; // No operation values only check the property name if (StringUtils.isEmpty(leftPropertyValue) && StringUtils.isEmpty(rightPropertyValue)) { - String fieldKeyInt = propertyName + SolrConstants.SOLR_MULTIVALUED_INT_FIELD_KEY_SUFFIX + ":"; - String fieldKeyDouble = propertyName + SolrConstants.SOLR_MULTIVALUED_DOUBLE_FIELD_KEY_SUFFIX + ":"; - String fieldKeyString = propertyName + SolrConstants.SOLR_MULTIVALUED_STRING_FIELD_KEY_SUFFIX + ":"; + String fieldKeyInt = propertyName + SolrConstants.SOLR_INT_FIELD_KEY_SUFFIX + ":"; + String fieldKeyDouble = propertyName + SolrConstants.SOLR_DOUBLE_FIELD_KEY_SUFFIX + ":"; + String fieldKeyString = propertyName + SolrConstants.SOLR_STRING_FIELD_KEY_SUFFIX + ":"; query.addFilterQuery(fieldKeyInt + "* | " + fieldKeyDouble + "* | " + fieldKeyString + "*"); } // check foe equal operation @@ -785,7 +784,7 @@ private void setQueryFilterForDoublePropertyValues(SolrQuery query, String prope if (StringUtils.isNotEmpty(leftPropertyValue)) { leftDoubleValue = Double.parseDouble(leftPropertyValue); } - String fieldKey = propertyName + SolrConstants.SOLR_MULTIVALUED_DOUBLE_FIELD_KEY_SUFFIX + ":"; + String fieldKey = propertyName + SolrConstants.SOLR_DOUBLE_FIELD_KEY_SUFFIX + ":"; if (leftOp.equals(SolrConstants.OPERATION_GREATER_THAN) || leftOp .equals(SolrConstants.OPERATION_GREATER_THAN_OR_EQUAL) || leftOp.equals(SolrConstants.OPERATION_NA)) { @@ -827,7 +826,7 @@ private void setQueryFilterForIntegerPropertyValues(SolrQuery query, String prop if (StringUtils.isNotEmpty(leftPropertyValue)) { leftIntValue = Integer.parseInt(leftPropertyValue); } - String fieldKey = propertyName + SolrConstants.SOLR_MULTIVALUED_INT_FIELD_KEY_SUFFIX + ":"; + String fieldKey = propertyName + SolrConstants.SOLR_INT_FIELD_KEY_SUFFIX + ":"; if (leftOp.equals(SolrConstants.OPERATION_GREATER_THAN) || leftOp .equals(SolrConstants.OPERATION_GREATER_THAN_OR_EQUAL) || leftOp.equals(SolrConstants.OPERATION_NA)) { @@ -864,17 +863,17 @@ private void setQueryFilterPropertyEqualOperation(SolrQuery query, String proper if (valueType.equals(SolrConstants.TYPE_INT)) { // Get the integer value int intValue = Integer.parseInt(rightPropertyValue); - fieldKey = propertyName + SolrConstants.SOLR_MULTIVALUED_INT_FIELD_KEY_SUFFIX + ":"; + fieldKey = propertyName + SolrConstants.SOLR_INT_FIELD_KEY_SUFFIX + ":"; query.addFilterQuery(fieldKey + intValue); } else if (valueType.equals(SolrConstants.TYPE_DOUBLE)) { // Get the float value double doubleValue = Double.parseDouble(rightPropertyValue); - fieldKey = propertyName + SolrConstants.SOLR_MULTIVALUED_DOUBLE_FIELD_KEY_SUFFIX + ":"; + fieldKey = propertyName + SolrConstants.SOLR_DOUBLE_FIELD_KEY_SUFFIX + ":"; query.addFilterQuery(fieldKey + doubleValue); } else if (valueType.equals(SolrConstants.TYPE_STRING)) { // Get the string value rightPropertyValue = getWildcardSearchQueryValue(rightPropertyValue); - fieldKey = propertyName + SolrConstants.SOLR_MULTIVALUED_STRING_FIELD_KEY_SUFFIX + ":"; + fieldKey = propertyName + SolrConstants.SOLR_STRING_FIELD_KEY_SUFFIX + ":"; query.addFilterQuery(fieldKey + rightPropertyValue); } }