Bug 30641

Summary: Authority detail page shows wrong number of records using the authority
Product: Koha Reporter: Katrin Fischer <katrin.fischer>
Component: Searching - ElasticsearchAssignee: Bugs List <koha-bugs>
Status: Failed QA --- QA Contact:
Severity: normal    
Priority: P5 - low CC: david, m.de.rooy, magnus
Version: unspecified   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20615
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Attachments: Bug 30641: Quote authority id search

Description Katrin Fischer 2022-04-28 12:06:09 UTC
You can see the wrong behaviour in a clean sample database with http://localhost:8081/cgi-bin/koha/authorities/detail.pl?authid=133

To test:
* Test plan assumes you are using the ktd sample data
* Staff interface > authorities
* Search for agile
* Verfiy the result list shows used by 2 records and this is correct (authority is linked to both of them)
* Switch to authority detail page
* Verify it shows 3 records use this authority
* Verify this is incorrect (the second record is not linked to the authority)

I suspect that the detail page doesn't do an exact/phrase search opposed to the other pages, finding also records with similar authority numbers?
Comment 1 Katrin Fischer 2022-04-28 12:21:12 UTC
Ok, getting closer:

The number on results and detail page match and are correct if AutoQueryTruncate is deactivated.
Comment 2 Katrin Fischer 2022-04-28 12:22:17 UTC
And Elasticsearch is used.
Comment 3 Marcel de Rooy 2022-04-28 12:25:52 UTC
Cant directly reproduce this under Zebra.
I am inclined to think that it is related to Elastic search engine module.
Please confirm. Did you work under Elastic?

Would be nice if we just used ->get_usage_count doing something like simple_search_compat( 'an:' . $authid, 0, 0 )
The other call goes (under Zebra) via SearchAuthorities.
Comment 4 Katrin Fischer 2022-04-28 12:37:46 UTC
Hi Marcel, our investigation overlapped. The key factors are:

Searchengine Elasticsearch
AutoQueryTruncate ON (automatic truncation)
Comment 5 Katrin Fischer 2022-04-28 12:39:13 UTC
The problematic one is get_usage_count - I found this while testing bug 20615 that uses it and shows the wrong number. Not sure what the result page does different... but it probably should all end up using the same and working code.
Comment 6 Nick Clemens 2022-04-28 13:25:39 UTC
Created attachment 134260 [details] [review]
Bug 30641: Quote authority id search
Comment 7 Marcel de Rooy 2022-04-28 13:31:43 UTC
(In reply to Nick Clemens from comment #6)
> Created attachment 134260 [details] [review] [review]
> Bug 30641: Quote authority id search

Not sure if you should solve it here. Elastic ?
Comment 8 Marcel de Rooy 2022-04-28 13:32:08 UTC
(In reply to Katrin Fischer from comment #5)
> The problematic one is get_usage_count - I found this while testing bug
> 20615 that uses it and shows the wrong number. Not sure what the result page
> does different... but it probably should all end up using the same and
> working code.

No, it is just a wrapper to SearchEngine code.
Comment 9 Katrin Fischer 2022-04-28 13:35:57 UTC
Marcel, can you explain the issue?

We don't want to disable auto-truncate in general, so using "" like I think we have done in other places already makes sense to me.

Nick, there is another query in Authorities.pm with an an-based search, maybe we should also fix that one?
Comment 10 Katrin Fischer 2022-04-28 13:38:10 UTC
... and we'll probably need a unit test
Comment 11 Marcel de Rooy 2022-05-02 10:13:21 UTC
Looks like that Zebra has no problem with the an:"9" since it is a :w index in MARC21. In UNIMARC it is both :n and :w.
But Zebra does not need it; SimpleSearch does not add the asterisks for truncation. Apparently, Elastic does because QueryBuilder is adding asterisks.

Looks to me that this is actually a more general problem: Elastic's simple_search_compat is not 'simple' enough ;) The quotes are a workaround.

Note: We are forming queries like an:1 in more places in code.
Comment 12 Magnus Enger 2022-08-26 07:50:23 UTC
(In reply to Katrin Fischer from comment #10)
> ... and we'll probably need a unit test

Should this be "Failed QA" then?
Comment 13 Katrin Fischer 2022-08-28 15:19:28 UTC
(In reply to Magnus Enger from comment #12)
> (In reply to Katrin Fischer from comment #10)
> > ... and we'll probably need a unit test
> 
> Should this be "Failed QA" then?