[LON-CAPA-cvs] cvs: loncom /interface lonsearchcat.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Fri, 07 May 2004 18:50:14 -0000
This is a MIME encoded message
--matthew1083955814
Content-Type: text/plain
matthew Fri May 7 14:50:14 2004 EDT
Modified files:
/loncom/interface lonsearchcat.pm
Log:
Bug 1030: Multiple words search always fails.
Now split whitespace separated words apart. Quoted items are handled properly.
Added &process_phrase_input to do this.
Simplified &related_version since it gets more regular inputs now.
Modified &parse_basic_search and &parse_advanced_search to use this new
method.
Added breadcrumbs to search results output.
Corrected misspelling of 'Correct' in &detailed_citation_view.
--matthew1083955814
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20040507145014.txt"
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.223 loncom/interface/lonsearchcat.pm:1.224
--- loncom/interface/lonsearchcat.pm:1.223 Wed May 5 13:29:06 2004
+++ loncom/interface/lonsearchcat.pm Fri May 7 14:50:14 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.223 2004/05/05 17:29:06 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.224 2004/05/07 18:50:14 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1248,8 +1248,8 @@
my $font = '<font color="#800000" face="helvetica">';
# Evaluate logical expression AND/OR/NOT phrase fields.
foreach my $field (@BasicFields) {
- if ($ENV{'form.'.$field}) {
- my $searchphrase = $ENV{'form.'.$field};
+ next if (!defined($ENV{'form.'.$field}) || $ENV{'form.'.$field} eq '');
+ foreach my $searchphrase(&process_phrase_input($ENV{'form.'.$field})){
$pretty_search_string .= $font."$field</font> contains <b>".
$searchphrase."</b>";
if ($ENV{'form.'.$field.'_related'}) {
@@ -1263,7 +1263,7 @@
}
}
$pretty_search_string .= "<br />\n";
- push @queries,&build_SQL_query($field,$searchphrase);
+ push @queries,&build_SQL_query($field,$searchphrase);
}
}
#
@@ -1400,7 +1400,7 @@
$pretty_search_string .= $pretty_domains_string."<br />\n";
#
if (@queries) {
- $query="select * from metadata where ".join(" AND ",@queries);
+ $query="SELET * FROM metadata WHERE ".join(" AND ",@queries);
} elsif ($customquery) {
$query = '';
}
@@ -1484,34 +1484,70 @@
&output_blank_field_error($r,$closebutton,'phase=disp_basic');
return OK;
}
- my $pretty_search_string = '<b>'.$ENV{'form.basicexp'}.'</b>';
- if ($ENV{'form.related'}) {
- my @New_Words;
- ($search_string,@New_Words) = &related_version($ENV{'form.basicexp'});
- if (@New_Words) {
- $pretty_search_string .= " with related words: <b>@New_Words</b>.";
- } else {
- $pretty_search_string .= " with no related words.";
+ my $pretty_search_string='';
+ my @Queries;
+ my $concatarg=join(',',
+ ('title', 'author', 'subject', 'notes', 'abstract',
+ 'keywords'));
+ foreach my $search (&process_phrase_input($search_string)){
+ $pretty_search_string .= '<br />'.'<b>'.$search.'</b>';
+ if ($ENV{'form.related'}) {
+ my @New_Words;
+ ($search,@New_Words) = &related_version($search);
+ next if (! $search);
+ if (@New_Words) {
+ $pretty_search_string .=
+ " with related words: <b>@New_Words</b>";
+ }
}
+ #
+ # Build SQL query string based on form page
+ push(@Queries,
+ &build_SQL_query('concat_ws(" ",'.$concatarg.')',$search));
}
+ my $final_query = 'SELECT * FROM metadata WHERE '.join(" AND ",@Queries);
#
- # Build SQL query string based on form page
- my $query='';
- my $concatarg=join(',',
- ('title', 'author', 'subject', 'notes', 'abstract',
- 'keywords'));
- $concatarg='title' if $ENV{'form.titleonly'};
- $query=&build_SQL_query('concat_ws(" ",'.$concatarg.')',$search_string);
if (defined($pretty_domains_string) && $pretty_domains_string ne '') {
$pretty_search_string .= ' '.$pretty_domains_string;
}
$pretty_search_string .= "<br />\n";
- my $final_query = 'SELECT * FROM metadata WHERE '.$query;
- # &Apache::lonnet::logthis($final_query);
+ $pretty_search_string =~ s:^<br />::;
+# &Apache::lonnet::logthis($final_query);
return ($final_query,$pretty_search_string,
$libraries_to_query);
}
+sub process_phrase_input {
+ my ($phrase)=@_;
+ my @Phrases;
+ # &Apache::lonnet::logthis('phrase = :'.$phrase.':');
+ my $in_quotes = 0;
+ my @Words = split(/\s+/,$phrase);
+ foreach my $word (@Words) {
+ $word =~ s/(\w+)\"(\w+)/$1$2/g;
+ if ($in_quotes) {
+ if ($word =~ s/(\")$//) {
+ $in_quotes = 0;
+ }
+ if ($Phrases[-1] ne '') {
+ $Phrases[-1] .= ' ';
+ }
+ $Phrases[-1] .= $word;
+ } else {
+ if ($word =~ s/^(\")//) {
+ $in_quotes=1;
+ }
+ push(@Phrases,$word);
+ }
+ }
+ #
+ #foreach my $p (@Phrases) {
+ # &Apache::lonnet::logthis(' subphrase = '.$p);
+ #}
+ #
+ return @Phrases;
+}
+
######################################################################
######################################################################
@@ -1530,19 +1566,13 @@
######################################################################
######################################################################
sub related_version {
- my $search_string = shift;
- my $result = $search_string;
- my %New_Words = ();
- while ($search_string =~ /(\w+)/cg) {
- my $word = $1;
- next if (lc($word) =~ /\b(or|and|not)\b/);
- my @Words = &Apache::loncommon::get_related_words($word);
- @Words = ($#Words>4? @Words[0..4] : @Words);
- foreach (@Words) { $New_Words{$_}++;}
- my $replacement = join " OR ", ($word,@Words);
- $result =~ s/(\b)$word(\b)/$1($replacement)$2/g;
- }
- return $result,sort(keys(%New_Words));
+ my ($word) = @_;
+ return (undef) if (lc($word) =~ /\b(or|and|not)\b/);
+ my @Words = &Apache::loncommon::get_related_words($word);
+ # Only use 4 related words
+ @Words = ($#Words>4? @Words[0..4] : @Words);
+ my $result = join " OR ", ($word,@Words);
+ return $result,sort(@Words);
}
######################################################################
@@ -1566,7 +1596,9 @@
-build => 'Text::Query::Build');
$q->prepare($logic_statement);
my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
+ &Apache::lonnet::logthis('matchexp = '.$matchexp);
my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
+ &Apache::lonnet::logthis('sql_query = '.$sql_query);
return $sql_query;
}
@@ -1836,7 +1868,11 @@
######################################################################
sub print_sort_form {
my ($r,$pretty_query_string) = @_;
- my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
+ my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1).
+ &Apache::lonhtmlcommon::breadcrumbs
+ (undef,'Searching','Searching',undef,undef,
+ ! ($ENV{'form.catalogmode'} eq 'groupsearch'));
+
##
my %SortableFields=&Apache::lonlocal::texthash(
id => 'Default',
@@ -2102,6 +2138,10 @@
sub run_search {
my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_;
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
+ $bodytag.=
+ &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Searching',
+ undef,undef,! $ENV{'form.launch'});
+
my $connection = $r->connection;
#
# Print run_search header
@@ -2285,13 +2325,13 @@
# results to get, so let the client know the top frame needs to be
# loaded from /adm/searchcat
$r->print("</body></html>");
- if ($ENV{'form.catalogmode'} ne 'groupsearch') {
+# if ($ENV{'form.catalogmode'} ne 'groupsearch') {
$r->print("<script>".
"window.location='/adm/searchcat?".
"phase=sort&".
"persistent_db_id=$ENV{'form.persistent_db_id'}';".
"</script>");
- }
+# }
return;
}
@@ -2811,6 +2851,41 @@
######################################################################
######################################################################
+sub has_stat_data {
+ my ($values) = @_;
+ if ( (defined($values->{'count'}) && $values->{'count'} ne '') ||
+ (defined($values->{'stdno'}) && $values->{'stdno'} ne '') ||
+ (defined($values->{'disc'}) && $values->{'disc'} ne '') ||
+ (defined($values->{'avetries'}) && $values->{'avetries'} ne '') ||
+ (defined($values->{'difficulty'}) && $values->{'difficulty'} ne '')) {
+ return 1;
+ }
+ return 0;
+}
+
+sub statfields {
+ return ('count','stdno','disc','avetries','difficulty');
+}
+
+sub has_eval_data {
+ my ($values) = @_;
+ if ( (defined($values->{'clear'}) && $values->{'clear'} ne '') ||
+ (defined($values->{'technical'}) && $values->{'technical'} ne '') ||
+ (defined($values->{'correct'}) && $values->{'correct'} ne '') ||
+ (defined($values->{'helpful'}) && $values->{'helpful'} ne '') ||
+ (defined($values->{'depth'}) && $values->{'depth'} ne '')) {
+ return 1;
+ }
+ return 0;
+}
+
+sub evalfields {
+ return ('clear','technical','correct','helpful','depth');
+}
+
+######################################################################
+######################################################################
+
=pod
=item Metadata Viewing Functions
@@ -2874,7 +2949,7 @@
{ name=>'helpful',
translate => '<b>Helpful:</b> [_1]',},
{ name=>'correct',
- translate => '<b>Correcy:</b> [_1]',},
+ translate => '<b>Correct:</b> [_1]',},
{ name=>'technical',
translate => '<b>Technical:</b> [_1]',},
) {
@@ -2903,41 +2978,6 @@
}
$result .= '<hr align="left" width="200" noshade />'."\n";
return $result;
-}
-
-######################################################################
-######################################################################
-
-sub has_stat_data {
- my ($values) = @_;
- if ( (defined($values->{'count'}) && $values->{'count'} ne '') ||
- (defined($values->{'stdno'}) && $values->{'stdno'} ne '') ||
- (defined($values->{'disc'}) && $values->{'disc'} ne '') ||
- (defined($values->{'avetries'}) && $values->{'avetries'} ne '') ||
- (defined($values->{'difficulty'}) && $values->{'difficulty'} ne '')) {
- return 1;
- }
- return 0;
-}
-
-sub statfields {
- return ('count','stdno','disc','avetries','difficulty');
-}
-
-sub has_eval_data {
- my ($values) = @_;
- if ( (defined($values->{'clear'}) && $values->{'clear'} ne '') ||
- (defined($values->{'technical'}) && $values->{'technical'} ne '') ||
- (defined($values->{'correct'}) && $values->{'correct'} ne '') ||
- (defined($values->{'helpful'}) && $values->{'helpful'} ne '') ||
- (defined($values->{'depth'}) && $values->{'depth'} ne '')) {
- return 1;
- }
- return 0;
-}
-
-sub evalfields {
- return ('clear','technical','correct','helpful','depth');
}
######################################################################
--matthew1083955814--