Search on basis of age in Library

Hello,
I am currently exploring methods to efficiently search for books in the library based on the age of the readers as input.
From DBs point of view, each book in the library has this information in “fields” as json string for “Reader Age (Youngest)” and “Reader Age (Oldest)” which can be utilized for this purpose.
Also, there is a function named addFilterRules in the file src/Domain/QueryCriteria.php, which appears to be closely aligned with these requirements. However, I am encountering some difficulty in understanding how to effectively implement this function.

db can be queried as follows for the intended result:

SELECT * FROM gibbonLibraryItem WHERE CAST(fields->‘$.“Reader Age (Youngest)”’ AS UNSIGNED) <= 8 AND CAST(fields->‘$.“Reader Age (Oldest)”’ AS UNSIGNED) >= 8

Now the question how get this as part of browse functionality in library.

Any hints here would be appreciated.
Thanks.

Hi @wakmun Welcome to the Gibbon community! Sounds like you’re off to an excellent start getting into the codebase. Adding new fields sounds like a way to go, however changing the interface to then search based on these fields its a bit more involved. The addFilterRules section to look at changing would be in the queryBrowseItems method in src/Domain/Library/LibraryGateway.php, and then passing in your search value through a ->filterBy call on the $criteria in modules/Library/library_browse.php. Hope this helps.

Keep in mind that your changes to the core will be overwritten when you next upgrade, so I recommend either tracking them in a fork on GitHub, or perhaps even doing a PR to contribute them to the core.

You may be interested in the upcoming Library UI changes for v27: Implementing Library Shelves as a UI Upgrade by felixOlesen · Pull Request #1794 · GibbonEdu/core · GitHub This enables you to make shelves for books, so I wonder if this would enable you to use a query to create shelves based on reader age. These changes also include an “omni search” which can search for values in a variety of fields. Here’s an example of it up and running in my school:

1 Like

Thanks for the hints. This seemed to work fine for me. I have sent a pull request (basically to get your feedback, but might end up helping others). The idea was to do the bare minimum changes in the beginning so didnt try my hand at “shelves” yet.

Thanks @wakmun for sharing your changes :smiley: I’ve added a couple small suggestions, which you should be able to auto-accept through the GitHub interface, otherwise this is looking useful and ready to merge :+1: