--- loncom/interface/lonsearchcat.pm 2001/03/22 14:03:55 1.70 +++ loncom/interface/lonsearchcat.pm 2001/03/27 20:33:40 1.87 @@ -229,9 +229,9 @@ LASTREVISIONDATEEND # ------------------------------------------- Compute customized metadata field $scrout.=< -LIMIT BY OTHER METADATA FIELDS: +LIMIT BY SPECIAL METADATA FIELDS: -For author-specific metadata, enter in an expression in the form of +For resource-specific metadata, enter in an expression in the form of key=value separated by operators such as AND or OR.
Example: grandmother=75 OR grandfather=85
@@ -239,6 +239,17 @@ CUSTOMMETADATA $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'}); $scrout.=' initial users of this system do not need to worry about this option'; + $scrout.=< +SHOW SPECIAL METADATA FIELDS: + +Enter in a space-separated list of special metadata fields to show +in a fielded listing for each record result. +
+CUSTOMSHOW +$scrout.=&simpletextfield('customshow',$ENV{'form.customshow'}); +$scrout.=' initial users of this system do not need to worry about this option'; + # ---------------------------------------------------------------- Print screen $r->print(< @@ -487,7 +498,7 @@ sub advancedsearch { 'lastrevisiondatestart_year','lastrevisiondateend_month', 'lastrevisiondateend_day','lastrevisiondateend_year', 'notes','abstract','mime','language','owner', - 'custommetadata') { + 'custommetadata','customshow') { $ENV{"form.$field"}=~s/[^\w\s\(\)\=\-\"\']//g; } for my $field ('title','author','subject','keywords','url','version', @@ -544,20 +555,38 @@ sub advancedsearch { elsif ($datequery) { push @queries,$datequery; } - my $customquery; + my $customquery=''; if ($ENV{'form.custommetadata'}) { $customquery=&build_custommetadata_query('custommetadata', $ENV{'form.custommetadata'}); } + my $customshow=''; + if ($ENV{'form.customshow'}) { + $customshow=$ENV{'form.customshow'}; + $customshow=~s/[^\w\s]//g; + my @fields=split(/\s+/,$customshow); + $customshow=join(" ",@fields); + } if (@queries) { $query=join(" AND ",@queries); $query="select * from metadata where $query"; - my $reply=&Apache::lonnet::metadata_query($query); + my $reply=''; + unless ($customquery or $customshow) { + $reply=&Apache::lonnet::metadata_query($query); + } + else { + $reply=&Apache::lonnet::metadata_query($query, + $customquery,$customshow); + } &output_results('Advanced',$r,$envhash,$customquery,$reply); } - else { - &output_results('Advanced',$r,$envhash,$query); + elsif ($customquery) { + my $reply=''; + $reply=&Apache::lonnet::metadata_query('', + $customquery,$customshow); + &output_results('Advanced',$r,$envhash,$customquery,$reply); } + $r->print(' '); # just in case.. hrrmm.. return OK; } @@ -659,7 +688,34 @@ sub output_results { @results=<$fh>; } + my $customshow=''; + my $extrashow=''; + my @customfields; + if ($ENV{'form.customshow'}) { + $customshow=$ENV{'form.customshow'}; + $customshow=~s/[^\w\s]//g; + my @fields=map {"$_:"} + split(/\s+/,$customshow); + my @customfields=split(/\s+/,$customshow); + if ($customshow) { + $extrashow="
  • ".join("
  • ",@fields)."
