I have 3 libraries; AB; AB_C and AB_D If I Refine Search for Holding Library AB_C I get the correct results, all biblios which have at least one item in AB_C; similarly for Holding Library AB_D but if I Refine Search for Holding Library AB I get all biblios which have at least one item in AB, or AB_C or AB_D. The system is treating AB_C and AB_D as subsets of AB but AB_C is a completely different value to AB. The problem is the same in the staff interface.
I have just tested quickly, I have a branchcode "CPL", I search for "d" and use the CPL facet. I get 240 results and the url is http://pro.kohadev.org/cgi-bin/koha/catalogue/search.pl?idx=kw&q=d&sort_by=relevance_dsc&limit=holdingbranch:CPL If I replace CPL with CP, I get the "no result" page Do you recreate this issue on a sandbox?
I think the issue is the underscore. My guess is that Zebra treats it as a space, so you end up with Zebra treating AB_D and AB_C as 2 words. When doing a keyword search or limit on AB it will then naturally return the records from all branches with the 'word' AB. My normal advice is: never use spaces or underscores or - in your codes (library, itemtype, locatio, collection, ...) in Koha, because of how Zebra will treat them. Sometimes you might want that behaviour, but other times it's really not helpful.
This is Zebra only (works ok with elastic)
Created attachment 96185 [details] [review] Bug 20099: Try exact search for facets
So this patch does not work as "ext" is not supported if ICU is enabled. The only thing is then to either use elastic, or modify the branchcodes :)