Bug 3154

Summary: OPAC Search refining by facets is wrong
Product: Koha Reporter: Frédéric Demians <f.demians>
Component: OPACAssignee: Henri-Damien LAURENT <henridamien>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: PATCH-Sent (DO NOT USE) CC: chris, cmurdock, dpavlin, fridolin.somers, julian.maurice, jwagner, m.de.rooy, nengard, smoreland
Version: Main   
Hardware: All   
OS: All   
See Also: http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=2614
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Proposed patch (based on render method)
Patch
Alternative patch with new preference
Patch for functionality
Install patch
Install patch (revised)
Patch for functionality (updated)
Install patch (updated)

Description Chris Cormack 2010-05-21 01:07:06 UTC


---- Reported by frederic@tamil.fr 2009-04-24 03:56:03 ----

OPAC facets are now generated based on current page biblio records not
the whole result set. For example, if your search found 1000 records,
on the first page, facets are created based on biblio record 1 to 20.

Facets SHOULD be generated using Zebra facets functionnalties:

  http://www.indexdata.dk/zebra/doc/special-retrieval.tkl



---- Additional Comments From joe.atzberger@liblime.com 2009-04-27 18:45:30 ----

Using the zebra facets is correct, but in the case of author or series, going based on the hits currently displayed (i.e. highest relevance) is perfectly reasonable to me.   You don't need or want 1000 author facets on the first page.



---- Additional Comments From frederic@tamil.fr 2009-05-05 08:02:21 ----

> Using the zebra facets is correct, but in the case of author or series, going
> based on the hits currently displayed (i.e. highest relevance) is perfectly
> reasonable to me.   You don't need or want 1000 author facets on the first
> page.

Thanks for you comment.

As you know, this is done this way in Worldcat which is Koha OPAC model:

http://www.worldcat.org/search?q=author

1000 author facets are not generated but the five first authors ordered 
by their relative weight to the resultset. That's all what facets are 
about. Display layer (Koha) can't do that; Zebra can or is supposed to 
be able to do that.

The way facets are displayed now is very disturbing for multi-branches
library. 'Site' facets won't show libraries which haven't biblio
records on the first page even if they have books on following
pages. Now, in this situation, a patron can conclude that their isn't
any book at all matching his request and stop searching if he wants
to refine his search to a specific library.



--- Bug imported by chris@bigballofwax.co.nz 2010-05-21 01:07 UTC  ---

This bug was previously known as _bug_ 3154 at http://bugs.koha.org/cgi-bin/bugzilla3/show_bug.cgi?id=3154

Actual time not defined. Setting to 0.0
CC member arm@hanover.ca does not have an account here
CC member joe.atzberger@liblime.com does not have an account here
CC member jwagner@ptfs.com does not have an account here
CC member nicolas.morin@biblibre.com does not have an account here
CC member scook@hartford.edu does not have an account here

