Skip to content
Mohammad Kasra Habib edited this page May 7, 2024 · 5 revisions

$KIB^3$ Moodle Plugin: Book Search

The plugin was developed to provide a search field for text search in Moodle books with image-based slides. The plugin requires that a PDF of (almost) the same name is present in the same course section. The pages of the PDF need to correspond 1-1 to the pages in the book. Names of book and PDF need to be identical, except for text specified in brackets inside their names.

The plugin searches all PDFs for the text and then displays the search results as a list of links. Clicking on a link shows the respective page with the corresponding number inside the book.

How to use

Prepare data for search as a teacher

In order for books and PDF files to be searchable via the booksearch, a few requirements must be met. The PDF and the book must be in the same section and the name must not differ except for text within () or [].

ENSection

Search data as student

Add a block

First activate the "Edit mode", the switch is located in the course view as well as on your dashboard, top right.

10

Next, open the "block drawer" by clicking on the marked button. Then, from the "block drawer" select "Booksearch".

11

You can now exit "Edit mode" again.

Use block

To use the block, open the "block drawer" in the course view or your dashboard. In the course view you can use the search function immediately, in the dashboard you first have to select a course you want to search via a dropdown menu.

12

Now you can get started and enter any terms in the search field. The result is displayed immediately and updates automatically. Results contain the name of the book/pdf, a link to the chapter and a small excerpt from the passage found.

13

Using data via web service

Configuring the web service

To configure the web service, follow the instructions under Site administration > Server > Web services > Overview.

14

Using the web service

A request to the web service is made by a GET request to the following URL:

http://YourMoodleDomain/webservice/rest/server.php?wstoken=User-token&wsfunction=block_booksearch_get_searched_locations&moodlewsrestformat=json&search_string=Search&course_id=Course-ID&context_length=Excerpt-length

  • YourMoodleDomain: Domain of your Moodle installation (core URL).
  • User-token: User token created by Moodle during the web service configuration (previous step).
  • Search: The word/letter string/phrase to search for.
  • Course-ID: ID of the course to search in.
  • Excerpt-length: The number of words to return as a context snippet.

Usage and API configuration

Type: Block

Add a block to either your dashboard or a course.

Course Selection

If you are on your dashboard, you will have to first select the course you want to search in (this will trigger a site reload) using a dropdown menu.

Search

You can use the input field to search for a text snippet you want to see results for. The results will get updated automatically.

Results

The results will be displayed in the block just below the search bar and will update automatically. They are ordered under PDF/Book source and link to the respective book chapter.

Web Service

To configure the web service, follow the instructions on Site Administration > Server > Web services > Overview to register the web service and set the right for a specified user to use it. This involves the following steps:

  1. Enable web services
  2. Enable protocols: Her, enable the REST protocol if not already enabled.
  3. Create a specified user
  4. Check user capability: The specified user has to have at least the webservice/rest:use capability.
  5. Select a service: Add the "Book Search" to custom services.
  6. Add functions: Add the "block_booksearch_get_searched_locations" function to the "Book Search" service.
  7. Select a specified user: Add the web services user as an authorised user.
  8. Create a token for a user: Create a token for the web services user.

Test it by sending an http GET request to 'http://[yourmoodle]/webservice/rest/server.php?wstoken=[user-token]&wsfunction=block_booksearch_get_searched_locations&moodlewsrestformat=json&search_string=[search_string]&course_id=[course_id]&context_length=[context_length]' where

  • yourmoodle: domain of your moodle installation (as developer: probably localhost)
  • user-token: token received from moodle for a user which is allowed to use the web service
  • search_string: the search string which is used to search in moodle books and pdfs
  • course_id: the id of the course the string is searched in
  • context_length: the number of word before and after each found string

Installing via uploaded ZIP file

  1. Log in to your Moodle site as an admin and go to Site administration > Plugins > Install plugins.
  2. Upload the ZIP file with the plugin code. You should only be prompted to add extra details if your plugin type is not automatically detected.
  3. Check the plugin validation report and finish the installation.

Installing manually

The plugin can be also installed by putting the contents of this directory to

{your/moodle/dirroot}/blocks/booksearch

Afterwards, log in to your Moodle site as an admin and go to Site administration > Notifications to complete the installation.

Alternatively, you can run

$ php admin/cli/upgrade.php

to complete the installation from the command line.

Third-party APIs

Book Search plug-in relies on pdfparser package to extract data from PDF files. Pdfparser is a standalone PHP package under LGPLv3 license (see above: thirdpartylibs.xml for more details).

License

2022 Universtity of Stuttgart [email protected]

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.