Permalink
Browse files

more experimental work on grouping with pazpar2

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
  • Loading branch information...
1 parent 3cb4ea7 commit 35249f48e457e726d687c254f1bcb5e663e28770 Galen Charlton committed with Joshua Ferraro Feb 11, 2008
Showing with 263 additions and 18 deletions.
  1. +16 −13 C4/Search.pm
  2. +65 −0 etc/pazpar2/MARC21slimUtils.xsl
  3. +1 −1 etc/pazpar2/koha-biblios.xml
  4. +173 −0 etc/pazpar2/marc21-work-groups.xsl
  5. +2 −2 etc/pazpar2/pazpar2.xml
  6. +6 −2 opac/opac-search.pl
View
@@ -623,6 +623,7 @@ sub pazGetRecords {
my $paz = C4::Search::PazPar2->new('http://localhost:10006/search.pz2');
$paz->init();
+ #die $simple_query;
$paz->search($simple_query);
sleep 1;
@@ -635,6 +636,7 @@ sub pazGetRecords {
HIT: foreach my $hit (@{ $results->{'hit'} }) {
warn "hit";
my $recid = $hit->{recid}->[0];
+ my $work_title = $hit->{'md-work-title'}->[0];
#if ($recid =~ /[\200-\377]/) {
if ($recid =~ /sodot/) {
#die "bad $recid\n";
@@ -650,7 +652,7 @@ sub pazGetRecords {
warn "look for $recid offset = $i";
my $rec = $paz->record($recid, $i);
warn "got record $i";
- push @{ $results_hashref->{'biblioserver'}->{'RECORDS'} }, $paz->record($recid, $i);
+ push @{ $results_hashref->{'biblioserver'}->{$work_title}->{'RECORDS'} }, $paz->record($recid, $i);
}
}
warn "past hits";
@@ -659,18 +661,19 @@ sub pazGetRecords {
my $termlist_xml = $paz->termlist('author,subject');
my $terms = XMLin($termlist_xml, forcearray => 1);
my @facets_loop = ();
- foreach my $list (sort keys %{ $terms->{'list'} }) {
- my @facets = ();
- foreach my $facet (sort @{ $terms->{'list'}->{$list}->{'term'} } ) {
- push @facets, {
- facet_label_value => $facet->{'name'}->[0],
- };
- }
- push @facets_loop, ( {
- type_label => $list,
- facets => \@facets,
- } );
- }
+ #die Dumper($results);
+# foreach my $list (sort keys %{ $terms->{'list'} }) {
+# my @facets = ();
+# foreach my $facet (sort @{ $terms->{'list'}->{$list}->{'term'} } ) {
+# push @facets, {
+# facet_label_value => $facet->{'name'}->[0],
+# };
+# }
+# push @facets_loop, ( {
+# type_label => $list,
+# facets => \@facets,
+# } );
+# }
return ( undef, $results_hashref, \@facets_loop );
}
@@ -0,0 +1,65 @@
+<?xml version='1.0'?>
+<xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:template name="datafield">
+ <xsl:param name="tag"/>
+ <xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
+ <xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
+ <xsl:param name="subfields"/>
+ <xsl:element name="datafield">
+ <xsl:attribute name="tag">
+ <xsl:value-of select="$tag"/>
+ </xsl:attribute>
+ <xsl:attribute name="ind1">
+ <xsl:value-of select="$ind1"/>
+ </xsl:attribute>
+ <xsl:attribute name="ind2">
+ <xsl:value-of select="$ind2"/>
+ </xsl:attribute>
+ <xsl:copy-of select="$subfields"/>
+ </xsl:element>
+ </xsl:template>
+
+ <xsl:template name="subfieldSelect">
+ <xsl:param name="codes"/>
+ <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
+ <xsl:variable name="str">
+ <xsl:for-each select="marc:subfield">
+ <xsl:if test="contains($codes, @code)">
+ <xsl:value-of select="text()"/><xsl:value-of select="$delimeter"/>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
+ </xsl:template>
+
+ <xsl:template name="buildSpaces">
+ <xsl:param name="spaces"/>
+ <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
+ <xsl:if test="$spaces>0">
+ <xsl:value-of select="$char"/>
+ <xsl:call-template name="buildSpaces">
+ <xsl:with-param name="spaces" select="$spaces - 1"/>
+ <xsl:with-param name="char" select="$char"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="chopPunctuation">
+ <xsl:param name="chopString"/>
+ <xsl:variable name="length" select="string-length($chopString)"/>
+ <xsl:choose>
+ <xsl:when test="$length=0"/>
+ <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
+ <xsl:call-template name="chopPunctuation">
+ <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="not($chopString)"/>
+ <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+</xsl:stylesheet><!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
+<metaInformation>
+<scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
+</metaInformation>
+-->
@@ -25,6 +25,6 @@
<!-- Result normalization settings -->
<set name="pz:nativesyntax" value="iso2709"/>
- <set name="pz:xslt" value="marc21.xsl"/>
+ <set name="pz:xslt" value="marc21-work-groups.xsl"/>
</settings>
@@ -0,0 +1,173 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- $Id: marc21.xsl,v 1.22 2007-10-04 12:01:15 adam Exp $ -->
+<xsl:stylesheet
+ version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:pz="http://www.indexdata.com/pazpar2/1.0"
+ xmlns:marc="http://www.loc.gov/MARC21/slim">
+
+
+ <xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
+
+<!-- Extract metadata from MARC21/USMARC
+ http://www.loc.gov/marc/bibliographic/ecbdhome.html
+-->
+ <xsl:include href="MARC21slimUtils.xsl" />
+ <xsl:include href="pz2-ourl-marc21.xsl" />
+
+ <xsl:template match="/marc:record">
+ <xsl:variable name="title_medium" select="marc:datafield[@tag='245']/marc:subfield[@code='h']"/>
+ <xsl:variable name="journal_title" select="marc:datafield[@tag='773']/marc:subfield[@code='t']"/>
+ <xsl:variable name="electronic_location_url" select="marc:datafield[@tag='856']/marc:subfield[@code='u']"/>
+ <xsl:variable name="medium">
+ <xsl:choose>
+ <xsl:when test="$title_medium">
+ <xsl:value-of select="substring-after(substring-before($title_medium,']'),'[')"/>
+ </xsl:when>
+ <xsl:when test="$electronic_location_url">
+ <xsl:text>electronic resource</xsl:text>
+ </xsl:when>
+ <xsl:when test="$journal_title">
+ <xsl:text>article</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>book</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="uniform_title_key">
+ <xsl:choose>
+ <xsl:when test="marc:datafield[@tag='130']">
+ <xsl:for-each select="marc:datafield[@tag='130']">
+ <xsl:call-template name="subfieldSelect">
+ <xsl:with-param name="codes">adfgkmnoprs</xsl:with-param>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:when>
+ <xsl:when test="marc:datafield[@tag='240']">
+ <xsl:for-each select="marc:datafield[@tag='240']">
+ <xsl:call-template name="subfieldSelect">
+ <xsl:with-param name="codes">adfgkmnoprs</xsl:with-param>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="title_key">
+ <xsl:for-each select="marc:datafield[@tag='245']">
+ <xsl:call-template name="subfieldSelect">
+ <xsl:with-param name="codes">abnp</xsl:with-param>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <xsl:variable name="work_title">
+ <xsl:choose>
+ <xsl:when test="$uniform_title_key != ''">
+ <xsl:value-of select="$uniform_title_key" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$title_key" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="non_ut_main_entry_key">
+ <xsl:choose>
+ <xsl:when test="marc:datafield[@tag='100']">
+ <xsl:for-each select="marc:datafield[@tag='100']">
+ <xsl:call-template name="subfieldSelect">
+ <xsl:with-param name="codes">abcd</xsl:with-param>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="mergekey">
+ <xsl:text>titlekey </xsl:text>
+ <xsl:value-of select="$work_title" />
+ <xsl:if test="$non_ut_main_entry_key != ''">
+ <xsl:text> namemainentry </xsl:text>
+ <xsl:value-of select="$non_ut_main_entry_key" />
+ </xsl:if>
+ </xsl:variable>
+
+ <pz:record>
+ <xsl:attribute name="mergekey">
+ <xsl:value-of select="$mergekey"/>
+ </xsl:attribute>
+
+ <xsl:for-each select="marc:datafield[@tag='999']">
+ <pz:metadata type="kohaid">
+ <xsl:value-of select="marc:subfield[@code='c']"/>
+ </pz:metadata>
+ </xsl:for-each>
+
+<!--
+ <xsl:for-each select="marc:datafield[@tag='020']">
+ <pz:metadata type="isbn">
+ <xsl:value-of select="marc:subfield[@code='a']"/>
+ </pz:metadata>
+ </xsl:for-each>
+-->
+
+ <xsl:for-each select="marc:datafield[@tag='245']">
+ <pz:metadata type="work-title">
+ <xsl:value-of select="$work_title" />
+ </pz:metadata>
+ </xsl:for-each>
+
+<!--
+ <xsl:for-each select="marc:datafield[@tag='250']">
+ <pz:metadata type="edition">
+ <xsl:value-of select="marc:subfield[@code='a']"/>
+ </pz:metadata>
+ </xsl:for-each>
+
+ <xsl:for-each select="marc:datafield[@tag='260']">
+ <pz:metadata type="publication-place">
+ <xsl:value-of select="marc:subfield[@code='a']"/>
+ </pz:metadata>
+ <pz:metadata type="publication-name">
+ <xsl:value-of select="marc:subfield[@code='b']"/>
+ </pz:metadata>
+ <pz:metadata type="publication-date">
+ <xsl:value-of select="marc:subfield[@code='c']"/>
+ </pz:metadata>
+ </xsl:for-each>
+-->
+
+<!--
+ <xsl:for-each select="marc:datafield[@tag='300']">
+ <pz:metadata type="physical-extent">
+ <xsl:value-of select="marc:subfield[@code='a']"/>
+ </pz:metadata>
+ <pz:metadata type="physical-format">
+ <xsl:value-of select="marc:subfield[@code='b']"/>
+ </pz:metadata>
+ <pz:metadata type="physical-dimensions">
+ <xsl:value-of select="marc:subfield[@code='c']"/>
+ </pz:metadata>
+ <pz:metadata type="physical-accomp">
+ <xsl:value-of select="marc:subfield[@code='e']"/>
+ </pz:metadata>
+ <pz:metadata type="physical-unittype">
+ <xsl:value-of select="marc:subfield[@code='f']"/>
+ </pz:metadata>
+ <pz:metadata type="physical-unitsize">
+ <xsl:value-of select="marc:subfield[@code='g']"/>
+ </pz:metadata>
+ <pz:metadata type="physical-specified">
+ <xsl:value-of select="marc:subfield[@code='3']"/>
+ </pz:metadata>
+ </xsl:for-each>
+-->
+
+ </pz:record>
+
+ </xsl:template>
+
+</xsl:stylesheet>
View
@@ -37,7 +37,7 @@
<!-- we try to keep same order as in marc21.xsl -->
<metadata name="id"/>
<metadata name="lccn" merge="unique"/>
- <metadata name="kohaid" merge="unique" brief="yes" />
+ <metadata name="kohaid" />
<metadata name="isbn"/>
<metadata name="issn"/>
<metadata name="tech-rep-nr"/>
@@ -52,7 +52,7 @@
<metadata name="meeting-date"/>
<metadata name="date" brief="yes" sortkey="numeric" type="year"
merge="range" termlist="yes"/>
- <metadata name="title" brief="yes" sortkey="skiparticle"
+ <metadata name="work-title" brief="yes" sortkey="skiparticle"
merge="longest" rank="6"/>
<metadata name="title-remainder" brief="yes" merge="longest" rank="5"/>
<metadata name="title-responsibility" brief="yes" />
View
@@ -306,7 +306,7 @@ ($)
};
} else {
eval {
- ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
+ ($error, $results_hashref, $facets) = C4::Search::pazGetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
};
}
if ($@ || $error) {
@@ -323,7 +323,11 @@ ($)
if ($server =~/biblioserver/) { # this is the local bibliographic server
$hits = $results_hashref->{$server}->{"hits"};
my $page = $cgi->param('page') || 0;
- my @newresults = searchResults( $query_desc,$hits,$results_per_page,$offset,@{$results_hashref->{$server}->{"RECORDS"}});
+ my @newresults;
+ for my $work_title (keys %{ $results_hashref->{$server} }) {
+ next if $work_title eq "hits";
+ push @newresults, searchResults( $query_desc,$hits,$results_per_page,$offset,@{$results_hashref->{$server}->{$work_title}->{"RECORDS"}});
+ }
$total = $total + $results_hashref->{$server}->{"hits"};
if ($hits) {
$template->param(total => $hits);

0 comments on commit 35249f4

Please sign in to comment.