use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class AddSchemaFieldsUpdateProcessorFactoryTest method testParseAndAddMultipleFieldsRoundTrip.
public void testParseAndAddMultipleFieldsRoundTrip() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
final String fieldName1 = "newfield7";
final String fieldName2 = "newfield8";
final String fieldName3 = "newfield9";
final String fieldName4 = "newfield10";
assertNull(schema.getFieldOrNull(fieldName1));
assertNull(schema.getFieldOrNull(fieldName2));
assertNull(schema.getFieldOrNull(fieldName3));
assertNull(schema.getFieldOrNull(fieldName4));
String field1String1 = "-13,258.0";
Float field1Value1 = -13258.0f;
String field1String2 = "84,828,800,808.0";
Double field1Value2 = 8.4828800808E10;
String field1String3 = "999";
Long field1Value3 = 999L;
String field2String1 = "55,123";
Integer field2Value1 = 55123;
String field2String2 = "1,234,567,890,123,456,789";
Long field2Value2 = 1234567890123456789L;
String field3String1 = "blah-blah";
String field3Value1 = field3String1;
String field3String2 = "-5.28E-3";
Double field3Value2 = -5.28E-3;
String field4String1 = "1999-04-17 17:42";
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm").withZoneUTC();
DateTime dateTime = dateTimeFormatter.parseDateTime(field4String1);
Date field4Value1 = dateTime.toDate();
DateTimeFormatter dateTimeFormatter2 = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").withZoneUTC();
String field4Value1String = dateTimeFormatter2.print(dateTime) + "Z";
SolrInputDocument d = processAdd("parse-and-add-fields", doc(f("id", "6"), f(fieldName1, field1String1, field1String2, field1String3), f(fieldName2, field2String1, field2String2), f(fieldName3, field3String1, field3String2), f(fieldName4, field4String1)));
assertNotNull(d);
schema = h.getCore().getLatestSchema();
assertNotNull(schema.getFieldOrNull(fieldName1));
assertNotNull(schema.getFieldOrNull(fieldName2));
assertNotNull(schema.getFieldOrNull(fieldName3));
assertNotNull(schema.getFieldOrNull(fieldName4));
assertEquals("tdouble", schema.getFieldType(fieldName1).getTypeName());
assertEquals("tlong", schema.getFieldType(fieldName2).getTypeName());
assertEquals("text", schema.getFieldType(fieldName3).getTypeName());
assertEquals("tdate", schema.getFieldType(fieldName4).getTypeName());
assertU(commit());
assertQ(req("id:6"), "//arr[@name='" + fieldName1 + "']/double[.='" + field1Value1.toString() + "']", "//arr[@name='" + fieldName1 + "']/double[.='" + field1Value2.toString() + "']", "//arr[@name='" + fieldName1 + "']/double[.='" + field1Value3.doubleValue() + "']", "//arr[@name='" + fieldName2 + "']/long[.='" + field2Value1.toString() + "']", "//arr[@name='" + fieldName2 + "']/long[.='" + field2Value2.toString() + "']", "//arr[@name='" + fieldName3 + "']/str[.='" + field3String1 + "']", "//arr[@name='" + fieldName3 + "']/str[.='" + field3String2 + "']", "//arr[@name='" + fieldName4 + "']/date[.='" + field4Value1String + "']");
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class AddSchemaFieldsUpdateProcessorFactoryTest method testSingleFieldMixedFieldTypesRoundTrip.
public void testSingleFieldMixedFieldTypesRoundTrip() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
final String fieldName = "newfield3";
assertNull(schema.getFieldOrNull(fieldName));
Float fieldValue1 = -13258.0f;
Double fieldValue2 = 8.4828800808E10;
SolrInputDocument d = processAdd("add-fields", doc(f("id", "3"), f(fieldName, fieldValue1, fieldValue2)));
assertNotNull(d);
schema = h.getCore().getLatestSchema();
assertNotNull(schema.getFieldOrNull(fieldName));
assertEquals("tdouble", schema.getFieldType(fieldName).getTypeName());
assertU(commit());
assertQ(req("id:3"), "//arr[@name='" + fieldName + "']/double[.='" + fieldValue1.toString() + "']", "//arr[@name='" + fieldName + "']/double[.='" + fieldValue2.toString() + "']");
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseTrieIntRoundTrip.
public void testParseTrieIntRoundTrip() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match dynamic field "*_ti"
assertNotNull(schema.getFieldOrNull("int1_ti"));
// should match dynamic field "*_ti"
assertNotNull(schema.getFieldOrNull("int2_ti"));
int value = 1089883491;
String intString1 = "1089883491";
String intString2 = "1,089,883,491";
SolrInputDocument d = processAdd("parse-int", doc(f("id", "113"), f("int1_ti", intString1), f("int2_ti", intString2)));
assertNotNull(d);
assertTrue(d.getFieldValue("int1_ti") instanceof Integer);
assertEquals(value, ((Integer) d.getFieldValue("int1_ti")).intValue());
assertTrue(d.getFieldValue("int2_ti") instanceof Integer);
assertEquals(value, ((Integer) d.getFieldValue("int2_ti")).intValue());
assertU(commit());
assertQ(req("id:113"), "//int[@name='int1_ti'][.='" + value + "']", "//int[@name='int2_ti'][.='" + value + "']");
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseIntNonRootLocale.
public void testParseIntNonRootLocale() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match dynamic field "*_i"
assertNotNull(schema.getFieldOrNull("int_i"));
assertNull(schema.getFieldOrNull("not_in_schema"));
int value = 1089883491;
String intString1 = "1089883491";
// no-break space U+00A0
String intString2 = "1 089 883 491";
SolrInputDocument d = processAdd("parse-int-russian-no-run-processor", doc(f("id", "113"), f("int_i", intString1), f("not_in_schema", intString2)));
assertNotNull(d);
assertTrue(d.getFieldValue("int_i") instanceof Integer);
assertEquals(value, ((Integer) d.getFieldValue("int_i")).intValue());
assertTrue(d.getFieldValue("not_in_schema") instanceof Integer);
assertEquals(value, ((Integer) d.getFieldValue("not_in_schema")).intValue());
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseDateFieldNotInSchema.
public void testParseDateFieldNotInSchema() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
assertNull(schema.getFieldOrNull("not_in_schema"));
String dateString = "2010-11-12T13:14:15.168Z";
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
DateTime dateTime = dateTimeFormatter.parseDateTime(dateString);
SolrInputDocument d = processAdd("parse-date-no-run-processor", doc(f("id", "18"), f("not_in_schema", dateString)));
assertNotNull(d);
assertTrue(d.getFieldValue("not_in_schema") instanceof Date);
assertEquals(dateTime.getMillis(), ((Date) d.getFieldValue("not_in_schema")).getTime());
d = processAdd("parse-date-no-run-processor", doc(f("id", "36"), f("not_in_schema", "not a date", dateString)));
assertNotNull(d);
for (Object val : d.getFieldValues("not_in_schema")) {
// check that nothing was mutated, since not all field values are parseable as dates
assertTrue(val instanceof String);
}
d = processAdd("parse-date-no-run-processor", doc(f("id", "72"), f("not_in_schema", dateString, "not a date")));
assertNotNull(d);
for (Object val : d.getFieldValues("not_in_schema")) {
// check again that nothing was mutated, but with a valid date first this time
assertTrue(val instanceof String);
}
}
Aggregations