\n"; + } + } + my $customdata=''; + my %customhash; foreach my $result (@results) { + if ($result=~/^(custom\=.*)$/) { # grab all custom metadata + my $tmp=$result; + $tmp=~s/^custom\=//; + my ($k,$v)=map {&Apache::lonnet::unescape($_); + } split(/\,/,$tmp); + $customhash{$k}=$v; + } + } + foreach my $result (@results) { + next if $result=~/^custom\=/; + chomp $result; + next unless $result; my @fields=map {&Apache::lonnet::unescape($_)} (split(/\,/,$result)); @@ -669,6 +725,16 @@ sub output_results { my $shortabstract=$abstract; $shortabstract=substr($abstract,0,200) if length($abstract)>200; $fields[7]=$shortabstract; + my $extrashow2=$extrashow; + if ($extrashow) { + foreach my $field (@customfields) { + my $value=''; + if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) { + my $value=$1; + } + $extrashow2=~s/\<\!\-\- $field \-\-\>/$value/g; + } + } $compiledresult.=< END @@ -690,17 +756,20 @@ END if ($viewselect eq 'Detailed Citation View') { $compiledresult.=&detailed_citation_view(@fields, - $hostname,$httphost); + $hostname,$httphost, + $extrashow2); } elsif ($viewselect eq 'Summary View') { - $compiledresult.=&summary_view(@fields,$hostname,$httphost); + $compiledresult.=&summary_view(@fields,$hostname,$httphost, + $extrashow2); } elsif ($viewselect eq 'Fielded Format') { $compiledresult.=&fielded_format_view(@fields,$hostname, - $httphost); + $httphost,$extrashow2); } elsif ($viewselect eq 'XML/SGML') { - $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost); + $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost, + $extrashow2); } } @@ -741,6 +810,7 @@ SCRIPT

Search Catalog

+$customdata $closebutton @@ -793,7 +863,9 @@ sub build_custommetadata_query { $q->prepare($logic_statement); my $matchexp=${$q}{'-parse'}{'-build'}{'matchstring'}; # quick fix to change literal into xml tag-matching - $matchexp=~s/\(\?\:([^\)]*)\\\=([^\)]*)\)/\(\?\:\<$1\>\[\^\\\<\]\*$2\[\^\\\<\]\*\<\/$1\>)/g; + # will eventually have to write a separate builder module + my $oldmatchexp=$matchexp; + $matchexp=~s/(\w+)\\\=(\w+)/\\\<$1\\\>\[\^\\\<\]\*$2\[\^\\\<\]\*\\\<\\\/$1\\\>/g; return $matchexp; } @@ -831,7 +903,7 @@ sub detailed_citation_view { my ($title,$author,$subject,$url,$keywords,$version, $notes,$shortabstract,$mime,$lang, $creationdate,$lastrevisiondate,$owner,$copyright, - $hostname,$httphost)=@_; + $hostname,$httphost,$extrashow)=@_; my $result=<$owner, last revised $lastrevisiondate

$title

@@ -844,6 +916,9 @@ sub detailed_citation_view { MIME Type: $mimetag{$mime}
Language: $language{$lang}
Copyright/Distribution: $cprtag{$copyright}
+

+$extrashow +

$shortabstract

END @@ -855,12 +930,13 @@ sub summary_view { my ($title,$author,$subject,$url,$keywords,$version, $notes,$shortabstract,$mime,$lang, $creationdate,$lastrevisiondate,$owner,$copyright, - $hostname,$httphost)=@_; + $hostname,$httphost,$extrashow)=@_; my $result=<$author
$title
$owner -- $lastrevisiondate
$cprtag{$copyright}
+$extrashow

END return $result; @@ -871,7 +947,7 @@ sub fielded_format_view { my ($title,$author,$subject,$url,$keywords,$version, $notes,$shortabstract,$mime,$lang, $creationdate,$lastrevisiondate,$owner,$copyright, - $hostname,$httphost)=@_; + $hostname,$httphost,$extrashow)=@_; my $result=<URL: $url
@@ -888,6 +964,7 @@ sub fielded_format_view { Copyright/Distribution: $cprtag{$copyright}
Repository Location: $hostname
Abstract: $shortabstract
+$extrashow

END return $result; @@ -898,7 +975,7 @@ sub xml_sgml_view { my ($title,$author,$subject,$url,$keywords,$version, $notes,$shortabstract,$mime,$lang, $creationdate,$lastrevisiondate,$owner,$copyright, - $hostname,$httphost)=@_; + $hostname,$httphost,$extrashow)=@_; my $result=< <LonCapaResource> @@ -927,6 +1004,7 @@ sub xml_sgml_view { <shortabstract>$shortabstract</shortabstract> </LonCapaResource> +$extrashow END return $result; }