use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseBooleanRoundTrip.
public void testParseBooleanRoundTrip() 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 value1 = true;
boolean value2 = false;
SolrInputDocument d = processAdd("parse-boolean", doc(f("id", "141"), f("boolean1_b", value1), f("boolean2_b", value2)));
assertNotNull(d);
assertTrue(d.getFieldValue("boolean1_b") instanceof Boolean);
assertEquals(value1, d.getFieldValue("boolean1_b"));
assertTrue(d.getFieldValue("boolean2_b") instanceof Boolean);
assertEquals(value2, d.getFieldValue("boolean2_b"));
assertU(commit());
assertQ(req("id:141"), "//bool[@name='boolean1_b'][.='" + value1 + "']", "//bool[@name='boolean2_b'][.='" + value2 + "']");
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testCascadingParsers.
public void testCascadingParsers() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
final String fieldName = "not_in_schema";
assertNull(schema.getFieldOrNull(fieldName));
SolrInputDocument d = null;
String chain = "cascading-parsers-no-run-processor";
Map<Boolean, String> booleans = new HashMap<>();
booleans.put(true, "truE");
booleans.put(false, "False");
d = processAdd(chain, doc(f("id", "341"), f(fieldName, booleans.values())));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof Boolean);
booleans.remove(o);
}
assertTrue(booleans.isEmpty());
Map<Integer, String> ints = new HashMap<>();
ints.put(2, "2");
ints.put(50928, "50928");
ints.put(86942008, "86,942,008");
d = processAdd(chain, doc(f("id", "333"), f(fieldName, ints.values())));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof Integer);
ints.remove(o);
}
assertTrue(ints.isEmpty());
Map<Long, String> longs = new HashMap<>();
longs.put(2L, "2");
longs.put(50928L, "50928");
longs.put(86942008987654L, "86,942,008,987,654");
d = processAdd(chain, doc(f("id", "342"), f(fieldName, longs.values())));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof Long);
longs.remove(o);
}
assertTrue(longs.isEmpty());
/*
// Disabling this test because unlike Integer/Long, Float parsing can perform
// rounding to make values fit. See
Map<Float,String> floats = new HashMap<Float,String>();
floats.put(2.0, "2.");
floats.put(509.28, "509.28");
floats.put(86942.008, "86,942.008");
d = processAdd(chain, doc(f("id", "342"), f(fieldName, floats.values())));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof float);
longs.remove(o);
}
*/
Map<Double, String> doubles = new HashMap<>();
doubles.put(2.0, "2.");
doubles.put(509.28, "509.28");
doubles.put(86942.008, "86,942.008");
d = processAdd(chain, doc(f("id", "342"), f(fieldName, doubles.values())));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof Double);
longs.remove(o);
}
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateOptionalTimeParser().withZoneUTC();
Map<Date, String> dates = new HashMap<>();
String[] dateStrings = { "2020-05-13T18:47", "1989-12-14", "1682-07-22T18:33:00.000Z" };
for (String dateString : dateStrings) {
dates.put(dateTimeFormatter.parseDateTime(dateString).toDate(), dateString);
}
d = processAdd(chain, doc(f("id", "343"), f(fieldName, dates.values())));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof Date);
dates.remove(o);
}
assertTrue(dates.isEmpty());
// preserve order
Map<Double, String> mixedLongsAndDoubles = new LinkedHashMap<>();
mixedLongsAndDoubles.put(85.0, "85");
mixedLongsAndDoubles.put(2.94423E-9, "2.94423E-9");
mixedLongsAndDoubles.put(2894518.0, "2,894,518");
mixedLongsAndDoubles.put(48794721.937, "48,794,721.937");
d = processAdd(chain, doc(f("id", "344"), f(fieldName, mixedLongsAndDoubles.values())));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof Double);
mixedLongsAndDoubles.remove(o);
}
assertTrue(mixedLongsAndDoubles.isEmpty());
Set<String> mixed = new HashSet<>();
mixed.add("true");
mixed.add("1682-07-22T18:33:00.000Z");
mixed.add("2,894,518");
mixed.add("308,393,131,379,900");
mixed.add("48,794,721.937");
d = processAdd(chain, doc(f("id", "345"), f(fieldName, mixed)));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof String);
}
// preserve order
Map<Double, Object> mixedDoubles = new LinkedHashMap<>();
mixedDoubles.put(85.0, "85");
// Double-typed field value
mixedDoubles.put(2.94423E-9, 2.94423E-9);
mixedDoubles.put(2894518.0, "2,894,518");
mixedDoubles.put(48794721.937, "48,794,721.937");
d = processAdd(chain, doc(f("id", "3391"), f(fieldName, mixedDoubles.values())));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof Double);
mixedDoubles.remove(o);
}
assertTrue(mixedDoubles.isEmpty());
// preserve order
Map<Integer, Object> mixedInts = new LinkedHashMap<>();
mixedInts.put(85, "85");
// Integer-typed field value
mixedInts.put(294423, 294423);
mixedInts.put(-2894518, "-2,894,518");
mixedInts.put(1879472193, "1,879,472,193");
d = processAdd(chain, doc(f("id", "3392"), f(fieldName, mixedInts.values())));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof Integer);
mixedInts.remove(o);
}
assertTrue(mixedInts.isEmpty());
// preserve order
Map<Long, Object> mixedLongs = new LinkedHashMap<>();
mixedLongs.put(85L, "85");
// Long-typed field value
mixedLongs.put(42944233L, 42944233L);
mixedLongs.put(2894518L, "2,894,518");
mixedLongs.put(48794721937L, "48,794,721,937");
d = processAdd(chain, doc(f("id", "3393"), f(fieldName, mixedLongs.values())));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof Long);
mixedLongs.remove(o);
}
assertTrue(mixedLongs.isEmpty());
// preserve order
Map<Boolean, Object> mixedBooleans = new LinkedHashMap<>();
mixedBooleans.put(true, "true");
// Boolean-typed field value
mixedBooleans.put(false, false);
mixedBooleans.put(false, "false");
mixedBooleans.put(true, "true");
d = processAdd(chain, doc(f("id", "3394"), f(fieldName, mixedBooleans.values())));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof Boolean);
mixedBooleans.remove(o);
}
assertTrue(mixedBooleans.isEmpty());
dateTimeFormatter = ISODateTimeFormat.dateOptionalTimeParser().withZoneUTC();
Map<Date, Object> mixedDates = new HashMap<>();
dateStrings = new String[] { "2020-05-13T18:47", "1989-12-14", "1682-07-22T18:33:00.000Z" };
for (String dateString : dateStrings) {
mixedDates.put(dateTimeFormatter.parseDateTime(dateString).toDate(), dateString);
}
Date extraDate = dateTimeFormatter.parseDateTime("2003-04-24").toDate();
// Date-typed field value
mixedDates.put(extraDate, extraDate);
d = processAdd(chain, doc(f("id", "3395"), f(fieldName, mixedDates.values())));
assertNotNull(d);
for (Object o : d.getFieldValues(fieldName)) {
assertTrue(o instanceof Date);
mixedDates.remove(o);
}
assertTrue(mixedDates.isEmpty());
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class FieldMutatingUpdateProcessorTest method testIgnore.
public void testIgnore() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
assertNull("test expects 'foo_giberish' to not be a valid field, looks like schema was changed out from under us", schema.getFieldTypeNoEx("foo_giberish"));
assertNull("test expects 'bar_giberish' to not be a valid field, looks like schema was changed out from under us", schema.getFieldTypeNoEx("bar_giberish"));
assertNotNull("test expects 't_raw' to be a valid field, looks like schema was changed out from under us", schema.getFieldTypeNoEx("t_raw"));
assertNotNull("test expects 'foo_s' to be a valid field, looks like schema was changed out from under us", schema.getFieldTypeNoEx("foo_s"));
SolrInputDocument d = null;
d = processAdd("ignore-not-in-schema", doc(f("id", "1111"), f("bar_giberish", "123456789", "", 42, "abcd"), f("foo_giberish", "123456789", "", 42, "abcd"), f("t_raw", "123456789", "", 42, "abcd"), f("foo_s", "hoss")));
assertNotNull(d);
assertFalse(d.containsKey("bar_giberish"));
assertFalse(d.containsKey("foo_giberish"));
assertEquals(Arrays.asList("123456789", "", 42, "abcd"), d.getFieldValues("t_raw"));
assertEquals("hoss", d.getFieldValue("foo_s"));
d = processAdd("ignore-some", doc(f("id", "1111"), f("foo_giberish", "123456789", "", 42, "abcd"), f("bar_giberish", "123456789", "", 42, "abcd"), f("t_raw", "123456789", "", 42, "abcd"), f("foo_s", "hoss")));
assertNotNull(d);
assertEquals(Arrays.asList("123456789", "", 42, "abcd"), d.getFieldValues("foo_giberish"));
assertEquals(Arrays.asList("123456789", "", 42, "abcd"), d.getFieldValues("bar_giberish"));
assertFalse(d.containsKey("t_raw"));
assertEquals("hoss", d.getFieldValue("foo_s"));
d = processAdd("ignore-not-in-schema-explicit-selector", doc(f("id", "1111"), f("foo_giberish", "123456789", "", 42, "abcd"), f("bar_giberish", "123456789", "", 42, "abcd"), f("t_raw", "123456789", "", 42, "abcd"), f("foo_s", "hoss")));
assertNotNull(d);
assertFalse(d.containsKey("foo_giberish"));
assertFalse(d.containsKey("bar_giberish"));
assertEquals(Arrays.asList("123456789", "", 42, "abcd"), d.getFieldValues("t_raw"));
assertEquals("hoss", d.getFieldValue("foo_s"));
d = processAdd("ignore-not-in-schema-and-foo-name-prefix", doc(f("id", "1111"), f("foo_giberish", "123456789", "", 42, "abcd"), f("bar_giberish", "123456789", "", 42, "abcd"), f("t_raw", "123456789", "", 42, "abcd"), f("foo_s", "hoss")));
assertNotNull(d);
assertFalse(d.containsKey("foo_giberish"));
assertEquals(Arrays.asList("123456789", "", 42, "abcd"), d.getFieldValues("bar_giberish"));
assertEquals(Arrays.asList("123456789", "", 42, "abcd"), d.getFieldValues("t_raw"));
assertEquals("hoss", d.getFieldValue("foo_s"));
d = processAdd("ignore-foo-name-prefix-except-not-schema", doc(f("id", "1111"), f("foo_giberish", "123456789", "", 42, "abcd"), f("bar_giberish", "123456789", "", 42, "abcd"), f("t_raw", "123456789", "", 42, "abcd"), f("foo_s", "hoss")));
assertNotNull(d);
assertEquals(Arrays.asList("123456789", "", 42, "abcd"), d.getFieldValues("foo_giberish"));
assertEquals(Arrays.asList("123456789", "", 42, "abcd"), d.getFieldValues("bar_giberish"));
assertEquals(Arrays.asList("123456789", "", 42, "abcd"), d.getFieldValues("t_raw"));
assertFalse(d.containsKey("foo_s"));
d = processAdd("ignore-in-schema", doc(f("id", "1111"), f("foo_giberish", "123456789", "", 42, "abcd"), f("bar_giberish", "123456789", "", 42, "abcd"), f("t_raw", "123456789", "", 42, "abcd"), f("foo_s", "hoss")));
assertNotNull(d);
assertTrue(d.containsKey("foo_giberish"));
assertTrue(d.containsKey("bar_giberish"));
assertFalse(d.containsKey("id"));
assertFalse(d.containsKey("t_raw"));
assertFalse(d.containsKey("foo_s"));
d = processAdd("ignore-not-in-schema-explicit-str-selector", doc(f("id", "1111"), f("foo_giberish", "123456789", "", 42, "abcd"), f("bar_giberish", "123456789", "", 42, "abcd"), f("t_raw", "123456789", "", 42, "abcd"), f("foo_s", "hoss")));
assertNotNull(d);
assertFalse(d.containsKey("foo_giberish"));
assertFalse(d.containsKey("bar_giberish"));
assertEquals(Arrays.asList("123456789", "", 42, "abcd"), d.getFieldValues("t_raw"));
assertEquals("hoss", d.getFieldValue("foo_s"));
d = processAdd("ignore-in-schema-str-selector", doc(f("id", "1111"), f("foo_giberish", "123456789", "", 42, "abcd"), f("bar_giberish", "123456789", "", 42, "abcd"), f("t_raw", "123456789", "", 42, "abcd"), f("foo_s", "hoss")));
assertNotNull(d);
assertTrue(d.containsKey("foo_giberish"));
assertTrue(d.containsKey("bar_giberish"));
assertFalse(d.containsKey("id"));
assertFalse(d.containsKey("t_raw"));
assertFalse(d.containsKey("foo_s"));
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class TestMinMaxOnMultiValuedField method beforeClass.
/** Initializes core and does some sanity checking of schema */
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig-functionquery.xml", "schema11.xml");
// sanity check the expected properties of our fields (ie: who broke the schema?)
IndexSchema schema = h.getCore().getLatestSchema();
for (String type : new String[] { "i", "l", "f", "d" }) {
for (String suffix : new String[] { "", "_dv", "_ni_dv" }) {
String f = "val_t" + type + "s" + suffix;
SchemaField sf = schema.getField(f);
assertTrue(f + " is not multivalued", sf.multiValued());
assertEquals(f + " doesn't have expected docValues status", f.contains("dv"), sf.hasDocValues());
assertEquals(f + " doesn't have expected index status", !f.contains("ni"), sf.indexed());
}
}
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class AddSchemaFieldsUpdateProcessorFactoryTest method testSingleFieldDefaultFieldTypeRoundTrip.
public void testSingleFieldDefaultFieldTypeRoundTrip() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
final String fieldName = "newfield4";
assertNull(schema.getFieldOrNull(fieldName));
Float fieldValue1 = -13258.0f;
Double fieldValue2 = 8.4828800808E10;
String fieldValue3 = "blah blah";
SolrInputDocument d = processAdd("add-fields", doc(f("id", "4"), f(fieldName, fieldValue1, fieldValue2, fieldValue3)));
assertNotNull(d);
schema = h.getCore().getLatestSchema();
assertNotNull(schema.getFieldOrNull(fieldName));
assertEquals("text", schema.getFieldType(fieldName).getTypeName());
assertU(commit());
assertQ(req("id:4"), "//arr[@name='" + fieldName + "']/str[.='" + fieldValue1.toString() + "']", "//arr[@name='" + fieldName + "']/str[.='" + fieldValue2.toString() + "']", "//arr[@name='" + fieldName + "']/str[.='" + fieldValue3.toString() + "']");
}
Aggregations