Comment 1 Fridolin Somers 2010-06-04 13:21:24 UTC
(In reply to comment #0)

Hie, I'm currently working with 3.2 alpha 2 version.

I also think it is a problem.

It can be somehow solved by editing C4/Search.pm line 418 :
change : for ( my $j = $offset ; $j < $times ; $j++ ) {
to :     for ( my $j = 0 ; $j < $size ; $j++ ) {
 
A problem remains : ordering facets with decreasing occurrences order.
Comment 2 Frédéric Demians 2010-06-04 14:15:10 UTC
> It can be somehow solved by editing C4/Search.pm line 418 :
> change : for ( my $j = $offset ; $j < $times ; $j++ ) {
> to :     for ( my $j = 0 ; $j < $size ; $j++ ) {

Just somehow. With your solution performance will collapse for large result set. Facet generation must be delegated to the indexing engine which has all the information about terms facets based on resultset and indexes. There is no other efficient solution. 

A la revoyure Fridolyn !
Comment 3 Fridolin Somers 2010-10-21 08:01:46 UTC
Hie,

I have worked on a half-solution to increase facets performance in order to use more than 20 results in facets.

I first used 500 results for facets : runtime takes 10 seconds.

Looking into Search.pm, I found that creating the MARC::Record object was taking most of the time :
  $facet_record = MARC::Record->new_from_usmarc($record)

This method creates a MARC::Record from a ZOOM::Record (returned from Zebra). It populates all fields and subfields. But we only need a few of them for facets.
I had to avoid this method.

I noticed that a ZOOM::Record can be returned in 2 forms : 
  - record.raw() that is a ISO2709
  - record.render() that is a more user-friendly

I used then the render form to directly extract facet datas (thanks to Perl regular expressions).

Its a real gain of performance : runtime falls at 0,5 second.
Despite this performance, I left the limit to the 500 first records.
Maybe it should be a system pref.

Second change : 
The number next facet data (facet_count) is the number of occurrences of this value.
I changed to this behavior : this number is the number of records that contains the facet. So that when choosing this facet, this number matches the new number of search results.

Hope it can help.
I'm open to any comment or modification.

ZOOM::Record doc:
http://search.cpan.org/~mirk/Net-Z3950-ZOOM/lib/ZOOM.pod#ZOOM::Record
Comment 4 Fridolin Somers 2010-10-21 08:03:16 UTC Comment hidden (obsolete)
Comment 5 Frédéric Demians 2010-12-01 21:41:12 UTC
http://lists.koha-community.org/pipermail/koha-patches/2010-December/013142.html

=>

I can confirm that Fridolyn trick is efficient and quick but:

  - Facets count are still wrong. The count are better (ie bigger) but still
    wrong as soon as result set is larger than examined set used to build
    facets.
  - Libraries facet remains misleading. If a biblio record contains a 'foo'
    library but is at the end of the resultset, 'foo' Library isn't displayed.
    A patron can conclude that the ressource he's not available at his library.
  - It reports a huge charge load on Zebra server which has to return a LOT of
    records to build facets. It should be tested with simultaneous requests in
    order to see if it impacts Zebra overall performances.
Comment 6 Fridolin Somers 2010-12-02 08:42:09 UTC
(In reply to comment #5)
> http://lists.koha-community.org/pipermail/koha-patches/2010-December/013142.html
> 
> =>
> 
> I can confirm that Fridolyn trick is efficient and quick but:
> 
>   - Facets count are still wrong. The count are better (ie bigger) but still
>     wrong as soon as result set is larger than examined set used to build
>     facets.
>   - Libraries facet remains misleading. If a biblio record contains a 'foo'
>     library but is at the end of the resultset, 'foo' Library isn't displayed.
>     A patron can conclude that the ressource he's not available at his library.
>   - It reports a huge charge load on Zebra server which has to return a LOT of
>     records to build facets. It should be tested with simultaneous requests in
>     order to see if it impacts Zebra overall performances.

Thanks for feedback.

Indeed, increasing the number of records Zebra must return adds an overload to server.

Can we imagine in a first time to include the patch but without increasing the number of records : not 500 but the number of records in a page ?
I will increase the performance of existing code.

Regards,
Comment 7 Chris Cormack 2010-12-02 23:38:05 UTC
New patches sent by Frederic, awaiting signoff
Comment 8 Frédéric Demians 2010-12-03 06:02:37 UTC
Someone else, familiar with C4::Search, should take a look at Fridolyn
Patch. IMHO this patch isn't a complete solution but is already an
improvement and doesn't break anything.
Comment 9 MJ Ray (software.coop) 2010-12-10 10:22:56 UTC
This bug is mentioned in:
Bug 3154 : Facets performance http://lists.koha-community.org/pipermail/koha-patches/2010-November/013100.html
Bug 3154: Improving facets perfomance http://lists.koha-community.org/pipermail/koha-patches/2010-November/013101.html
Comment 10 MJ Ray (software.coop) 2011-01-06 10:18:03 UTC
This bug is mentioned in:
Bug 3154: Improving facets perfomance http://lists.koha-community.org/pipermail/koha-patches/2010-December/013141.html
Comment 11 Marcel de Rooy 2011-01-31 12:20:40 UTC Comment hidden (obsolete)
Comment 12 Chris Cormack 2011-02-16 21:43:00 UTC
Pushed to new/bug_3154

I have some worries about the load this places on zebra, can we get some more testing done on it, before I merge it into master
Comment 13 Marcel de Rooy 2011-02-17 11:10:15 UTC
(In reply to comment #12)
> I have some worries about the load this places on zebra, can we get some more
> testing done on it, before I merge it into master

I would prefer to make this functionality parameter-driven, as was suggested earlier, via a preference (number of records for building facets).
A default of 20 would mimic current behavior.
I would not merge it in its current state because the 500 is hardcoded and could affect performance substantially in larger catalogs with large result sets.
Comment 14 Fridolin Somers 2011-02-21 07:28:22 UTC
(In reply to comment #13)
Hie,

I totally agree, a system pref is perfect to choose the limit depending on the server's performance.

But I never add a system pref, it includes many modifications I've seen (update script, database structure in many languages, ...).

Could someone manage this?
I'm also quite busy at staff.

Regards,
Comment 15 Nicole C. Engard 2011-02-21 17:14:40 UTC
I have a question about what the sys pref would control. Will is control the showing of the numbers next to the facets? Or will it control the showing of all possible facets on the first page of results?  If both then I'd ask for two prefs instead of one to control both. I don't mind giving up the numbers (personally) but I always thought that the facets were showing me facets for all of the results (and was kind of disappointed to find out that the facets are in fact inaccurate).
Comment 16 Frédéric Demians 2011-02-21 18:14:32 UTC
(In reply to comment #15)
> I have a question about what the sys pref would control. Will is control the
> showing of the numbers next to the facets? Or will it control the showing of
> all possible facets on the first page of results?  If both then I'd ask for two
> prefs instead of one to control both. I don't mind giving up the numbers
> (personally) but I always thought that the facets were showing me facets for
> all of the results (and was kind of disappointed to find out that the facets
> are in fact inaccurate).

I propose:

FacetFirstBiblios: to fix the number of biblio records used to find facets and count.

FacetHideCount: to hide numbers next to the facets.

And someone who isn't busy has to do it :-)
Comment 17 Marcel de Rooy 2011-02-24 10:29:34 UTC
(In reply to comment #16)
> FacetHideCount: to hide numbers next to the facets.

Do not completely understand that one. I checked the git log on opac facets template. And discovered that at creation time of opac-facets.inc, the facet count was already commented and thus invisible.
See commit: f8e9fb6445dadbdef91e13a253c9c6bcb75e0eec

I can understand why the number was made invisible. As long as it does not refer to the complete result set, it is quite irrelevant.

Based on the work of Fridolyn and Frederic latest patch with a default of 50, I have attached a patch with a new preference maxRecordsForFacets. My default would be 20 to mimic current behavior.
Comment 18 Marcel de Rooy 2011-02-24 10:33:38 UTC Comment hidden (obsolete)
Comment 19 Frédéric Demians 2011-02-25 07:30:37 UTC
(In reply to comment #17)
> (In reply to comment #16)
> > FacetHideCount: to hide numbers next to the facets.
> 
> Do not completely understand that one. I checked the git log on opac
> facets template. And discovered that at creation time of
> opac-facets.inc, the facet
> count was already commented and thus invisible.
> See commit: f8e9fb6445dadbdef91e13a253c9c6bcb75e0eec
> 
> I can understand why the number was made invisible. As long as it does
> not refer to the complete result set, it is quite irrelevant.

That's why a syspref may be useful in order to let the library choose
whether or not a count is displayed next to each facet. If you choose via
the first syspref to find your facets on the 1000 first records of a
resultset, it may be considered as relevant to display a count.
Comment 20 Marcel de Rooy 2011-02-28 11:34:16 UTC Comment hidden (obsolete)
Comment 21 Marcel de Rooy 2011-02-28 11:35:57 UTC Comment hidden (obsolete)
Comment 22 Marcel de Rooy 2011-02-28 11:36:13 UTC
(In reply to comment #19)
> That's why a syspref may be useful in order to let the library choose
> whether or not a count is displayed next to each facet. If you choose via
> the first syspref to find your facets on the 1000 first records of a
> resultset, it may be considered as relevant to display a count.

OK. I am convinced. Sending two patches this time. The first patch contains functionality including second pref displayFacetCount. The second patch only contains install stuff.

Could one of you please test and sign?
Comment 23 Marcel de Rooy 2011-02-28 12:09:22 UTC Comment hidden (obsolete)
Comment 24 Fridolin Somers 2011-03-01 08:38:59 UTC
(In reply to comment #23)
> Created attachment 3224 [details] [review]
> Install patch (revised)
> 
> Installation issues (small revision)

Tanks a lot for your help.

Regards,
Comment 26 Marcel de Rooy 2011-03-17 09:33:43 UTC
Created attachment 3332 [details] [review]
Patch for functionality (updated)
Comment 27 Marcel de Rooy 2011-03-17 09:54:44 UTC
Created attachment 3334 [details] [review]
Install patch (updated)
Comment 28 Chris Cormack 2011-03-22 07:57:37 UTC
Pushed, please test
Comment 29 MJ Ray (software.coop) 2011-04-07 10:50:34 UTC
This bug is mentioned in:
Bug 3154: Preferences for	building facets http://lists.koha-community.org/pipermail/koha-patches/2011-March/014267.html
Bug 3154: Preferences for	building facets http://lists.koha-community.org/pipermail/koha-patches/2011-March/014268.html