Skip to content

Instantly share code, notes, and snippets.

@dmj
Created April 11, 2012 07:40
Show Gist options
  • Save dmj/2357640 to your computer and use it in GitHub Desktop.
Save dmj/2357640 to your computer and use it in GitHub Desktop.
Compare vanilla VuFind SOLR schema.xml to custom schema.xml
<?php
if (count($argv) != 3) {
die();
}
function load_schema ($path)
{
if (!file_exists($path)) {
die();
}
$parser = xml_parser_create('');
$val = array();
$idx = array();
$types = array();
$fields = array();
if (xml_parse_into_struct($parser, file_get_contents($path), $val, $idx)) {
foreach ($idx['FIELDTYPE'] as $typeIndex) {
if (isset($val[$typeIndex]['attributes'])) {
$attr = $val[$typeIndex]['attributes'];
$name = $attr['NAME'];
if (isset($attr['MULTIVALUED']) && strcasecmp($attr['MULTIVALUED'], 'true') == 0) {
$types[$name] = true;
} else {
$types[$name] = false;
}
}
}
foreach ($idx['FIELD'] as $fieldIndex) {
if (isset($val[$fieldIndex]['attributes'])) {
$attr = $val[$fieldIndex]['attributes'];
$name = $attr['NAME'];
if (isset($attr['MULTIVALUED'])) {
if (strcasecmp($attr['MULTIVALUED'], 'true') == 0) {
$fields[$name] = true;
} else {
$fields[$name] = false;
}
} else {
$fields[$name] = $types[$attr['TYPE']];
}
}
}
}
xml_parser_free($parser);
return $fields;
}
$vufind = load_schema($argv[1]);
$custom = load_schema($argv[2]);
foreach ($vufind as $name => $multi) {
if (!isset($custom[$name])) {
$statCustom = 'MISSING';
$statVufind = '-';
$out = true;
} else {
$statCustom = $custom[$name] ? 'multi' : 'single';
$statVufind = $multi ? 'multi' : 'single';
$out = $multi != $custom[$name];
}
if ($out) {
printf("| %-25s | %-20s | %-20s\n", $name, $statCustom, $statVufind);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment