use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseAlternateSingleValuesBooleans.
public void testParseAlternateSingleValuesBooleans() 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"));
boolean[] values = { true, false };
String[] stringValues = { "yup", "nope" };
String[] fieldNames = { "boolean1_b", "boolean2_b" };
SolrInputDocument d = doc(f("id", "59"));
for (int i = 0; i < values.length; ++i) {
d.addField(fieldNames[i], stringValues[i]);
}
d = processAdd("parse-boolean-alternate-single-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]));
}
// Standard boolean values should not be mutated, since they're not configured
stringValues = new String[] { "true", "false" };
d = doc(f("id", "593"));
for (int i = 0; i < values.length; ++i) {
d.addField(fieldNames[i], stringValues[i]);
}
d = processAdd("parse-boolean-alternate-single-values-no-run-processor", d);
assertNotNull(d);
for (int i = 0; i < values.length; ++i) {
assertTrue(d.getFieldValue(fieldNames[i]) instanceof String);
}
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseIntRoundTrip.
public void testParseIntRoundTrip() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match dynamic field "*_i"
assertNotNull(schema.getFieldOrNull("int1_i"));
// should match dynamic field "*_i"
assertNotNull(schema.getFieldOrNull("int2_i"));
int value = 1089883491;
String intString1 = "1089883491";
String intString2 = "1,089,883,491";
SolrInputDocument d = processAdd("parse-int", doc(f("id", "113"), f("int1_i", intString1), f("int2_i", intString2)));
assertNotNull(d);
assertTrue(d.getFieldValue("int1_i") instanceof Integer);
assertEquals(value, ((Integer) d.getFieldValue("int1_i")).intValue());
assertTrue(d.getFieldValue("int2_i") instanceof Integer);
assertEquals(value, ((Integer) d.getFieldValue("int2_i")).intValue());
assertU(commit());
assertQ(req("id:113"), "//int[@name='int1_i'][.='" + value + "']", "//int[@name='int2_i'][.='" + value + "']");
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testMixedFloats.
public void testMixedFloats() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match dynamic field "*_tf"
assertNotNull(schema.getFieldOrNull("float_tf"));
Map<Float, Object> mixedFloats = new HashMap<>();
mixedFloats.put(85.0f, "85");
mixedFloats.put(2894518.0f, "2,894,518");
// Float-typed field value
mixedFloats.put(2.94423E-9f, 2.94423E-9f);
mixedFloats.put(48794721.937f, "48,794,721.937");
SolrInputDocument d = processAdd("parse-float-no-run-processor", doc(f("id", "342"), f("float_tf", mixedFloats.values())));
assertNotNull(d);
for (Object o : d.getFieldValues("float_tf")) {
assertTrue(o instanceof Float);
mixedFloats.remove(o);
}
assertTrue(mixedFloats.isEmpty());
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testFailedParseMixedLong.
public void testFailedParseMixedLong() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
assertNull(schema.getFieldOrNull("not_in_schema"));
Map<Object, Object> mixed = new HashMap<>();
Float floatVal = 294423.0f;
mixed.put(85L, "85");
// Float-typed field value
mixed.put(floatVal, floatVal);
mixed.put(-2894518L, "-2,894,518");
mixed.put(1879472193L, "1,879,472,193");
SolrInputDocument d = processAdd("parse-long-no-run-processor", doc(f("id", "7204"), f("not_in_schema", mixed.values())));
assertNotNull(d);
boolean foundFloat = false;
for (Object o : d.getFieldValues("not_in_schema")) {
if (floatVal == o) {
foundFloat = true;
} else {
assertTrue(o instanceof String);
}
mixed.values().remove(o);
}
assertTrue(foundFloat);
assertTrue(mixed.isEmpty());
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseDateRoundTrip.
public void testParseDateRoundTrip() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match "*_dt" dynamic field
assertNotNull(schema.getFieldOrNull("date_dt"));
String dateString = "2010-11-12T13:14:15.168Z";
SolrInputDocument d = processAdd("parse-date", doc(f("id", "9"), f("date_dt", dateString)));
assertNotNull(d);
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
DateTime dateTime = dateTimeFormatter.parseDateTime(dateString);
assertTrue(d.getFieldValue("date_dt") instanceof Date);
assertEquals(dateTime.getMillis(), ((Date) d.getFieldValue("date_dt")).getTime());
assertU(commit());
assertQ(req("id:9"), "//date[@name='date_dt'][.='" + dateString + "']");
}
Aggregations