Skip to content

Commit

Permalink
Merge pull request #56 from wso2/revert-50-master
Browse files Browse the repository at this point in the history
Revert "Enabled multivalued support for property fields"
  • Loading branch information
daneshk committed Apr 9, 2015
2 parents d6154a6 + 7ce866e commit a7ee60e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private void addPropertyData() {

if (values != null) {
for (Object value : values) {
propertyValue += value + ",";
propertyValue = value + ",";
}
} else {
propertyValue = ",";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -295,8 +297,8 @@ private void addDynamicFields(Map<String, List<String>> 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;
Expand Down Expand Up @@ -335,28 +337,22 @@ private void addDynamicFields(Map<String, List<String>> 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);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit a7ee60e

Please sign in to comment.