Bug 34857 - OPAC advanced search operator "not" is searching as "and" on chrome
Summary: OPAC advanced search operator "not" is searching as "and" on chrome
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Searching (show other bugs)
Version: Main
Hardware: All All
: P5 - low critical
Assignee: Andreas Jonsson
QA Contact: Katrin Fischer
URL:
Keywords:
: 35214 (view as bug list)
Depends on: 33233
Blocks:
  Show dependency treegraph
 
Reported: 2023-09-20 19:48 UTC by Laura Escamilla
Modified: 2024-07-04 20:40 UTC (History)
9 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
This fixes a regression (from bug 33233) when using a Chrome-based browser with AND, OR, and NOT in OPAC > Advanced search > More options. Using these operators with keywords should now work as expected.
Version(s) released in:
23.11.00,23.05.06,22.11.12
Circulation function:


Attachments
Bug 34857 Do not enable hidden select element (regression from bug 33233). (1.39 KB, patch)
2023-11-07 13:52 UTC, Andreas Jonsson
Details | Diff | Splinter Review
Bug 34857 Do not enable hidden select element (regression from bug 33233). (1.44 KB, patch)
2023-11-07 20:21 UTC, David Nind
Details | Diff | Splinter Review
Bug 34857 Do not enable hidden select element (regression from bug 33233). (1.49 KB, patch)
2023-11-07 21:14 UTC, Katrin Fischer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Laura Escamilla 2023-09-20 19:48:07 UTC
To recreate in ktd or sandboxes:
1. In the Koha OPAC go to Advanced search and choose "More options". 
2. Do a keyword search for "Doctor Who" with an operator of "Not" and a second keyword search of "video". Only 1 search result shows up. 
3. Go back to the advanced search using the back arrow (don't click on Advanced search again). 
4. Now search for "Doctor Who" with an operator of "And" and a second keyword search of "video". This shows 3 results. 
5. Go back again to advanced search using the back arrow. 
6. Try the "Not" video search again. The results show the 3 video results that appeared with the "And" operator. They do not show the 1 result that showed with the "Not" operator.
Comment 1 holly 2023-09-29 19:34:27 UTC
ALL OPAC advanced search operators are functioning as AND. 

1. Do a basic search with two KW terms using OR
2. Repeat the basic search using AND 
2. Do an advanced search with same terms in 2 fields using OR
Note advanced OR search gives same number of results as AND
Comment 2 jesus 2023-10-04 14:52:50 UTC
The search query varies according to the browser used. For Chrome (anonymous) and Firefox the result URL is correct. For Chrome standard it is not:

Started happening in 22.11, when this code in opac-advsearch.tt was introduced:

window.addEventListener('pageshow', function( e ){
    $('.form-control').prop('disabled' , false );
});

Result URL in Chrome
https://catalog.bywatersolutions.com/cgi-bin/koha/opac-search.pl?advsearch=1&op=AND&idx=kw&q=keyword1&op=NOT&idx=kw&q=keyword2&do=Search&sort_by=relevance

Result URL in Firefox and anonymous Chrome:

https://catalog.bywatersolutions.com/cgi-bin/koha/opac-search.pl?advsearch=1&idx=kw&q=keyword1&op=NOT&idx=kw&q=keyword2&do=Search&sort_by=relevance
Comment 3 Frédéric Demians 2023-10-05 15:35:55 UTC
It's not good at all :-)
Comment 4 Frédéric Demians 2023-10-05 15:44:55 UTC
The culprit is bug 33233. It should be reverted or amended.
Comment 5 jesus 2023-10-05 16:41:23 UTC
No back browser button involved in my proof of concept. Our programmer suggests it is a race condition on two different javascript codes.
Comment 6 Katrin Fischer 2023-10-29 09:38:39 UTC
The change on bug 33233 was quite small, any idea on how we could fix?

@@ -459,6 +459,9 @@
 [% BLOCK jsinclude %]
 [% Asset.js("lib/jquery/plugins/jquery.deserialize.min.js") | $raw %]
 <script>
+window.addEventListener('pageshow', function( e ){
+    $('.form-control').prop('disabled' , false );
+});
 $(document).ready(function() {
     [% IF search_groups %]
         function branch_limit() {
@@ -559,6 +562,5 @@ $(document).ready(function() {
         $(this).parent().parent().remove();
         $('.search-term-row .search-term-input select[name="op"]').first().prop("disabled",true).hide();
     });
-
 </script>
 [% END %]
Comment 7 Katrin Fischer 2023-11-01 15:30:02 UTC
*** Bug 35214 has been marked as a duplicate of this bug. ***
Comment 8 Christopher Brannon 2023-11-01 22:17:18 UTC
Just found this problem today.  On advanced search, keyword OR keyword works fine.  subject OR subject is run as subject AND subject (see the URL after running the search).  I can manually replace the AND with OR in the url and press enter and the search is run as expected.  Just can't do it with the dropdown on the previous page.
Comment 9 Andreas Jonsson 2023-11-07 13:28:43 UTC
I happened to notice the following difference:

Firefox:

>> $('.form-control').get(0).disabled
<- true

Chrome:

>> $('.form-control').get(0).disabled
<- false

If you run 

>> $('.form-control').get(0).disabled = true

in the console in chrome the search will work.

It looks like this is a hidden <select> which is used for copying the operator dropdown menu when adding additional search clauses.  It should be disabled.

The difference between browser is probably in execution order.

So, a fix is to change the code from bug 33233 to:

window.addEventListener('pageshow', function( e ){
    $('.form-control:visible').prop('disabled' , false );
});
Comment 10 Andreas Jonsson 2023-11-07 13:52:31 UTC
Created attachment 158598 [details] [review]
Bug 34857 Do not enable hidden select element (regression from bug 33233).

Test plan:

Using Chrome as web browser:

* Go to opac advanced search
* Press "more options"
* Search for two keywords using "and" operator (on ktd search for idea AND behind, which matches 1 result)
* Search for two keywords using "or" operator (on ktd search for idea OR behind, which matches 4 results)
* Search for two keywords using "not" operator (on ktd search for idea NOT behind, which matches 2 results)
Comment 11 David Nind 2023-11-07 20:21:30 UTC
Created attachment 158619 [details] [review]
Bug 34857 Do not enable hidden select element (regression from bug 33233).

Test plan:

Using Chrome as web browser:

* Go to opac advanced search
* Press "more options"
* Search for two keywords using "and" operator (on ktd search for idea AND behind, which matches 1 result)
* Search for two keywords using "or" operator (on ktd search for idea OR behind, which matches 4 results)
* Search for two keywords using "not" operator (on ktd search for idea NOT behind, which matches 2 results)

Signed-off-by: David Nind <david@davidnind.com>
Comment 12 Katrin Fischer 2023-11-07 21:14:49 UTC
Created attachment 158621 [details] [review]
Bug 34857 Do not enable hidden select element (regression from bug 33233).

Test plan:

Using Chrome as web browser:

* Go to opac advanced search
* Press "more options"
* Search for two keywords using "and" operator (on ktd search for idea AND behind, which matches 1 result)
* Search for two keywords using "or" operator (on ktd search for idea OR behind, which matches 4 results)
* Search for two keywords using "not" operator (on ktd search for idea NOT behind, which matches 2 results)

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 13 Katrin Fischer 2023-11-07 21:15:11 UTC
Thanks a lot Andreas, I am really happy to see this one fixed.
Comment 14 Tomás Cohen Arazi (tcohen) 2023-11-08 13:08:37 UTC
QA: the commit title fails the qa script tests.
Comment 15 Tomás Cohen Arazi (tcohen) 2023-11-08 14:42:51 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 16 Katrin Fischer 2023-11-08 16:06:02 UTC
I am sorry, I thought I had fixed that.
Comment 17 Christopher Brannon 2023-11-08 18:43:22 UTC
The title of this bug is misleading. It is not limited to Chrome.  I can reproduce in Firefox.
Comment 18 David Nind 2023-11-08 18:57:18 UTC
(In reply to Christopher Brannon from comment #17)
> The title of this bug is misleading. It is not limited to Chrome.  I can
> reproduce in Firefox.

I tested using Firefox Developer Edition (Firefox version 120.0b7) and Chromium (version 119.0.6045.105) (on Ubuntu 22.04) - I was not able to replicate the problem in Firefox. As far as I could see, it was specific to Chrome-based browsers. I'll have another go shortly and see if I can replicate the issue using Firefox.
Comment 19 Fridolin Somers 2023-11-10 20:42:05 UTC
Pushed to 23.05.x for 23.05.06
Comment 20 Pedro Amorim 2023-11-14 14:50:04 UTC
Nice work everyone!

Pushed to 22.11.x for next release
Comment 21 Christopher Brannon 2023-11-14 15:33:31 UTC
(In reply to Pedro Amorim from comment #20)
> Nice work everyone!
> 
> Pushed to 22.11.x for next release

Nice!  Thank you!