use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseLongRoundTrip.
public void testParseLongRoundTrip() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match dynamic field "*_l"
assertNotNull(schema.getFieldOrNull("long1_l"));
// should match dynamic field "*_l"
assertNotNull(schema.getFieldOrNull("long2_l"));
long value = 1089883491L;
String longString1 = "1089883491";
String longString2 = "1,089,883,491";
SolrInputDocument d = processAdd("parse-long", doc(f("id", "113"), f("long1_l", longString1), f("long2_l", longString2)));
assertNotNull(d);
assertTrue(d.getFieldValue("long1_l") instanceof Long);
assertEquals(value, ((Long) d.getFieldValue("long1_l")).longValue());
assertTrue(d.getFieldValue("long2_l") instanceof Long);
assertEquals(value, ((Long) d.getFieldValue("long2_l")).longValue());
assertU(commit());
assertQ(req("id:113"), "//long[@name='long1_l'][.='" + value + "']", "//long[@name='long2_l'][.='" + value + "']");
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testParseLongNonRootLocale.
public void testParseLongNonRootLocale() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
// should match dynamic field "*_l"
assertNotNull(schema.getFieldOrNull("long_l"));
assertNull(schema.getFieldOrNull("not_in_schema"));
long value = 1089883491L;
String longString1 = "1089883491";
// no-break space U+00A0
String longString2 = "1 089 883 491";
SolrInputDocument d = processAdd("parse-long-russian-no-run-processor", doc(f("id", "113"), f("long_l", longString1), f("not_in_schema", longString2)));
assertNotNull(d);
assertTrue(d.getFieldValue("long_l") instanceof Long);
assertEquals(value, ((Long) d.getFieldValue("long_l")).longValue());
assertTrue(d.getFieldValue("not_in_schema") instanceof Long);
assertEquals(value, ((Long) d.getFieldValue("not_in_schema")).longValue());
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class ParsingFieldUpdateProcessorsTest method testFailedParseMixedInt.
public void testFailedParseMixedInt() 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(85, "85");
// Float-typed field value
mixed.put(floatVal, floatVal);
mixed.put(-2894518, "-2,894,518");
mixed.put(1879472193, "1,879,472,193");
SolrInputDocument d = processAdd("parse-int-no-run-processor", doc(f("id", "7202"), 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 LukeRequestHandlerTest method testCatchAllCopyField.
public void testCatchAllCopyField() throws Exception {
deleteCore();
initCore("solrconfig.xml", "schema-copyfield-test.xml");
IndexSchema schema = h.getCore().getLatestSchema();
assertNull("'*' should not be (or match) a dynamic field", schema.getDynamicPattern("*"));
boolean foundCatchAllCopyField = false;
for (IndexSchema.DynamicCopy dcf : schema.getDynamicCopyFields()) {
foundCatchAllCopyField = dcf.getRegex().equals("*") && dcf.getDestFieldName().equals("catchall_t");
if (foundCatchAllCopyField) {
break;
}
}
assertTrue("<copyField source=\"*\" dest=\"catchall_t\"/> is missing from the schema", foundCatchAllCopyField);
SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema", "indent", "on");
String xml = h.query(req);
String result = TestHarness.validateXPath(xml, field("bday") + "/arr[@name='copyDests']/str[.='catchall_t']");
assertNull(xml, result);
// Put back the configuration expected by the rest of the tests in this suite
deleteCore();
initCore("solrconfig.xml", "schema12.xml");
}
use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.
the class CursorMarkTest method testRoundTripParsing.
public void testRoundTripParsing() throws IOException {
// for any valid SortSpec, and any legal values, we should be able to round
// trip serialize the totem and get the same values back.
final Collection<String> allFieldNames = getAllFieldNames();
final SolrQueryRequest req = req();
final IndexSchema schema = req.getSchema();
final int numRandomSorts = atLeast(50);
final int numRandomValIters = atLeast(10);
for (int i = 0; i < numRandomSorts; i++) {
final SortSpec ss = SortSpecParsing.parseSortSpec(CursorPagingTest.buildRandomSort(allFieldNames), req);
final CursorMark totemIn = new CursorMark(schema, ss);
final CursorMark totemOut = new CursorMark(schema, ss);
// trivial case: regardless of sort, "*" should be valid and roundtrippable
totemIn.parseSerializedTotem(CURSOR_MARK_START);
assertEquals(CURSOR_MARK_START, totemIn.getSerializedTotem());
// values should be null (and still roundtrippable)
assertNull(totemIn.getSortValues());
totemOut.setSortValues(null);
assertEquals(CURSOR_MARK_START, totemOut.getSerializedTotem());
for (int j = 0; j < numRandomValIters; j++) {
final Object[] inValues = buildRandomSortObjects(ss);
totemIn.setSortValues(Arrays.<Object>asList(inValues));
totemOut.parseSerializedTotem(totemIn.getSerializedTotem());
final List<Object> out = totemOut.getSortValues();
assertNotNull(out);
final Object[] outValues = out.toArray();
assertArrayEquals(inValues, outValues);
}
}
}
Aggregations