Skip to content
Snippets Groups Projects
Commit d776d3e9 authored by Demian Katz's avatar Demian Katz
Browse files

Updated to latest files from SolrMarc trunk.

- Resolves VUFIND-1125
parent 24a5713c
No related merge requests found
...@@ -6,125 +6,137 @@ ...@@ -6,125 +6,137 @@
* it will be applied during indexing. * it will be applied during indexing.
*/ */
import org.marc4j.marc.Record; import org.marc4j.marc.Record;
import org.solrmarc.callnum.LCCallNumber;
import org.solrmarc.index.SolrIndexer;
// define the base level indexer so that its methods can be called from the script. // define the base level indexer so that its methods can be called from the script.
// note that the SolrIndexer code will set this value before the script methods are called. // note that the SolrIndexer code will set this value before the script methods are called.
org.solrmarc.index.SolrIndexer indexer = null; org.solrmarc.index.SolrIndexer indexer = null;
/** /**
* Extract the call number label from a record * Extract the full call number from a record, stripped of spaces
* @param record * @param record MARC record
* @return Call number label * @return Call number label
*/ * @deprecated Obsolete as of VuFind 2.4.
public String getFullCallNumber(Record record) { * This method exists only to support the VuFind call number search, version <= 2.3.
* As of VuFind 2.4, the munging for call number search in handled entirely in Solr.
return(getFullCallNumber(record, "099ab:090ab:050ab")); */
} public String getFullCallNumber(Record record) {
/** return(getFullCallNumber(record, "099ab:090ab:050ab"));
* Extract the call number label from a record }
* @param record
* @return Call number label
*/
public String getFullCallNumber(Record record, String fieldSpec) {
String val = indexer.getFirstFieldVal(record, fieldSpec); /**
* Extract the full call number from a record, stripped of spaces
* @param record MARC record
* @param fieldSpec taglist for call number fields
* @return Call number label
* @deprecated Obsolete as of VuFind 2.4.
* This method exists only to support the VuFind call number search, version <= 2.3.
* As of VuFind 2.4, the munging for call number search in handled entirely in Solr.
*/
public String getFullCallNumber(Record record, String fieldSpec) {
String val = SolrIndexer.getFirstFieldVal(record, fieldSpec);
if (val != null) {
return val.toUpperCase().replaceAll(" ", "");
} else {
return val;
}
}
if (val != null) {
return val.toUpperCase().replaceAll(" ", "");
} else {
return val;
}
}
/** /**
* Extract the call number label from a record * Extract the call number label from a record
* @param record * @param record MARC record
* @return Call number label * @return Call number label
*/ */
public String getCallNumberLabel(Record record) { public String getCallNumberLabel(Record record) {
return getCallNumberLabel(record, "090a:050a"); return getCallNumberLabel(record, "090a:050a");
} }
/** /**
* Extract the call number label from a record * Extract the call number label from a record
* @param record * @param record MARC record
* @return Call number label * @param fieldSpec taglist for call number fields
*/ * @return Call number label
public String getCallNumberLabel(Record record, String fieldSpec) { */
public String getCallNumberLabel(Record record, String fieldSpec) {
String val = indexer.getFirstFieldVal(record, fieldSpec);
String val = SolrIndexer.getFirstFieldVal(record, fieldSpec);
if (val != null) {
int dotPos = val.indexOf("."); if (val != null) {
if (dotPos > 0) { int dotPos = val.indexOf(".");
val = val.substring(0, dotPos); if (dotPos > 0) {
} val = val.substring(0, dotPos);
return val.toUpperCase(); }
} else { return val.toUpperCase();
return val; } else {
} return val;
} }
}
/** /**
* Extract the subject component of the call number * Extract the subject component of the call number
* *
* Can return null * Can return null
* *
* @param record * @param record MARC record
* @return Call number label * @return Call number subject letters
*/ */
public String getCallNumberSubject(Record record) { public String getCallNumberSubject(Record record) {
return(getCallNumberSubject(record, "090a:050a")); return(getCallNumberSubject(record, "090a:050a"));
} }
/** /**
* Extract the subject component of the call number * Extract the subject component of the call number
* *
* Can return null * Can return null
* *
* @param record * @param record current MARC record
* @return Call number label * @return Call number subject letters
*/ */
public String getCallNumberSubject(Record record, String fieldSpec) { public String getCallNumberSubject(Record record, String fieldSpec) {
String val = indexer.getFirstFieldVal(record, fieldSpec); String val = SolrIndexer.getFirstFieldVal(record, fieldSpec);
if (val != null) { if (val != null) {
String [] callNumberSubject = val.toUpperCase().split("[^A-Z]+"); String [] callNumberSubject = val.toUpperCase().split("[^A-Z]+");
if (callNumberSubject.length > 0) if (callNumberSubject.length > 0)
{ {
return callNumberSubject[0]; return callNumberSubject[0];
} }
} }
return(null); return(null);
} }
/** /**
* Normalize a single LCCN * Normalize a single LC call number
* @param record * @param record current MARC record
* @param fieldSpec * @return String Normalized LCCN
* @return String Normalized LCCN */
*/ public String getFullCallNumberNormalized(Record record) {
public String getFullCallNumberNormalized(Record record) {
return(getFullCallNumberNormalized(record, "099ab:090ab:050ab")); return(getFullCallNumberNormalized(record, "099ab:090ab:050ab"));
} }
/** /**
* Normalize a single LCCN * Normalize a single LC call number
* @param record * @param record current MARC record
* @param fieldSpec * @param fieldSpec which MARC fields / subfields need to be analyzed
* @return String Normalized LCCN * @return String Normalized LC call number
*/ */
public String getFullCallNumberNormalized(Record record, String fieldSpec) { public String getFullCallNumberNormalized(Record record, String fieldSpec) {
if (fieldSpec != null) { // TODO: is the null fieldSpec still an issue?
String cn = indexer.getFirstFieldVal(record, fieldSpec); if (fieldSpec != null) {
return (new LCCallNumber(cn)).getShelfKey(); String cn = SolrIndexer.getFirstFieldVal(record, fieldSpec);
return (new LCCallNumber(cn)).getShelfKey();
}
// If we got this far, we couldn't find a valid value:
return null;
} }
// If we got this far, we couldn't find a valid value:
return null;
}
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
* it will be applied during indexing. * it will be applied during indexing.
*/ */
import org.marc4j.marc.Record; import org.marc4j.marc.Record;
import org.solrmarc.callnum.DeweyCallNumber;
import org.solrmarc.index.SolrIndexer;
import org.solrmarc.tools.CallNumUtils; import org.solrmarc.tools.CallNumUtils;
/** /**
...@@ -13,9 +15,9 @@ import org.solrmarc.tools.CallNumUtils; ...@@ -13,9 +15,9 @@ import org.solrmarc.tools.CallNumUtils;
* *
* Can return null * Can return null
* *
* @param record * @param record current MARC record
* @param fieldSpec - which MARC fields / subfields need to be analyzed * @param fieldSpec which MARC fields / subfields need to be analyzed
* @param precisionStr - a decimal number (represented in string format) showing the * @param precisionStr a decimal number (represented in string format) showing the
* desired precision of the returned number; i.e. 100 to round to nearest hundred, * desired precision of the returned number; i.e. 100 to round to nearest hundred,
* 10 to round to nearest ten, 0.1 to round to nearest tenth, etc. * 10 to round to nearest ten, 0.1 to round to nearest tenth, etc.
* @return Set containing requested numeric portions of Dewey decimal call numbers * @return Set containing requested numeric portions of Dewey decimal call numbers
...@@ -28,21 +30,18 @@ public Set getDeweyNumber(Record record, String fieldSpec, String precisionStr) ...@@ -28,21 +30,18 @@ public Set getDeweyNumber(Record record, String fieldSpec, String precisionStr)
float precision = Float.parseFloat(precisionStr); float precision = Float.parseFloat(precisionStr);
// Loop through the specified MARC fields: // Loop through the specified MARC fields:
Set input = indexer.getFieldList(record, fieldSpec); Set input = SolrIndexer.getFieldList(record, fieldSpec);
Iterator iter = input.iterator(); for (String current: input) {
while (iter.hasNext()) {
// Get the current string to work on:
String current = iter.next();
DeweyCallNumber callNum = new DeweyCallNumber(current); DeweyCallNumber callNum = new DeweyCallNumber(current);
if (callNum.isValid()) { if (callNum.isValid()) {
// Convert the numeric portion of the call number into a float: // Convert the numeric portion of the call number into a float:
float currentVal = Float.parseFloat(callNum.getClassification()); float currentVal = Float.parseFloat(callNum.getClassification());
// Round the call number value to the specified precision: // Round the call number value to the specified precision:
Float finalVal = new Float(Math.floor(currentVal / precision) * precision); Float finalVal = new Float(Math.floor(currentVal / precision) * precision);
// Convert the rounded value back to a string (with leading zeros) and save it: // Convert the rounded value back to a string (with leading zeros) and save it:
// TODO: Provide different conversion to remove CallNumUtils dependency
result.add(CallNumUtils.normalizeFloat(finalVal.toString(), 3, -1)); result.add(CallNumUtils.normalizeFloat(finalVal.toString(), 3, -1));
} }
} }
...@@ -58,8 +57,8 @@ public Set getDeweyNumber(Record record, String fieldSpec, String precisionStr) ...@@ -58,8 +57,8 @@ public Set getDeweyNumber(Record record, String fieldSpec, String precisionStr)
* *
* Can return null * Can return null
* *
* @param record * @param record current MARC record
* @param fieldSpec - which MARC fields / subfields need to be analyzed * @param fieldSpec which MARC fields / subfields need to be analyzed
* @return Set containing normalized Dewey numbers extracted from specified fields. * @return Set containing normalized Dewey numbers extracted from specified fields.
*/ */
public Set getDeweySearchable(Record record, String fieldSpec) { public Set getDeweySearchable(Record record, String fieldSpec) {
...@@ -67,7 +66,7 @@ public Set getDeweySearchable(Record record, String fieldSpec) { ...@@ -67,7 +66,7 @@ public Set getDeweySearchable(Record record, String fieldSpec) {
Set result = new LinkedHashSet(); Set result = new LinkedHashSet();
// Loop through the specified MARC fields: // Loop through the specified MARC fields:
Set input = indexer.getFieldList(record, fieldSpec); Set input = SolrIndexer.getFieldList(record, fieldSpec);
Iterator iter = input.iterator(); Iterator iter = input.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
// Get the current string to work on: // Get the current string to work on:
...@@ -92,14 +91,14 @@ public Set getDeweySearchable(Record record, String fieldSpec) { ...@@ -92,14 +91,14 @@ public Set getDeweySearchable(Record record, String fieldSpec) {
* *
* Can return null * Can return null
* *
* @param record * @param record current MARC record
* @param fieldSpec - which MARC fields / subfields need to be analyzed * @param fieldSpec which MARC fields / subfields need to be analyzed
* @return String containing the first valid Dewey number encountered, normalized * @return String containing the first valid Dewey number encountered, normalized
* for sorting purposes. * for sorting purposes.
*/ */
public String getDeweySortable(Record record, String fieldSpec) { public String getDeweySortable(Record record, String fieldSpec) {
// Loop through the specified MARC fields: // Loop through the specified MARC fields:
Set input = indexer.getFieldList(record, fieldSpec); Set input = SolrIndexer.getFieldList(record, fieldSpec);
Iterator iter = input.iterator(); Iterator iter = input.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
// Get the current string to work on: // Get the current string to work on:
...@@ -116,13 +115,64 @@ public String getDeweySortable(Record record, String fieldSpec) { ...@@ -116,13 +115,64 @@ public String getDeweySortable(Record record, String fieldSpec) {
return null; return null;
} }
/**
* Get sort key for first Dewey call number, identified by call type.
*
* <p>{@code fieldSpec} is of form {@literal 098abc:099ab}, does not accept subfield ranges.
*
*
* @param record current MARC record
* @param fieldSpec which MARC fields / subfields need to be analyzed
* @param callTypeSf subfield containing call number type, single character only
* @param callType literal call number code
* @return sort key for first identified Dewey call number
*/
public static String getDeweySortableByType(
Record record, String fieldSpec, String callTypeSf, String callType) {
String sortKey = null;
for (String tag : fieldSpec.split(":")) {
// Check to ensure tag length is at least 3 characters
if (tag.length() < 3) {
//TODO: Should this go to a log? Better message for a bad tag in a field spec?
System.err.println("Invalid tag specified: " + tag);
continue;
}
String dfTag = tag.substring(0, 3);
String sfSpec = null;
if (tag.length() > 3) {
sfSpec = tag.substring(3);
}
// do all fields for this tag
for (VariableField vf : record.getVariableFields(dfTag)) {
// Assume tag represents a DataField
DataField df = (DataField) vf;
boolean callTypeMatch = false;
// Assume call type subfield could repeat
for (Subfield typeSf : df.getSubfields(callTypeSf)) {
if (callTypeSf.indexOf(typeSf.getCode()) != -1 && typeSf.getData().equals(callType)) {
callTypeMatch = true;
}
}
// take the first call number coded as Dewey
if (callTypeMatch) {
sortKey = new DeweyCallNumber(df.getSubfieldsAsString(sfSpec)).getShelfKey();
break;
}
} // end loop over variable fields
} // end loop over fieldSpec
return sortKey;
}
/** /**
* Normalize Dewey numbers for AlphaBrowse sorting purposes (use all numbers!) * Normalize Dewey numbers for AlphaBrowse sorting purposes (use all numbers!)
* *
* Can return null * Can return null
* *
* @param record * @param record current MARC record
* @param fieldSpec - which MARC fields / subfields need to be analyzed * @param fieldSpec which MARC fields / subfields need to be analyzed
* @return List containing normalized Dewey numbers extracted from specified fields. * @return List containing normalized Dewey numbers extracted from specified fields.
*/ */
public List getDeweySortables(Record record, String fieldSpec) { public List getDeweySortables(Record record, String fieldSpec) {
...@@ -130,7 +180,7 @@ public List getDeweySortables(Record record, String fieldSpec) { ...@@ -130,7 +180,7 @@ public List getDeweySortables(Record record, String fieldSpec) {
List result = new LinkedList(); List result = new LinkedList();
// Loop through the specified MARC fields: // Loop through the specified MARC fields:
Set input = indexer.getFieldList(record, fieldSpec); Set input = SolrIndexer.getFieldList(record, fieldSpec);
Iterator iter = input.iterator(); Iterator iter = input.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
// Get the current string to work on: // Get the current string to work on:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment