Bug 28492 - Hyphen in branchcode gives wrong search results
Summary: Hyphen in branchcode gives wrong search results
Status: CLOSED WONTFIX
Alias: None
Product: Koha
Classification: Unclassified
Component: Searching (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords: Manual
Depends on:
Blocks:
 
Reported: 2021-05-31 20:43 UTC by Caroline Cyr La Rose
Modified: 2025-11-05 22:53 UTC (History)
4 users (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: ---
Documentation contact: Caroline Cyr La Rose
Documentation submission: https://gitlab.com/koha-community/koha-manual/-/merge_requests/626 https://gitlab.com/koha-community/koha-manual/-/merge_requests/627
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Caroline Cyr La Rose 2021-05-31 20:43:10 UTC
A client noticed that when limiting by branch, some search results were wrong and after a bit of digging, I found that it happens when the branchcode contains a hyphen.

I was able to recreate the situation as follows:
1) Go to Administration > Libraries and add the libraries
  - Fairfield (branchcode FFL) -- if you have the default database, this library should already exist
  - Fairfield North (branchcode FFL-N)
  - Fairfield South (branchcode FFLS)

2) Add an item to record A with holding branch FFL-N

3) Add an item to record B with holding branch FFLS

4) reindex if necessary

5) In Advanced search, search for record A and limit to Fairfield North library -- record is in the results - OK

6) In Advanced search, search for record A and limit to Fairfield library 
-- record is in the results! - NOT OK

7) In Advanced search, search for record B and limit to Fairfield South library -- record is in the results - OK

8) In Advanced search, search for record B and limit  to Fairfield library 
-- record is not in results - OK

As you can see, the search for branchcode FFL-N and for branchcode FFL give the same results. 

The problem was originally found by a client using 18.05.03. I was able to recreate in 20.05.08 and master (21.06.000), always with Zebra. I didn't try with ES because mine is currently broken :(
Comment 1 Katrin Fischer 2021-05-31 21:10:06 UTC
Hi Caroline,
that's a known issue. The search by library and others are keyword searches. hyphens are treated as spaces, so FFL-N is "FFL S" and a search for FFL will find it. Same is true for locations, collections etc.

I don't think changing the hyphen behavior in general would be a good idea as we want that for normal search. Using "ext" (exact field search) was problematic in the past - it didn't work for libraries using ICU. Not sure if it does now.

Safest option might be to avoid hyphens in the codes.
Comment 2 Caroline Cyr La Rose 2021-05-31 21:12:05 UTC
To add in the manual, no hyphens in branchodes, loc, CCODE
Comment 3 Caroline Cyr La Rose 2023-02-16 22:23:37 UTC
Not really fixed, but I added the info in the manual... hopefully bug 28495 will prevent users from making mistakes
Comment 4 Michaela Sieber 2025-11-05 17:19:44 UTC
Is this still valid? 
I can not recreate this (with Elastic)

We have more than 150 branchcodes with hyphens but never had problems since we started to migrate to Koha (I think we started with Version 21.11)

Or is this only a problem with Zebra?
Comment 5 Katrin Fischer 2025-11-05 19:30:58 UTC
I would imagine it's a problem with Elastic too, but depending on your search terms. The problem arises here:

branchcodes:
A
A-B

So when searching for A you'd also find A-B, because they are treated as words.
Comment 6 David Cook 2025-11-05 22:53:02 UTC
(In reply to Katrin Fischer from comment #5)
> I would imagine it's a problem with Elastic too, but depending on your
> search terms. The problem arises here:
> 
> branchcodes:
> A
> A-B
> 
> So when searching for A you'd also find A-B, because they are treated as
> words.

Yeah I'd say it's probably a problem. The same problem exists throughout Koha. Item types, collection codes, locations, etc.