Bugzilla – Attachment 39498 Details for
Bug 8571
Add search suggestions on the OPAC ("Did you mean?" feature)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 8571: Add search suggestions to search results on the OPAC.
Bug-8571-Add-search-suggestions-to-search-results-.patch (text/plain), 5.36 KB, created by
Mark Tompsett
on 2015-05-26 04:52:46 UTC
(
hide
)
Description:
Bug 8571: Add search suggestions to search results on the OPAC.
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2015-05-26 04:52:46 UTC
Size:
5.36 KB
patch
obsolete
>From 28e5a6d93a070844eaa2d01124a65d6e19238f73 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Fr=C3=A9d=C3=A9rick=20Capovilla?= <fcapovilla@live.ca> >Date: Tue, 26 May 2015 00:49:38 -0400 >Subject: [PATCH] Bug 8571: Add search suggestions to search results on the > OPAC. > >This patch will add search suggestions at the beginning of >search results on the OPAC if the "OPACSearchSuggestions" >preference is activated. This feature can be compared to >"Did you mean?" or autocorrect features in search engines. > >Authorities records are used as a source of suggestions. >The search terms the user entered are used in a "see also" >authority search to find suggestions. >--- > .../prog/en/modules/admin/preferences/opac.pref | 7 +++++ > .../bootstrap/en/modules/opac-results-grouped.tt | 9 ++++++ > .../opac-tmpl/bootstrap/en/modules/opac-results.tt | 8 ++++++ > opac/opac-search.pl | 32 ++++++++++++++++++++++ > 4 files changed, 56 insertions(+) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref >index c26d048..ca6aee2 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref >@@ -468,6 +468,13 @@ OPAC: > yes: Display > no: Don't display > - the acquisition details on OPAC detail pages. >+ - >+ - pref: OPACSearchSuggestions >+ choices: >+ yes: Show >+ no: "Don't show" >+ - search suggestions in the OPAC's search results page. Suggestions are found by searching for the search terms in the "see-from" of authority records. >+ > Policy: > - > - pref: singleBranchMode >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results-grouped.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results-grouped.tt >index 05d022a..a357d73 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results-grouped.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results-grouped.tt >@@ -27,6 +27,15 @@ href="/cgi-bin/koha/opac-rss.pl?[% query_cgi %][% limit_cgi |html %]" /> > </li> > </ul> > >+ [% IF ( suggestionsloop ) %] >+ <div class="suggestions"> >+ <span>Did you mean : </span> >+ [% FOREACH suggestionsloo IN suggestionsloop %] >+ <a href="/cgi-bin/koha/opac-search.pl?q=[% suggestionsloo.suggestionquery |url %]">[% suggestionsloo.suggestionterm %]</a> >+ [% END %] >+ </div> >+ [% END %] >+ > [% IF ( query_error ) %] > <div class="container-fluid"> > <div class="row-fluid"> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >index 27c5a10..375683e 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >@@ -114,6 +114,14 @@ > </div> > [% END %] > [% END %] >+ [% IF ( suggestionsloop ) %] >+ <div class="suggestions"> >+ <span>Did you mean : </span> >+ [% FOREACH suggestionsloo IN suggestionsloop %] >+ <a href="/cgi-bin/koha/opac-search.pl?q=[% suggestionsloo.suggestionquery |url %]">[% suggestionsloo.suggestionterm %]</a> >+ [% END %] >+ </div> >+ [% END %] > [% IF ( query_error ) %] > <div class="dialog alert"> > <h4>Error:</h4> >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index 0ff2507..7cce869 100755 >--- a/opac/opac-search.pl >+++ b/opac/opac-search.pl >@@ -918,6 +918,38 @@ if ($query_desc || $limit_desc) { > $template->param(searchdesc => 1); > } > >+# III. LOOK FOR SEARCH SUGGESTIONS IN AUTHORITIES >+ >+if (C4::Context->preference('OPACSearchSuggestions')) { >+ # Search for authorities that could better represent the search query >+ my @suggestions; >+ >+ # Set the index of all operands for Match-heading-see-from search >+ my @indexes_match; >+ foreach(@operands){push(@indexes_match, 'Match-heading-see-from,ext');} >+ >+ # Build the query and do a simple search with it >+ ($error, $query) = buildQuery(\@operators,\@operands,\@indexes_match,0,0,0,$lang); >+ my ($error2, $results, $total_hits) = SimpleSearch( $query, undef, undef, [ "authorityserver" ] ); >+ >+ # Add the main Heading of each search result and add it to the suggestion list >+ foreach my $r (@$results) >+ { >+ my $record = MARC::Record->new_from_usmarc( $r ); >+ my @subfields = ($record->field('1..'))[0]->subfields(); >+ >+ # Fuse the subfields >+ my $suggestionterm = ''; >+ foreach(@subfields){$suggestionterm .= $_->[1] . ', ';} >+ $suggestionterm =~ s/,\s+$//; >+ >+ my $suggestion = {'suggestionterm' => $suggestionterm, 'suggestionquery' => $suggestionterm}; >+ push(@suggestions, $suggestion); >+ } >+ >+ $template->param( 'suggestionsloop' => \@suggestions ); >+} >+ > # VI. BUILD THE TEMPLATE > # Build drop-down list for 'Add To:' menu... > my ($totalref, $pubshelves, $barshelves)= >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 8571
:
11348
| 39498