Bug 27546 - Add option to search within results on the staff interface
Summary: Add option to search within results on the staff interface
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Searching (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Nick Clemens
QA Contact: Testopia
URL:
Keywords:
Depends on: 22605
Blocks: 33093
  Show dependency treegraph
 
Reported: 2021-01-25 14:52 UTC by Nick Clemens
Modified: 2023-12-28 20:43 UTC (History)
10 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: ---
Documentation contact: Caroline Cyr La Rose
Documentation submission: https://gitlab.com/koha-community/koha-manual/-/merge_requests/679
Text to go in the release notes:
This enhancement adds a new input above the search results allowing one to search within the results. The search box will take a query and add it as a limit to the previous search.
Version(s) released in:
22.11.00


Attachments
Bug 27546: Add 'Search within results' search box (4.90 KB, patch)
2021-01-25 14:58 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 27546: Add 'Search within results' search box (4.97 KB, patch)
2021-02-09 00:11 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 27546: Add 'Search within results' search box (4.99 KB, patch)
2021-03-29 13:48 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 27546: Add 'Search within results' search box (5.02 KB, patch)
2021-03-30 20:55 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
Bug 27546: Add 'Search within results' search box (5.03 KB, patch)
2021-08-12 15:44 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 27546: Add 'Search within results' search box (5.25 KB, patch)
2022-03-16 10:29 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 27546: (follow-up) Escape new search string (1.23 KB, patch)
2022-04-26 10:57 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 27546: (follow-up) Avoid index clash (2.41 KB, patch)
2022-05-06 12:40 UTC, Nick Clemens
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Clemens 2021-01-25 14:52:11 UTC
This enhancement will add a new box above the search results allowing one to search within the previous search results
Comment 1 Nick Clemens 2021-01-25 14:58:28 UTC
Created attachment 115779 [details] [review]
Bug 27546: Add 'Search within results' search box

This enhancement adds a new input above the search results allowing one to search within the results. The search
box will take a query and add it as a limit to the previous search

These patches make a slight change to the search header, passing the dropdown selection as a parameter rather thandirectly.

Searching this way is functionally equivaled to adding 'AND' with the new term to original results.

To test:
1 - Apply patch
2 - Search on staff client wiht a term that returns results
3 - Note the new 'Search within results box'
4 - Add a search term
5 - Note new results and confirm they are as expected
6 - Enable IntranetCatalogSearchPulldown and confirm the dropdown works as expected
7 - Edit your search - the reinfements appear in the limits section and can be removed
Comment 2 Sally 2021-01-27 13:05:12 UTC
I get the following error when I try to apply this to a sandbox:

Applying: Bug 27546: Add 'Search within results' search box
error: sha1 information is lacking or useless (catalogue/search.pl).
error: could not build fake ancestor
Patch failed at 0001 Bug 27546: Add 'Search within results' search box
Comment 3 Nick Clemens 2021-01-27 13:26:56 UTC
(In reply to Sally from comment #2)
> I get the following error when I try to apply this to a sandbox:
> 
> Applying: Bug 27546: Add 'Search within results' search box
> error: sha1 information is lacking or useless (catalogue/search.pl).
> error: could not build fake ancestor
> Patch failed at 0001 Bug 27546: Add 'Search within results' search box

Apologies, there is a dependency, bug 22605
Comment 4 PTFS Europe Sandboxes 2021-02-09 00:11:40 UTC
Created attachment 116533 [details] [review]
Bug 27546: Add 'Search within results' search box

This enhancement adds a new input above the search results allowing one to search within the results. The search
box will take a query and add it as a limit to the previous search

These patches make a slight change to the search header, passing the dropdown selection as a parameter rather thandirectly.

Searching this way is functionally equivaled to adding 'AND' with the new term to original results.

To test:
1 - Apply patch
2 - Search on staff client wiht a term that returns results
3 - Note the new 'Search within results box'
4 - Add a search term
5 - Note new results and confirm they are as expected
6 - Enable IntranetCatalogSearchPulldown and confirm the dropdown works as expected
7 - Edit your search - the reinfements appear in the limits section and can be removed

Signed-off-by: Barbara Johnson <barbara.johnson@bedfordtx.gov>
Comment 5 Barbara Johnson 2021-02-09 00:12:39 UTC
This worked great.
Comment 6 Victor Grousset/tuxayo 2021-03-27 21:37:55 UTC
error: sha1 information is lacking or useless (koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt).
error: could not build fake ancestor
Patch failed at 0001 Bug 27546: Add 'Search within results' search box
hint: Use 'git am --show-current-patch=diff' to see the failed patch

Tried to QA, code looks good.
Comment 7 Nick Clemens 2021-03-29 13:48:38 UTC
Created attachment 118958 [details] [review]
Bug 27546: Add 'Search within results' search box

This enhancement adds a new input above the search results allowing one to search within the results. The search
box will take a query and add it as a limit to the previous search

These patches make a slight change to the search header, passing the dropdown selection as a parameter rather thandirectly.

Searching this way is functionally equivaled to adding 'AND' with the new term to original results.

To test:
1 - Apply patch
2 - Search on staff client wiht a term that returns results
3 - Note the new 'Search within results box'
4 - Add a search term
5 - Note new results and confirm they are as expected
6 - Enable IntranetCatalogSearchPulldown and confirm the dropdown works as expected
7 - Edit your search - the reinfements appear in the limits section and can be removed

Signed-off-by: Barbara Johnson <barbara.johnson@bedfordtx.gov>
Comment 8 Nick Clemens 2021-03-29 13:49:08 UTC
(In reply to Victor Grousset/tuxayo from comment #6)
> error: sha1 information is lacking or useless
> (koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt).
> error: could not build fake ancestor
> Patch failed at 0001 Bug 27546: Add 'Search within results' search box
> hint: Use 'git am --show-current-patch=diff' to see the failed patch
> 
> Tried to QA, code looks good.

Did you apply the dependency? It auto merged for me, attached a new patch
Comment 9 Victor Grousset/tuxayo 2021-03-29 16:36:30 UTC
> Did you apply the dependency?

Yes, followed git-bz suggestion.

Thanks, it applies now :)
Comment 10 Victor Grousset/tuxayo 2021-03-29 16:51:27 UTC
First test looks good :)

Is that expected that "edit search" only edits the main part and not the merge with the "within" part?
Comment 11 Nick Clemens 2021-03-29 18:45:16 UTC
(In reply to Victor Grousset/tuxayo from comment #10)
> First test looks good :)
> 
> Is that expected that "edit search" only edits the main part and not the
> merge with the "within" part?

I believe they show up under the 'limits' secion, nearer the bottom of the form/
Comment 12 Victor Grousset/tuxayo 2021-03-29 20:10:53 UTC
> I believe they show up under the 'limits' secion, nearer the bottom of the
> form/

Indeed! Thanks
Comment 13 Victor Grousset/tuxayo 2021-03-29 20:21:08 UTC
When emptying the "Search within results" field and clicking on search, it still searches with the previous limit value.

I guess that's an issue?



When doing a search, then using the within two times:
search "book" => within "guide" => within "rome"
I have a final search like this:
2 result(s) found for 'kw,wrdl: book' with limit(s): 'guide rome'. 

That seems what should happen right? I though it would replace the first within but chaining them seems valid and better even :)
(though I don't have the right PoV about how this should be used)
Comment 14 Victor Grousset/tuxayo 2021-03-29 20:27:48 UTC
Wait, the first thing happens because of the second. i.e. chaining means that emptying the field will chain the empty string.

Is that needed to easily "unrefine" the search? Like to fix a typo or something too specific. There is always the back button of the browser.
Comment 15 Nick Clemens 2021-03-30 14:49:54 UTC
(In reply to Victor Grousset/tuxayo from comment #14)
> Wait, the first thing happens because of the second. i.e. chaining means
> that emptying the field will chain the empty string.
> 
> Is that needed to easily "unrefine" the search? Like to fix a typo or
> something too specific. There is always the back button of the browser.

Leaving the 'Search within' blank and pressing search should not change anything - it will not clear previous refinements, that is done via 'Edit this search'

Future enhancement could be to list the limits and allow for unchecking on the results page, but I do not think that is necessary for this stage
Comment 16 Victor Grousset/tuxayo 2021-03-30 20:55:55 UTC
Created attachment 119025 [details] [review]
Bug 27546: Add 'Search within results' search box

This enhancement adds a new input above the search results allowing one to search within the results. The search
box will take a query and add it as a limit to the previous search

These patches make a slight change to the search header, passing the dropdown selection as a parameter rather thandirectly.

Searching this way is functionally equivaled to adding 'AND' with the new term to original results.

To test:
1 - Apply patch
2 - Search on staff client wiht a term that returns results
3 - Note the new 'Search within results box'
4 - Add a search term
5 - Note new results and confirm they are as expected
6 - Enable IntranetCatalogSearchPulldown and confirm the dropdown works as expected
7 - Edit your search - the reinfements appear in the limits section and can be removed

Signed-off-by: Barbara Johnson <barbara.johnson@bedfordtx.gov>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 17 Victor Grousset/tuxayo 2021-03-30 20:59:41 UTC
ok, current behavior looks good for me.

Code ok, QA script ok, it works.

Will retest and pass QA when the dep (bug 22605) will be passed QA
Comment 18 Katrin Fischer 2021-04-03 14:15:28 UTC
Blocked by failed dependency
Comment 19 Nick Clemens 2021-08-12 15:44:33 UTC
Created attachment 123817 [details] [review]
Bug 27546: Add 'Search within results' search box

This enhancement adds a new input above the search results allowing one to search within the results. The search
box will take a query and add it as a limit to the previous search

These patches make a slight change to the search header, passing the dropdown selection as a parameter rather thandirectly.

Searching this way is functionally equivaled to adding 'AND' with the new term to original results.

To test:
1 - Apply patch
2 - Search on staff client wiht a term that returns results
3 - Note the new 'Search within results box'
4 - Add a search term
5 - Note new results and confirm they are as expected
6 - Enable IntranetCatalogSearchPulldown and confirm the dropdown works as expected
7 - Edit your search - the reinfements appear in the limits section and can be removed

Signed-off-by: Barbara Johnson <barbara.johnson@bedfordtx.gov>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 20 Nick Clemens 2022-03-16 10:29:07 UTC
Created attachment 131780 [details] [review]
Bug 27546: Add 'Search within results' search box

This enhancement adds a new input above the search results allowing one to search within the results. The search
box will take a query and add it as a limit to the previous search

These patches make a slight change to the search header, passing the dropdown selection as a parameter rather thandirectly.

Searching this way is functionally equivaled to adding 'AND' with the new term to original results.

To test:
1 - Apply patch
2 - Search on staff client wiht a term that returns results
3 - Note the new 'Search within results box'
4 - Add a search term
5 - Note new results and confirm they are as expected
6 - Enable IntranetCatalogSearchPulldown and confirm the dropdown works as expected
7 - Edit your search - the reinfements appear in the limits section and can be removed

Signed-off-by: Barbara Johnson <barbara.johnson@bedfordtx.gov>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 21 Victor Grousset/tuxayo 2022-04-22 23:56:38 UTC
Retested, still good, passing QA :)
Comment 22 Fridolin Somers 2022-04-25 19:58:20 UTC
+            window.location.href = "/cgi-bin/koha/catalogue/search.pl?[% query_cgi | $raw %]&[% limit_cgi | $raw %]&[% sort_cgi | $raw %]&limit="+index+$("#refiner").val();
Arf we must URI-espace $("#refiner").val() no ?
Comment 23 David Cook 2022-04-25 23:52:06 UTC
(In reply to Fridolin Somers from comment #22)
> +            window.location.href = "/cgi-bin/koha/catalogue/search.pl?[%
> query_cgi | $raw %]&[% limit_cgi | $raw %]&[% sort_cgi | $raw
> %]&limit="+index+$("#refiner").val();
> Arf we must URI-espace $("#refiner").val() no ?

100% needs an escape_str() there to prevent XSS.

Great catch, Frido!
Comment 24 Nick Clemens 2022-04-26 10:57:13 UTC
Created attachment 133873 [details] [review]
Bug 27546: (follow-up) Escape new search string
Comment 25 Fridolin Somers 2022-05-05 21:48:29 UTC
Arf we have a problem with #idx in actual code :
In koha-tmpl/intranet-tmpl/prog/en/includes/search_indexes.inc there is :
  <select class="advsearch" name="idx" id="idx">
But this include is used several times, so there are several id="idx".
We should remove this id.

So this patch should use select[name="idx"] I propose
Comment 26 Nick Clemens 2022-05-06 12:40:21 UTC
Created attachment 134729 [details] [review]
Bug 27546: (follow-up) Avoid index clash
Comment 27 Tomás Cohen Arazi 2022-07-20 12:59:51 UTC
Pushed to master for 22.11.

Nice work everyone, thanks!
Comment 28 Lucas Gass 2022-08-23 19:50:47 UTC
Enhancement will not be backported to 22.05.x series unless requested
Comment 29 Katrin Fischer 2022-08-23 20:53:52 UTC
Don't forget Needs dcocumenting :)