use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testFailedParseMixedDate.
public void testFailedParseMixedDate() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
assertNull(schema.getFieldOrNull("not_in_schema"));
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateOptionalTimeParser().withZoneUTC();
Map<Object, Object> mixed = new HashMap<>();
String[] dateStrings = { "2020-05-13T18:47", "1989-12-14", "1682-07-22T18:33:00.000Z" };
for (String dateString : dateStrings) {
mixed.put(dateTimeFormatter.parseDateTime(dateString).toDate(), dateString);
}
Double extraDouble = 29.554d;
// Double-typed field value
mixed.put(extraDouble, extraDouble);
SolrInputDocument d = processAdd("parse-date-no-run-processor", doc(f("id", "7201"), f("not_in_schema", mixed.values())));
assertNotNull(d);
boolean foundDouble = false;
for (Object o : d.getFieldValues("not_in_schema")) {
if (extraDouble == o) {
foundDouble = true;
} else {
assertTrue(o instanceof String);
}
mixed.values().remove(o);
}
assertTrue(foundDouble);
assertTrue(mixed.isEmpty());
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseDoubleRoundTrip.
public void testParseDoubleRoundTrip() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match dynamic field "*_d"
assertNotNull(schema.getFieldOrNull("double1_d"));
// should match dynamic field "*_d"
assertNotNull(schema.getFieldOrNull("double2_d"));
double value = 10898.83491;
String doubleString1 = "10898.83491";
String doubleString2 = "10,898.83491";
SolrInputDocument d = processAdd("parse-double", doc(f("id", "128"), f("double1_d", doubleString1), f("double2_d", doubleString2)));
assertNotNull(d);
assertTrue(d.getFieldValue("double1_d") instanceof Double);
assertEquals(value, (Double) d.getFieldValue("double1_d"), EPSILON);
assertTrue(d.getFieldValue("double2_d") instanceof Double);
assertEquals(value, (Double) d.getFieldValue("double2_d"), EPSILON);
assertU(commit());
assertQ(req("id:128"), "//double[@name='double1_d'][.='" + value + "']", "//double[@name='double2_d'][.='" + value + "']");
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseTrieDoubleRoundTrip.
public void testParseTrieDoubleRoundTrip() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match dynamic field "*_td"
assertNotNull(schema.getFieldOrNull("double1_td"));
// should match dynamic field "*_td"
assertNotNull(schema.getFieldOrNull("double2_td"));
double value = 10898.83491;
String doubleString1 = "10898.83491";
String doubleString2 = "10,898.83491";
SolrInputDocument d = processAdd("parse-double", doc(f("id", "728"), f("double1_td", doubleString1), f("double2_td", doubleString2)));
assertNotNull(d);
assertTrue(d.getFieldValue("double1_td") instanceof Double);
assertEquals(value, (Double) d.getFieldValue("double1_td"), EPSILON);
assertTrue(d.getFieldValue("double2_td") instanceof Double);
assertEquals(value, (Double) d.getFieldValue("double2_td"), EPSILON);
assertU(commit());
assertQ(req("id:728"), "//double[@name='double1_td'][.='" + value + "']", "//double[@name='double2_td'][.='" + value + "']");
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testFailedParseMixedBoolean.
public void testFailedParseMixedBoolean() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
assertNull(schema.getFieldOrNull("not_in_schema"));
Map<Object, Object> mixed = new HashMap<>();
Long longVal = 294423L;
mixed.put(true, "true");
// Float-typed field value
mixed.put(longVal, longVal);
mixed.put(false, "false");
mixed.put(true, "true");
SolrInputDocument d = processAdd("parse-boolean-no-run-processor", doc(f("id", "7207"), f("not_in_schema", mixed.values())));
assertNotNull(d);
boolean foundLong = false;
for (Object o : d.getFieldValues("not_in_schema")) {
if (longVal == o) {
foundLong = true;
} else {
assertTrue(o instanceof String);
}
mixed.values().remove(o);
}
assertTrue(foundLong);
assertTrue(mixed.isEmpty());
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseAlternateValueBooleans.
public void testParseAlternateValueBooleans() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match dynamic field "*_b"
assertNotNull(schema.getFieldOrNull("boolean1_b"));
// should match dynamic field "*_b"
assertNotNull(schema.getFieldOrNull("boolean2_b"));
// should match dynamic field "*_b"
assertNotNull(schema.getFieldOrNull("boolean3_b"));
// should match dynamic field "*_b"
assertNotNull(schema.getFieldOrNull("boolean4_b"));
// should match dynamic field "*_b"
assertNotNull(schema.getFieldOrNull("boolean5_b"));
assertNull(schema.getFieldOrNull("not_in_schema"));
boolean[] values = { true, true, true, false, false, false };
String[] stringValues = { "on", "yes", "True", "Off", "no", "FALSE" };
String[] fieldNames = { "boolean1_b", "boolean2_b", "boolean3_b", "boolean4_b", "boolean5_b", "not_in_schema" };
SolrInputDocument d = doc(f("id", "55"));
for (int i = 0; i < values.length; ++i) {
d.addField(fieldNames[i], stringValues[i]);
}
d = processAdd("parse-boolean-alternate-values-no-run-processor", d);
assertNotNull(d);
for (int i = 0; i < values.length; ++i) {
assertTrue(d.getFieldValue(fieldNames[i]) instanceof Boolean);
assertEquals(values[i], d.getFieldValue(fieldNames[i]));
}
}
Aggregations