Revision: 1784
Author:
olso...@gmail.com
Date: Fri Mar 6 18:06:06 2015 UTC
Log: have VuFindIndexer.getLCSortable fall back to first call number
if no valid LC found
https://code.google.com/p/solrmarc/source/detail?r=1784
Modified:
/trunk/examples/GenericVuFind/src/org/solrmarc/index/VuFindIndexer.java
/trunk/examples/GenericVuFind/test/src/org/solrmarc/index/VuFindIndexerTest.java
=======================================
--- /trunk/examples/GenericVuFind/src/org/solrmarc/index/VuFindIndexer.java
Fri Mar 6 13:44:20 2015 UTC
+++ /trunk/examples/GenericVuFind/src/org/solrmarc/index/VuFindIndexer.java
Fri Mar 6 18:06:06 2015 UTC
@@ -1083,32 +1083,31 @@
/**
- * Normalize LC numbers for sorting purposes (use only the first valid
number!)
+ * Normalize LC numbers for sorting purposes (use only the first valid
number!).
+ * Will return first call number found if none pass validation.
*
- * Can return null
- *
- * @param record current MARC record
- * @param fieldSpec which MARC fields / subfields need to be analyzed
- * @return String containing the first valid LC number encountered,
normalized
- * for sorting purposes.
+ * @param record current MARC record
+ * @param fieldSpec which MARC fields / subfields need to be analyzed
+ * @return sortable shelf key of the first valid LC number encountered,
+ * otherwise shelf key of the first call number found.
*/
- public String getLCSortable(Record record, String fieldSpec) {
+ public static String getLCSortable(Record record, String fieldSpec) {
// Loop through the specified MARC fields:
Set<String> input = getFieldList(record, fieldSpec);
- Iterator<String> iter = input.iterator();
- while (iter.hasNext()) {
- // Get the current string to work on:
- String current = iter.next();
-
+ String firstCall = null;
+ for (String current : input) {
// If this is a valid LC number, return the sortable shelf key:
LCCallNumber callNum = new LCCallNumber(current);
if (callNum.isValid()) {
- return callNum.getShelfKey();
+ return callNum.getShelfKey(); // RETURN first valid
+ }
+ if (firstCall == null) {
+ firstCall = current;
}
}
- // If we made it this far, we didn't find a valid sortable LC
number:
- return null;
+ // If we made it this far, did not find a valid LC number, so use
what we have:
+ return new LCCallNumber(firstCall).getShelfKey();
}
/**
=======================================
---
/trunk/examples/GenericVuFind/test/src/org/solrmarc/index/VuFindIndexerTest.java
Thu Mar 5 21:32:51 2015 UTC
+++
/trunk/examples/GenericVuFind/test/src/org/solrmarc/index/VuFindIndexerTest.java
Fri Mar 6 18:06:06 2015 UTC
@@ -128,4 +128,58 @@
assertEquals(new LCCallNumber(callNumLC).getShelfKey(),
VuFindIndexer.getLCSortableByType(myCallNumRec, "090a", "t", "LC"));
}
+
+ /**
+ * Unit test for VuFindIndexer.getLCSortable
+ */
+ @Test
+ public void testGetLCSortable() {
+
+ // Init records
+ Record myCallNumRec = new RecordImpl();
+ myCallNumRec.setLeader(genericLeader);;
+
+ String callNumDDC = "324.987 B34";
+ DataField df090DDC = new DataFieldImpl("090", ' ', ' ');
+ df090DDC.addSubfield(new SubfieldImpl('a', callNumDDC));
+ df090DDC.addSubfield(new SubfieldImpl('t', "DDC"));
+ myCallNumRec.addVariableField(df090DDC);
+
+ String callNumLC = "PS 1234.5 .G78";
+ DataField df090LC = new DataFieldImpl("090", ' ', ' ');
+ df090LC.addSubfield(new SubfieldImpl('a', callNumLC));
+ df090LC.addSubfield(new SubfieldImpl('t', "LC"));
+ myCallNumRec.addVariableField(df090LC);
+
+ assertEquals(new LCCallNumber(callNumLC).getShelfKey(),
+ VuFindIndexer.getLCSortable(myCallNumRec, "090a"));
+ }
+
+ /**
+ * Unit test for VuFindIndexer.getLCSortable
+ * case where no call number is valid LC.
+ */
+ @Test
+ public void testGetLCSortableNoneValid() {
+
+ // Init records
+ Record myCallNumRec = new RecordImpl();
+ myCallNumRec.setLeader(genericLeader);;
+
+ String callNumDDC = "324.987 B34";
+ DataField df090DDC = new DataFieldImpl("090", ' ', ' ');
+ df090DDC.addSubfield(new SubfieldImpl('a', callNumDDC));
+ df090DDC.addSubfield(new SubfieldImpl('t', "DDC"));
+ myCallNumRec.addVariableField(df090DDC);
+
+ String callNumInvalid = "1234XXXXX";
+ DataField df090LC = new DataFieldImpl("090", ' ', ' ');
+ df090LC.addSubfield(new SubfieldImpl('a', callNumInvalid));
+ df090LC.addSubfield(new SubfieldImpl('t', "LC"));
+ myCallNumRec.addVariableField(df090LC);
+
+ assertEquals(new LCCallNumber(callNumDDC).getShelfKey(),
+ VuFindIndexer.getLCSortable(myCallNumRec, "090a"));
+ }
+
}