https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43151 --- Comment #2 from Pedro Amorim (ammopt) <pedro.amorim@openfifth.co.uk> --- Created attachment 202513 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202513&action=edit Bug 43151: Scope item-level facet counts to the active combined filter Facet counts (itype, location, ccode, homebranch, holdingbranch) scanned every item on each matching bib, ignoring the active combined filter - filtering to itype:BOOK + ccode:FICTION still listed unrelated values like Music in the itype facet. _get_item_facets now runs one query per facet field, each excluding that field's own constraint but keeping the others, so facets stay accurate without hiding valid alternative values (standard multi-select faceting). Test plan: 1) Set up KTD with Elasticsearch 8: ktd --search-engine es8 up 2) Catalogue a record titled (MARC21: 245$a) e.g. 'ZZZ43151TEST' with 2 items: - item 1: type 'Books', collection 'Fiction' - item 2: type 'Music', collection 'Non-fiction' 3) Before rebuilding, confirm plack-error.log shows "Elasticsearch items index not ready" (if not, e.g. you already rebuilt earlier, skip to step 4). Then hit: http://localhost:8081/cgi-bin/koha/catalogue/search.pl?q=ZZZ43151TEST&limit=itype:BK&limit=ccode:NFIC Should return a normal page, not an error - falling back to crash isn't. 4) Rebuild the items index: $ misc/search_tools/rebuild_elasticsearch.pl -i -r -v 5) Search '43' at http://localhost:8081/cgi-bin/koha/catalogue/search.pl 'Item types' facet shows both 'Books' and 'Music'. 6) Combine 'Books' + 'Fiction' (facets or &limit=itype:BK&limit, but the 'Item types' facet now shows only 'Books' (previously it kept showing 'Music' too). 7) Combine 'Books' + 'Non-fiction' (&limit=itype:BK&limit=ccode -> 0 results (previously incorrectly returned 1).8) Edit item 1 and item 2's home/holding library to two different libraries (allow ~15s for cache) - no rebuild needed. Combine an item type + one branch's facet: Verify our test biblio is returned 9) Run tests: prove t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t prove t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t prove t/db_dependent/Koha/SearchEngine/Elasticsearch/Search.t prove t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.