https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42835

--- Comment #6 from Pedro Amorim (ammopt) <[email protected]> ---
Created attachment 200317
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=200317&action=edit
Bug 42835: Elasticsearch: Gate items index features behind readiness check

Adds _items_index_ready() which checks whether the items index is fully
populated before enabling availability filtering and facet aggregation.
The index is considered ready only when it contains at least 95% of the
items in the database — this prevents the gate opening after a single
circulation event has indexed one item before rebuild_elasticsearch.pl
--items has been run.

The result is cached: 5 minutes when ready, 60 seconds when not, so a
freshly populated index is detected quickly without a restart.

TEST PLAN (Do not apply patches yet)
1) Set up KTD with Elasticsearch 8:
  ktd --search-engine es8 up
2) Do a search for 'music', you should get 42 results:
   http://localhost:8081/cgi-bin/koha/catalogue/search.pl?idx=&q=music
3) Click the 'Limit to records with available items' facet link. Notice you get
40 results. 9 of these bibs have all their items unavailable and should NOT be
showing.
4) Find a biblio with a single item (the top result of the search):
  http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=437
5) Check-out that item (39999000019186) to a patron
6) Repeat the same search with 'Limit to records with available items'. Notice
the biblio above is no longer showing (this is correct).
7) Check the background jobs:
  http://localhost:8081/cgi-bin/koha/admin/background_jobs.pl
8) Confirm at least 1 'Update Elasticsearch index' entry exists. This is
because a full bib reindex is triggered for anytime a check-out happens.
9) Let's pick a 2nd bib from that same search ('music' + only available):
http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=380
10) Edit that single item, put it 'Not for loan'
11) Refresh the search. Notice the bib is always showing, even though all its
items are unavailable (This is incorrect):
http://localhost:8081/cgi-bin/koha/catalogue/search.pl?idx=&q=music&weight_search=1&sort_by=relevance&limit=available

APPLY PATCHES
1) Set up KTD with Elasticsearch 8:
  ktd --search-engine es8 up
2) Do a search for 'music', you should get 42 results:
   http://localhost:8081/cgi-bin/koha/catalogue/search.pl?idx=&q=music
3) Click the 'Limit to records with available items' facet link. Notice you now
get 31 results. The previous 9 with all their items unavailable do not show
anymore.
4) Find a biblio with a single item (the top result of the search):
  http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=437
5) Check-out that item (39999000019186) to a patron
6) Repeat the same search with 'Limit to records with available items'. Notice
the biblio above is no longer showing (this is still correct).
7) Check the background jobs:
  http://localhost:8081/cgi-bin/koha/admin/background_jobs.pl
8) Confirm at least 1 'Update Elasticsearch index' entry exists. This is
because a full bib reindex is triggered for anytime a check-out happens. This
is still the case because a full reindex (to create the items index) has not
occurred yet. Let's do that
9) Run:
$ perl misc/search_tools/rebuild_elasticsearch.pl -i -r -v
10) Do another check-out for a 2nd bib with a single item e.g.
(39999000016710):
http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=380
11) Check the background jobs again:
  http://localhost:8081/cgi-bin/koha/admin/background_jobs.pl
12) Notice a new full bib record reindex job was not triggered, because this
was updated directly on the items index synchronously. Confirm that bib record
no longer shows on the 'only available' search:
http://localhost:8081/cgi-bin/koha/catalogue/search.pl?idx=&q=music&weight_search=1&sort_by=relevance&limit=available
13) Pick a third bib from the same search
http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=374
14) Edit the single item and put it 'not for loan'.
15) Refresh the search. Notice the bib is not showing anymore, because all its
items are unavailable (This is now correct):
http://localhost:8081/cgi-bin/koha/catalogue/search.pl?idx=&q=music&weight_search=1&sort_by=relevance&limit=available

Benefits:
  1. notforloan/damaged/withdrawn availability fix
  2. Skip biblio re-index on checkout — performance improvement, visible under
load
  3. Availability filtering via items index — real-time post-checkout
  4. Safe on upgrade — falls back to the biblios index until a rebuild with
--items is run, no hard requirement to rebuild before the system works
correctly.

Run tests:
prove t/db_dependent/Koha/SearchEngine/Elasticsearch/Search.t
prove t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t
prove t/db_dependent/Koha/SearchEngine/Elasticsearch.t
prove t/db_dependent/Koha/Item.t
prove t/db_dependent/Search.t
prove t/db_dependent/Koha/SearchEngine/Search.t

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

-- 
You are receiving this mail because:
You are watching all bug changes.
You are the assignee for the bug.
_______________________________________________
Koha-bugs mailing list
[email protected]
https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to