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

Progress on VUFIND-701 (Dewey AlphaBrowse skips records w/ multiple call numbers)

Some edge cases won't be fixed until next SolrMarc upgrade (need List support)
parent f2bb1dc0
Branches
Tags
No related merge requests found
......@@ -15,8 +15,8 @@ import org.solrmarc.tools.CallNumUtils;
*
* @param record
* @param fieldSpec - which MARC fields / subfields need to be analyzed
* @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,
* @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,
* 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
*/
......@@ -24,23 +24,23 @@ public Set getDeweyNumber(Record record, String fieldSpec, String precisionStr)
// Initialize our return value:
Set result = new LinkedHashSet();
// Precision comes in as a string, but we need to convert it to a float:
// Precision comes in as a string, but we need to convert it to a float:
float precision = Float.parseFloat(precisionStr);
// Loop through the specified MARC fields:
Set input = indexer.getFieldList(record, fieldSpec);
Iterator iter = input.iterator();
while (iter.hasNext()) {
// Get the current string to work on:
String current = iter.next();
if (CallNumUtils.isValidDewey(current)) {
// Convert the numeric portion of the call number into a float:
float currentVal = Float.parseFloat(CallNumUtils.getDeweyB4Cutter(current));
// Round the call number value to the specified precision:
Float finalVal = new Float(Math.floor(currentVal / precision) * precision);
// Convert the rounded value back to a string (with leading zeros) and save it:
result.add(CallNumUtils.normalizeFloat(finalVal.toString(), 3, -1));
}
......@@ -71,14 +71,14 @@ public Set getDeweySearchable(Record record, String fieldSpec) {
while (iter.hasNext()) {
// Get the current string to work on:
String current = iter.next();
// Add valid strings to the set, normalizing them to be all uppercase
// and free from whitespace.
if (CallNumUtils.isValidDewey(current)) {
result.add(current.toUpperCase().replaceAll(" ", ""));
}
}
// If we found no call numbers, return null; otherwise, return our results:
if (result.isEmpty())
return null;
......@@ -108,7 +108,39 @@ public String getDeweySortable(Record record, String fieldSpec) {
return CallNumUtils.getDeweyShelfKey(current);
}
}
// If we made it this far, we didn't find a valid sortable Dewey number:
return null;
}
/**
* Normalize Dewey numbers for AlphaBrowse sorting purposes (use all numbers!)
*
* Can return null
*
* @param record
* @param fieldSpec - which MARC fields / subfields need to be analyzed
* @return Set containing normalized Dewey numbers extracted from specified fields.
*/
public Set getDeweySortables(Record record, String fieldSpec) {
// Initialize our return value:
Set result = new LinkedHashSet();
// Loop through the specified MARC fields:
Set input = indexer.getFieldList(record, fieldSpec);
Iterator iter = input.iterator();
while (iter.hasNext()) {
// Get the current string to work on:
String current = iter.next();
// If this is a valid Dewey number, return the sortable shelf key:
if (CallNumUtils.isValidDewey(current)) {
result.add(CallNumUtils.getDeweyShelfKey(current));
}
}
// If we found no call numbers, return null; otherwise, return our results:
if (result.isEmpty())
return null;
return result;
}
\ No newline at end of file
......@@ -76,7 +76,8 @@ dewey-tens = custom, getDeweyNumber(082a:083a, 10), ddc22_map.properties(tens)
dewey-ones = custom, getDeweyNumber(082a:083a, 1), ddc22_map.properties(ones)
dewey-full = custom, getDeweySearchable(082a:083a)
dewey-sort = custom, getDeweySortable(082a:083a)
dewey-raw = 082a:083a, first
dewey-sort-browse = script(dewey.bsh), getDeweySortables(082a:083a)
dewey-raw = 082a:083a
# Extract the numeric portion of the OCLC number using a pattern map:
oclc_num = 035a, (pattern_map.oclc_num)
......
......@@ -64,7 +64,7 @@ call %VUFIND_HOME%\index-alphabetic-browse.bat build_browse title title_fullStr
call %VUFIND_HOME%\index-alphabetic-browse.bat build_browse topic topic_browse
call %VUFIND_HOME%\index-alphabetic-browse.bat build_browse author author_browse
call %VUFIND_HOME%\index-alphabetic-browse.bat build_browse lcc callnumber-a 1
call %VUFIND_HOME%\index-alphabetic-browse.bat build_browse dewey dewey-raw 1 "-Dbibleech=StoredFieldLeech -Dsortfield=dewey-sort -Dvaluefield=dewey-raw"
call %VUFIND_HOME%\index-alphabetic-browse.bat build_browse dewey dewey-raw 1 "-Dbibleech=StoredFieldLeech -Dsortfield=dewey-sort-browse -Dvaluefield=dewey-raw"
goto end
rem Function to process a single browse index:
......
......@@ -39,4 +39,4 @@ build_browse "title" "title_fullStr" 1 "-Dbibleech=StoredFieldLeech -Dsortfield=
build_browse "topic" "topic_browse"
build_browse "author" "author_browse"
build_browse "lcc" "callnumber-a" 1
build_browse "dewey" "dewey-raw" 1 "-Dbibleech=StoredFieldLeech -Dsortfield=dewey-sort -Dvaluefield=dewey-raw"
build_browse "dewey" "dewey-raw" 1 "-Dbibleech=StoredFieldLeech -Dsortfield=dewey-sort-browse -Dvaluefield=dewey-raw"
......@@ -73,4 +73,25 @@ class SolrTest extends \VuFindTest\Unit\TestCase
$this->assertTrue(empty($item['seeAlso']));
$this->assertTrue(in_array('Royal Dublin Society', $item['useInstead']));
}
/**
* Check that expected Dewey values are present (tests VUFIND-701).
*
* @return void
*/
public function testDeweyValues()
{
$solr = $this->getServiceManager()->get('VuFind\Search\BackendManager')
->get('Solr');
$result = $solr->alphabeticBrowse('dewey', '123.45 .I39', 0, 1);
$item = $result['Browse']['items'][0];
$this->assertEquals(1, $item['count']);
$this->assertEquals($item['count'], count($item['ids']));
$this->assertEquals('123.45 .I39', $item['heading']);
$result = $solr->alphabeticBrowse('dewey', '123.46 .Q39', 0, 1);
$item = $result['Browse']['items'][0];
$this->assertEquals(1, $item['count']);
$this->assertEquals($item['count'], count($item['ids']));
$this->assertEquals('123.46 .Q39', $item['heading']);
}
}
\ No newline at end of file
......@@ -154,7 +154,8 @@
<field name="dewey-ones" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="dewey-full" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="dewey-sort" type="string" indexed="true" stored="true" />
<field name="dewey-raw" type="string" indexed="true" stored="true" />
<field name="dewey-sort-browse" type="string" indexed="true" stored="true" multiValued="true" />
<field name="dewey-raw" type="string" indexed="true" stored="true" multiValued="true" />
<field name="author2" type="textProper" indexed="true" stored="true" multiValued="true"/>
<field name="author2Str" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="author2-role" type="string" indexed="true" stored="true" multiValued="true"/>
......
00613cam a2200229Ma 4500001001600000005001700016008004100033020001500074035002300089040002500112041001800137043001200155050002400167049000900191082001600200082001600216100003000232245002200262250002300284260004700307300002900354testdeweybrowse20110419140028.0110214s1992 it a b 001 0 ita d a8820737493 a(OCoLC)ocm30585539 aRBNcRBNdOCLCGdPVU1 aitaalathlat ae-it---14aDG848.15b.V53 1992 aPVUM a123.45 .I39 a123.46 .Q391 aPerson, Fake,d1668-1744.10aDewey browse test aFictional edition. aMorano :bCentro di Studi Vichiani,c1992. a296 p. :bill. ;c24 cm.
\ No newline at end of file
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