Bug 29048 - Incorrect search for linked authority records from authority search result list in OPAC
Summary: Incorrect search for linked authority records from authority search result li...
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Searching - Elasticsearch (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal (vote)
Assignee: Katrin Fischer
QA Contact: Martin Renvoize
URL:
Keywords:
Depends on: 30740
Blocks:
  Show dependency treegraph
 
Reported: 2021-09-17 13:28 UTC by Vitor Fernandes
Modified: 2023-12-28 20:42 UTC (History)
6 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.11.00, 22.05.08


Attachments
Bug 29048: Fix link to linked records from authority search results in OPAC (2.32 KB, patch)
2022-02-27 00:17 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 29048: Fix link to linked records from authority search results in OPAC (2.33 KB, patch)
2022-05-13 07:32 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 29048: Fix link to linked records from authority search results in OPAC (2.38 KB, patch)
2022-09-14 21:26 UTC, David Nind
Details | Diff | Splinter Review
Bug 29048: Fix link to linked records from authority search results in OPAC (2.44 KB, patch)
2022-10-07 10:09 UTC, Martin Renvoize
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Vitor Fernandes 2021-09-17 13:28:45 UTC
The related records link in the authorities search results searches for "an=authid", which returns all records with an started with authid (after clicking the link). This causes a difference between the number of related records and the number of records retrieved in the search (using Elasticsearch).

The link should change from:

q=an=[% resul.authid | uri %]

To:

q=[% resul.authid | uri %]&idx=an,phr

in the following line:

https://github.com/Koha-Community/Koha/blob/master/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-authoritiessearchresultlist.tt#L110

Test plan:

- Create 10 authority with similar values
- Relate some record with authority 1
- Relate some record with authority 10
- Search authorities (authority 1 should have 1 related record)
- Click the related records link
- You should get 2 related records
Comment 1 Katrin Fischer 2022-02-26 23:57:20 UTC
It looks like this is only an issue with Elasticsearch - Zebra seems to be have fine. I guess there is some automatic truncation going on here?

You can test this easily with: an:3 and an,phr:3 in ktd and notice the difference in result lists. 

The authority detail page already uses the ,phr, so making them consistent seems like a good idea for a quick fix, but maybe we want to dig a little deeper to fully understand the difference in behavior here?
Comment 2 Katrin Fischer 2022-02-27 00:17:00 UTC Comment hidden (obsolete)
Comment 3 Katrin Fischer 2022-05-13 07:32:56 UTC
Created attachment 134946 [details] [review]
Bug 29048: Fix link to linked records from authority search results in OPAC

Without this patch the constructed search link would give wrong
results with Elasticsearch. If you searched for records linked
to authority id 3 it would also turn up all other records linked
to an authority where the id started with 3...

This just copies the more specific link using an,phr used in the
staff interface and the OPAC detail page to make things consistent

To test:
- Turn on Elasticsearch
- Search for authorities in the OPAC
- Locate a authority with a low ID in your result list
- Note the number of linked records
- Click on the link
- It will give you more results than it said before
- Verify results don't match your search
- Apply patch
- Try again - now it should all match up
Comment 4 Katrin Fischer 2022-05-13 07:33:20 UTC
Rebased on top of bug 30740
Comment 5 Fridolin Somers 2022-05-13 08:24:32 UTC
We should always use "an:XXX" but with bug 24143

This is the behavior of Zebra.
And this syntax is used in facets for example.
Comment 6 Katrin Fischer 2022-05-13 08:27:46 UTC
Sorry, Frido, I forgot to save the change I had made (it was my intention to fix exactly that in the rebase).
Comment 7 Fridolin Somers 2022-05-13 08:28:40 UTC
(In reply to Fridolin Somers from comment #5)
> We should always use "an:XXX" but with bug 24143
I mean Bug 26608
Comment 8 Fridolin Somers 2022-05-13 08:31:03 UTC
(In reply to Katrin Fischer from comment #6)
> Sorry, Frido, I forgot to save the change I had made (it was my intention to
> fix exactly that in the rebase).

Ah if adding phr works cool.
We also need to change in staff interface then.
Arf and XSLT is full of 'q=an:XXXX'
Comment 9 Katrin Fischer 2022-05-13 08:34:48 UTC
I just made them 'the same', so fixing the inconsistency here. But I believe it's just a trick maybe to 'deactivate' QueryAutoTruncate?

See: bug 30641
Comment 10 David Nind 2022-09-14 21:26:56 UTC
Created attachment 140642 [details] [review]
Bug 29048: Fix link to linked records from authority search results in OPAC

Without this patch the constructed search link would give wrong
results with Elasticsearch. If you searched for records linked
to authority id 3 it would also turn up all other records linked
to an authority where the id started with 3...

This just copies the more specific link using an,phr used in the
staff interface and the OPAC detail page to make things consistent

To test:
- Turn on Elasticsearch
- Search for authorities in the OPAC
- Locate a authority with a low ID in your result list
- Note the number of linked records
- Click on the link
- It will give you more results than it said before
- Verify results don't match your search
- Apply patch
- Try again - now it should all match up

Signed-off-by: David Nind <david@davidnind.com>
Comment 11 David Nind 2022-09-14 21:31:06 UTC
I've tested and signed off (using KTD and the sample data).

This on the assumption that it fixes the actual URL link in the records column (X record) on the OPAC authority search results listing page by changing it from &q=an:3 to &q=an,phr:3.

Apologies if I have misunderstood what this is fixing!

Testing notes
-------------

1. Both before and after patch: searching for Ritchie (authid=3) shows "1 record" in the records column in the authority search results listing page.

2. Link for '1 record' in the records column in the authority search results page BEFORE the patch is applied: http://127.0.0.1:8080/cgi-bin/koha/opac-search.pl?type=opac&op=do_search&q=an:3

3. Link for '1 record' in the records column in the authority search results page AFTER the patch is applied: http://127.0.0.1:8080/cgi-bin/koha/opac-search.pl?type=opac&op=do_search&q=an,phr:3

4. Both before and after the patch is applied: in the details page for the authority record it shows "Number of records used in: 44"

5. Both before and after the patch is applied: if I click the link in the authority search results listing page, I get 44 search results.

6. For all the above (1-5) QueryAutoTruncate was set to "automatically".

7. If QueryAutoTruncate is set to "only if * is added.", then the number of results displays as expected: 1. (I also linked the authority to another record, and this displayed as expected with 2 records.)

8. Bugs that will fix other issues:
   . Bug 26608 - Authorities: linked biblios is inconsistent using elasticsearch and QueryAutoTruncate
   . Bug 30641 - Authority detail page shows wrong number of records using the authority
Comment 12 Martin Renvoize 2022-10-07 10:09:27 UTC
Created attachment 141486 [details] [review]
Bug 29048: Fix link to linked records from authority search results in OPAC

Without this patch the constructed search link would give wrong
results with Elasticsearch. If you searched for records linked
to authority id 3 it would also turn up all other records linked
to an authority where the id started with 3...

This just copies the more specific link using an,phr used in the
staff interface and the OPAC detail page to make things consistent

To test:
- Turn on Elasticsearch
- Search for authorities in the OPAC
- Locate a authority with a low ID in your result list
- Note the number of linked records
- Click on the link
- It will give you more results than it said before
- Verify results don't match your search
- Apply patch
- Try again - now it should all match up

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 13 Martin Renvoize 2022-10-07 10:09:51 UTC
Nice consistency improvement, trivial fix.

Passing QA
Comment 14 Tomás Cohen Arazi 2022-10-11 14:21:17 UTC
Pushed to master for 22.11.

Nice work everyone, thanks!
Comment 15 Lucas Gass 2022-12-05 18:24:34 UTC
Backported to 22.05.x for upcoming 22.05.08
Comment 16 Bernard 2022-12-08 15:04:34 UTC
I have found this problem also affects the equivalent intranet search. I was able to fix it by changing line 61 of /usr/share/koha/intranet/htdocs/intranet-tmpl/prog/en-GB/modules/authorities/details.tt and add the ,phr

<a href="/cgi-bin/koha/catalogue/search.pl?type=intranet&amp;op=do_search&amp;q=an,phr=[% authid | uri %]">[% count | html %] record(s)</a>

Does this need adding to this patch?
Comment 17 Bernard 2022-12-08 15:35:31 UTC
CORRECTION: My patch was wrong. Instead, we surround the authority number with &quot; to force phrase search:

 Used in <a href="/cgi-bin/koha/catalogue/search.pl?type=intranet&amp;op=do_search&amp;q=an=&quot;[% authid | uri %]&quot;">[% count | html %] record(s)</a>
Comment 18 Arthur Suzuki 2022-12-14 14:35:59 UTC
depends on 30740, not present in 21.11.
Won't backport.